From 51bcdf7e2bb5c35047143a314285579545a8f6e8 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 21 Oct 2020 14:16:48 +0200 Subject: [PATCH 1/5] Check METIS real size, use it where appropriate --- config/pac.m4 | 10 +++--- configure | 23 ++++++++------ configure.ac | 9 ++++-- util/psb_metis_int.c | 33 +++++++++++++++++++ util/psb_metispart_mod.F90 | 65 ++++++++++++++++++++++++++++++++------ 5 files changed, 115 insertions(+), 25 deletions(-) diff --git a/config/pac.m4 b/config/pac.m4 index 0fa7324e..becf32ad 100644 --- a/config/pac.m4 +++ b/config/pac.m4 @@ -1850,17 +1850,17 @@ fi if test "x$pac_metis_header_ok" == "xyes" ; then AC_LANG_PUSH([C]) - AC_MSG_CHECKING([for METIS idx size]) + AC_MSG_CHECKING([for METIS real size]) AC_LINK_IFELSE([AC_LANG_SOURCE( #include #include "$psblas_cv_metisincfile" void main(){ - printf("%d\n",IDXTYPEWIDTH); + printf("%d\n",REALTYPEWIDTH); } )], - [pac_cv_metis_idx=`./conftest${ac_exeext} | sed 's/^ *//'`], - [pac_cv_metis_idx="unknown"]) - AC_MSG_RESULT($pac_cv_metis_idx) + [pac_cv_metis_real=`./conftest${ac_exeext} | sed 's/^ *//'`], + [pac_cv_metis_real="unknown"]) + AC_MSG_RESULT($pac_cv_metis_real) AC_LANG_POP() fi diff --git a/configure b/configure index bacb6175..a0979f7e 100755 --- a/configure +++ b/configure @@ -8988,26 +8988,26 @@ ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' ac_compiler_gnu=$ac_cv_c_compiler_gnu - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for METIS idx size" >&5 -$as_echo_n "checking for METIS idx size... " >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for METIS real size" >&5 +$as_echo_n "checking for METIS real size... " >&6; } cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ #include #include "$psblas_cv_metisincfile" void main(){ - printf("%d\n",IDXTYPEWIDTH); + printf("%d\n",REALTYPEWIDTH); } _ACEOF if ac_fn_c_try_link "$LINENO"; then : - pac_cv_metis_idx=`./conftest${ac_exeext} | sed 's/^ *//'` + pac_cv_metis_real=`./conftest${ac_exeext} | sed 's/^ *//'` else - pac_cv_metis_idx="unknown" + pac_cv_metis_real="unknown" fi rm -f core conftest.err conftest.$ac_objext \ conftest$ac_exeext conftest.$ac_ext - { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pac_cv_metis_idx" >&5 -$as_echo "$pac_cv_metis_idx" >&6; } + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pac_cv_metis_real" >&5 +$as_echo "$pac_cv_metis_real" >&6; } ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -9180,9 +9180,14 @@ if test "x$pac_cv_metis_idx" == "xunknown" ; then $as_echo "$as_me: Unknown METIS bitsize." >&6;} $psblas_cv_have_metis = "no"; fi +if test "x$pac_cv_metis_real" == "xunknown" ; then + { $as_echo "$as_me:${as_lineno-$LINENO}: Unknown METIS REAL bitsize." >&5 +$as_echo "$as_me: Unknown METIS REAL bitsize." >&6;} + $psblas_cv_have_metis = "no"; +fi if test "x$psblas_cv_have_metis" == "xyes" ; then - FDEFINES="$psblas_cv_define_prepend-DHAVE_METIS $psblas_cv_define_prepend-DMETIS_$pac_cv_metis_idx $FDEFINES" - CDEFINES="-DHAVE_METIS_ $psblas_cv_metis_includes $CDEFINES -DMETIS_$pac_cv_metis_idx" + FDEFINES="$psblas_cv_define_prepend-DHAVE_METIS $psblas_cv_define_prepend-DMETIS_$pac_cv_metis_idx $psblas_cv_define_prepend-DMETIS_REAL_$pac_cv_metis_real $FDEFINES" + CDEFINES="-DHAVE_METIS_ $psblas_cv_metis_includes $CDEFINES -DMETIS_$pac_cv_metis_idx -DMETIS_REAL_$pac_cv_metis_real" METISINCFILE=$psblas_cv_metisincfile fi diff --git a/configure.ac b/configure.ac index 8bfd5806..0145a9e1 100755 --- a/configure.ac +++ b/configure.ac @@ -716,9 +716,14 @@ if test "x$pac_cv_metis_idx" == "xunknown" ; then AC_MSG_NOTICE([Unknown METIS bitsize.]) $psblas_cv_have_metis = "no"; fi +if test "x$pac_cv_metis_real" == "xunknown" ; then + dnl mismatch between metis size and PSBLAS LPK + AC_MSG_NOTICE([Unknown METIS REAL bitsize.]) + $psblas_cv_have_metis = "no"; +fi if test "x$psblas_cv_have_metis" == "xyes" ; then - FDEFINES="$psblas_cv_define_prepend-DHAVE_METIS $psblas_cv_define_prepend-DMETIS_$pac_cv_metis_idx $FDEFINES" - CDEFINES="-DHAVE_METIS_ $psblas_cv_metis_includes $CDEFINES -DMETIS_$pac_cv_metis_idx" + FDEFINES="$psblas_cv_define_prepend-DHAVE_METIS $psblas_cv_define_prepend-DMETIS_$pac_cv_metis_idx $psblas_cv_define_prepend-DMETIS_REAL_$pac_cv_metis_real $FDEFINES" + CDEFINES="-DHAVE_METIS_ $psblas_cv_metis_includes $CDEFINES -DMETIS_$pac_cv_metis_idx -DMETIS_REAL_$pac_cv_metis_real" METISINCFILE=$psblas_cv_metisincfile fi diff --git a/util/psb_metis_int.c b/util/psb_metis_int.c index 0b76c2a6..5c86ea26 100644 --- a/util/psb_metis_int.c +++ b/util/psb_metis_int.c @@ -2,6 +2,7 @@ #if defined(HAVE_METIS_) #include "psb_metis_int.h" +#if defined(METIS_REAL_32) int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, idx_t *iajw, idx_t *nparts, float *weights, idx_t *graphpart) @@ -34,6 +35,38 @@ int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, } } +#elif defined(METIS_REAL_64) +int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, + idx_t *iajw, idx_t *nparts, double *weights, + idx_t *graphpart) +{ + int res = -1; + idx_t objval = 0; + idx_t options[METIS_NOPTIONS]; + //printf("Inside Metis/C interface\n"); + idx_t ncon=1; + METIS_SetDefaultOptions(options); + options[METIS_OPTION_NUMBERING] = 1; + //printf("n:%p ncon:%p ixadj:%p iadj:%p npart:%p weights:%p options:%p objval:%p graphpart: %p\n",n,&ncon,ixadj,iadj,nparts,NULL,options,&objval,graphpart); + /* fprintf(stderr,"From metis_int: %f\n",weights[0]); */ + if (weights[0] == -1.0) { + res = METIS_PartGraphKway((idx_t*)n,(idx_t *)&ncon,(idx_t *)ixadj,(idx_t *)iadj, + NULL,NULL,NULL,(idx_t *)nparts,NULL,NULL,options, + &objval,(idx_t *)graphpart); + } else { + /* res = METIS_PartGraphKway((idx_t*)n,(idx_t *)&ncon,(idx_t *)ixadj,(idx_t *)iadj, */ + /* NULL,NULL,NULL,(idx_t *)nparts,NULL,NULL,NULL, */ + /* &objval,(idx_t *)graphpart); */ + res = METIS_PartGraphKway((idx_t*)n,(idx_t *)&ncon,(idx_t *)ixadj,(idx_t *)iadj, + NULL,NULL,NULL,(idx_t *)nparts,weights,NULL,options, + &objval,(idx_t *)graphpart); + } + if (res == METIS_OK) { + return(0); + } else { + return res; + } +} #else diff --git a/util/psb_metispart_mod.F90 b/util/psb_metispart_mod.F90 index fa6581e9..0957030b 100644 --- a/util/psb_metispart_mod.F90 +++ b/util/psb_metispart_mod.F90 @@ -77,8 +77,13 @@ module psb_metispart_mod integer(psb_lpk_), intent(in) :: n, nparts integer(psb_lpk_), intent(in) :: ja(:), irp(:) integer(psb_lpk_), allocatable, intent(inout) :: vect(:) +#if defined(METIS_REAL_32) real(psb_spk_),optional, intent(in) :: weights(:) - +#elif defined(METIS_REAL_64) + real(psb_dpk_),optional, intent(in) :: weights(:) +#else + choke on me; +#endif end subroutine psi_l_build_mtpart end interface @@ -181,8 +186,13 @@ contains type(psb_ld_csr_sparse_mat), intent(in) :: a integer(psb_lpk_) :: nparts real(psb_dpk_), optional :: weights(:) +#if defined(METIS_REAL_32) real(psb_spk_), allocatable :: wgh_(:) - +#elif defined(METIS_REAL_64) + real(psb_dpk_), allocatable :: wgh_(:) +#else + choke on me; +#endif if (present(weights)) then if (size(weights)==nparts) then @@ -220,8 +230,13 @@ contains type(psb_lz_csr_sparse_mat), intent(in) :: a integer(psb_lpk_) :: nparts real(psb_dpk_), optional :: weights(:) +#if defined(METIS_REAL_32) real(psb_spk_), allocatable :: wgh_(:) - +#elif defined(METIS_REAL_64) + real(psb_dpk_), allocatable :: wgh_(:) +#else + choke on me; +#endif if (present(weights)) then if (size(weights)==nparts) then @@ -276,9 +291,25 @@ contains type(psb_lc_csr_sparse_mat), intent(in) :: a integer(psb_lpk_) :: nparts real(psb_spk_), optional :: weights(:) - - - call psi_build_mtpart(a%get_nrows(),a%ja,a%irp,nparts,graph_vect,weights) +#if defined(METIS_REAL_32) + real(psb_spk_), allocatable :: wgh_(:) +#elif defined(METIS_REAL_64) + real(psb_dpk_), allocatable :: wgh_(:) +#else + choke on me; +#endif + + + if (present(weights)) then + if (size(weights)==nparts) then + wgh_ = weights + end if + end if + if (allocated(wgh_)) then + call psi_build_mtpart(a%get_nrows(),a%ja,a%irp,nparts,graph_vect,wgh_) + else + call psi_build_mtpart(a%get_nrows(),a%ja,a%irp,nparts,graph_vect) + end if end subroutine lc_csr_build_mtpart @@ -288,10 +319,26 @@ contains type(psb_ls_csr_sparse_mat), intent(in) :: a integer(psb_lpk_) :: nparts real(psb_spk_), optional :: weights(:) - - - call psi_build_mtpart(a%get_nrows(),a%ja,a%irp,nparts,graph_vect,weights) +#if defined(METIS_REAL_32) + real(psb_spk_), allocatable :: wgh_(:) +#elif defined(METIS_REAL_64) + real(psb_dpk_), allocatable :: wgh_(:) +#else + choke on me; +#endif + + if (present(weights)) then + if (size(weights)==nparts) then + wgh_ = weights + end if + end if + if (allocated(wgh_)) then + call psi_build_mtpart(a%get_nrows(),a%ja,a%irp,nparts,graph_vect,wgh_) + else + call psi_build_mtpart(a%get_nrows(),a%ja,a%irp,nparts,graph_vect) + end if + end subroutine ls_csr_build_mtpart ! From 5168c05f8e6fd11cb4c70dd6fd97f7ac3ecc2d87 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 21 Oct 2020 14:35:33 +0200 Subject: [PATCH 2/5] Fix metis interface. --- util/psb_metis_int.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/util/psb_metis_int.c b/util/psb_metis_int.c index 5c86ea26..5f451cb7 100644 --- a/util/psb_metis_int.c +++ b/util/psb_metis_int.c @@ -3,6 +3,7 @@ #include "psb_metis_int.h" #if defined(METIS_REAL_32) + int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, idx_t *iajw, idx_t *nparts, float *weights, idx_t *graphpart) @@ -36,6 +37,7 @@ int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, } #elif defined(METIS_REAL_64) + int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, idx_t *iajw, idx_t *nparts, double *weights, idx_t *graphpart) @@ -77,3 +79,4 @@ int metis_PartGraphKway_C(idx_t *n, idx_t *ixadj, idx_t *iadj, idx_t *ivwg, return(-1); } #endif +#endif From 3a975c6881d4c1280d5650d587c03646c27acde4 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 21 Oct 2020 15:18:35 +0200 Subject: [PATCH 3/5] Add psb_dpk_ to imports --- util/psb_metispart_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/psb_metispart_mod.F90 b/util/psb_metispart_mod.F90 index 0957030b..496e263f 100644 --- a/util/psb_metispart_mod.F90 +++ b/util/psb_metispart_mod.F90 @@ -55,7 +55,7 @@ ! module psb_metispart_mod use psb_base_mod, only : psb_ipk_, psb_lpk_, psb_mpk_, psb_epk_, & - & psb_err_unit, psb_spk_,& + & psb_err_unit, psb_spk_, psb_dpk_,& & psb_lsspmat_type, psb_lcspmat_type,& & psb_ldspmat_type, psb_lzspmat_type, & & psb_ls_csr_sparse_mat, psb_ld_csr_sparse_mat, & From 28b3ab5f772baf04e0ada75c309795072939c560 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 21 Oct 2020 16:08:56 +0200 Subject: [PATCH 4/5] Fix import of psb_dpk_ --- util/psb_metispart_mod.F90 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/psb_metispart_mod.F90 b/util/psb_metispart_mod.F90 index 496e263f..081d1bc1 100644 --- a/util/psb_metispart_mod.F90 +++ b/util/psb_metispart_mod.F90 @@ -72,7 +72,7 @@ module psb_metispart_mod interface psi_build_mtpart subroutine psi_l_build_mtpart(n,ja,irp,nparts,vect, weights) - import :: psb_lpk_, psb_spk_ + import :: psb_lpk_, psb_spk_, psb_dpk_ implicit none integer(psb_lpk_), intent(in) :: n, nparts integer(psb_lpk_), intent(in) :: ja(:), irp(:) From 1023ba9019b9d726e4ce9b05c0354d4313dd01d8 Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Thu, 22 Oct 2020 11:22:00 +0200 Subject: [PATCH 5/5] Fix METIS detection --- config/pac.m4 | 17 +++++++++++++++++ configure | 38 ++++++++++++++++++++++++++++++++++++++ configure.ac | 1 + 3 files changed, 56 insertions(+) diff --git a/config/pac.m4 b/config/pac.m4 index becf32ad..46a56b68 100644 --- a/config/pac.m4 +++ b/config/pac.m4 @@ -1848,6 +1848,23 @@ dnl Maybe new structure with METIS UFconfig METIS? [pac_metis_header_ok=no; METIS_INCLUDES=""]) fi +if test "x$pac_metis_header_ok" == "xyes" ; then + AC_LANG_PUSH([C]) + AC_MSG_CHECKING([for METIS integer size]) + AC_LINK_IFELSE([AC_LANG_SOURCE( + #include + #include "$psblas_cv_metisincfile" + void main(){ + printf("%d\n",IDXTYPEWIDTH); + } + )], + [pac_cv_metis_idx=`./conftest${ac_exeext} | sed 's/^ *//'`], + [pac_cv_metis_idx="unknown"]) + AC_MSG_RESULT($pac_cv_metis_idx) + + AC_LANG_POP() +fi + if test "x$pac_metis_header_ok" == "xyes" ; then AC_LANG_PUSH([C]) AC_MSG_CHECKING([for METIS real size]) diff --git a/configure b/configure index a0979f7e..e8688547 100755 --- a/configure +++ b/configure @@ -8981,6 +8981,42 @@ done fi +if test "x$pac_metis_header_ok" == "xyes" ; then + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for METIS integer size" >&5 +$as_echo_n "checking for METIS integer size... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + #include "$psblas_cv_metisincfile" + void main(){ + printf("%d\n",IDXTYPEWIDTH); + } + +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + pac_cv_metis_idx=`./conftest${ac_exeext} | sed 's/^ *//'` +else + pac_cv_metis_idx="unknown" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $pac_cv_metis_idx" >&5 +$as_echo "$pac_cv_metis_idx" >&6; } + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + +fi + if test "x$pac_metis_header_ok" == "xyes" ; then ac_ext=c ac_cpp='$CPP $CPPFLAGS' @@ -10812,6 +10848,7 @@ fi METIS usable : ${psblas_cv_have_metis} METIS bitsize : ${pac_cv_metis_idx} + METIS realsize : ${pac_cv_metis_real} AMD detected : ${psblas_cv_have_amd} LIBS : ${LIBS} LDLIBS : ${LDLIBS} @@ -10841,6 +10878,7 @@ $as_echo "$as_me: METIS usable : ${psblas_cv_have_metis} METIS bitsize : ${pac_cv_metis_idx} + METIS realsize : ${pac_cv_metis_real} AMD detected : ${psblas_cv_have_amd} LIBS : ${LIBS} LDLIBS : ${LDLIBS} diff --git a/configure.ac b/configure.ac index 0145a9e1..a2650489 100755 --- a/configure.ac +++ b/configure.ac @@ -841,6 +841,7 @@ AC_MSG_NOTICE([ METIS usable : ${psblas_cv_have_metis} METIS bitsize : ${pac_cv_metis_idx} + METIS realsize : ${pac_cv_metis_real} AMD detected : ${psblas_cv_have_amd} LIBS : ${LIBS} dnl Note : we should use LDLIBS sooner or later!