From 33d28de9283baffd139c0ae0a24f4a12623c6c0c Mon Sep 17 00:00:00 2001 From: Salvatore Filippone Date: Wed, 4 Sep 2013 15:02:49 +0000 Subject: [PATCH] psblas-3.99: config/pac.m4 configure.ac configure util/Makefile util/metis_int.c util/psb_d_genpde_impl.f90 util/psb_d_genpde_mod.f90 util/psb_metispart_mod.F90 Beginning stuf for METIS 5.1.0: configry, genpd and metispart. --- config/pac.m4 | 111 +++++++ configure | 619 ++++++++++++++++++++++++++++++++++--- configure.ac | 19 +- util/Makefile | 5 +- util/metis_int.c | 37 +++ util/psb_d_genpde_impl.f90 | 112 ++++--- util/psb_d_genpde_mod.f90 | 8 +- util/psb_metispart_mod.F90 | 138 ++++++--- 8 files changed, 908 insertions(+), 141 deletions(-) create mode 100644 util/metis_int.c diff --git a/config/pac.m4 b/config/pac.m4 index 410d8bea..a5738c36 100644 --- a/config/pac.m4 +++ b/config/pac.m4 @@ -1688,3 +1688,114 @@ LIBS="$SAVE_LIBS"; CPPFLAGS="$SAVE_CPPFLAGS"; ])dnl +dnl @synopsis PAC_CHECK_METIS +dnl +dnl Will try to find the METIS library and headers. +dnl +dnl Will use $CC +dnl +dnl If the test passes, will execute ACTION-IF-FOUND. Otherwise, ACTION-IF-NOT-FOUND. +dnl Note : This file will be likely to induce the compiler to create a module file +dnl (for a module called conftest). +dnl Depending on the compiler flags, this could cause a conftest.mod file to appear +dnl in the present directory, or in another, or with another name. So be warned! +dnl +dnl @author Salvatore Filippone +dnl +AC_DEFUN(PAC_CHECK_METIS, +[AC_ARG_WITH(metis, AC_HELP_STRING([--with-metis=LIBNAME], [Specify the library name for METIS library. +Default: "-lmetis"]), + [psblas_cv_metis=$withval], + [psblas_cv_metis='-lmetis']) +AC_ARG_WITH(metisdir, AC_HELP_STRING([--with-metisdir=DIR], [Specify the directory for METIS library and includes.]), + [psblas_cv_metisdir=$withval], + [psblas_cv_metisdir='']) +AC_ARG_WITH(metisincdir, AC_HELP_STRING([--with-metisincdir=DIR], [Specify the directory for METIS includes.]), + [psblas_cv_metisincdir=$withval], + [psblas_cv_metisincdir='']) +AC_ARG_WITH(metislibdir, AC_HELP_STRING([--with-metislibdir=DIR], [Specify the directory for METIS library.]), + [psblas_cv_metislibdir=$withval], + [psblas_cv_metislibdir='']) + +AC_LANG([C]) +SAVE_LIBS="$LIBS" +SAVE_CPPFLAGS="$CPPFLAGS" +if test "x$psblas_cv_metisdir" != "x"; then + METIS_LIBDIR="-L$psblas_cv_metisdir" + LIBS="-L$psblas_cv_metisdir $LIBS" + METIS_INCLUDES="-I$psblas_cv_metisdir" + CPPFLAGS="$METIS_INCLUDES $CPPFLAGS" +fi +if test "x$psblas_cv_metisincdir" != "x"; then + METIS_INCLUDES="-I$psblas_cv_metisincdir" + CPPFLAGS="$METIS_INCLUDES $CPPFLAGS" +fi +if test "x$psblas_cv_metislibdir" != "x"; then + LIBS="-L$psblas_cv_metislibdir $LIBS" + METIS_LIBDIR="-L$psblas_cv_metislibdir" +fi + +AC_MSG_NOTICE([metis dir $psblas_cv_metisdir]) +AC_CHECK_HEADER([metis.h], + [pac_metis_header_ok=yes], + [pac_metis_header_ok=no; METIS_INCLUDES=""]) +if test "x$pac_metis_header_ok" == "xno" ; then +dnl Maybe Include or include subdirs? + unset ac_cv_header_metis_h + METIS_INCLUDES="-I$psblas_cv_metisdir/include -I$psblas_cv_metisdir/Include " + CPPFLAGS="$METIS_INCLUDES $SAVE_CPPFLAGS" + + AC_MSG_CHECKING([for metis_h in $METIS_INCLUDES]) + AC_CHECK_HEADER([metis.h], + [pac_metis_header_ok=yes], + [pac_metis_header_ok=no; METIS_INCLUDES=""]) +fi +if test "x$pac_metis_header_ok" == "xno" ; then +dnl Maybe new structure with METIS UFconfig METIS? + unset ac_cv_header_metis_h + METIS_INCLUDES="-I$psblas_cv_metisdir/UFconfig -I$psblas_cv_metisdir/METIS/Include -I$psblas_cv_metisdir/METIS/Include" + CPPFLAGS="$METIS_INCLUDES $SAVE_CPPFLAGS" + AC_CHECK_HEADER([metis.h], + [pac_metis_header_ok=yes], + [pac_metis_header_ok=no; METIS_INCLUDES=""]) +fi + + +if test "x$pac_metis_header_ok" == "xyes" ; then + psblas_cv_metis_includes="$METIS_INCLUDES" + METIS_LIBS="$psblas_cv_metis $METIS_LIBDIR" + LIBS="$METIS_LIBS -lm $LIBS"; + AC_MSG_CHECKING([for METIS_PartGraphRecursive in $METIS_LIBS]) + AC_TRY_LINK_FUNC(METIS_PartGraphRecursive, + [psblas_cv_have_metis=yes;pac_metis_lib_ok=yes; ], + [psblas_cv_have_metis=no;pac_metis_lib_ok=no; METIS_LIBS=""]) + AC_MSG_RESULT($pac_metis_lib_ok) + if test "x$pac_metis_lib_ok" == "xno" ; then + dnl Maybe Lib or lib? + METIS_LIBDIR="-L$psblas_cv_metisdir/Lib -L$psblas_cv_metisdir/lib" + METIS_LIBS="$psblas_cv_metis $METIS_LIBDIR" + LIBS="$METIS_LIBS -lm $SAVE_LIBS" + + AC_MSG_CHECKING([for METIS_PartGraphRecursive in $METIS_LIBS]) + AC_TRY_LINK_FUNC(METIS_PartGraphRecursive, + [psblas_cv_have_metis=yes;pac_metis_lib_ok=yes; ], + [psblas_cv_have_metis=no;pac_metis_lib_ok=no; METIS_LIBS=""]) + AC_MSG_RESULT($pac_metis_lib_ok) + fi + if test "x$pac_metis_lib_ok" == "xno" ; then + dnl Maybe METIS/Lib? + METIS_LIBDIR="-L$psblas_cv_metisdir/METIS/Lib -L$psblas_cv_metisdir/METIS/Lib" + METIS_LIBS="$psblas_cv_metis $METIS_LIBDIR" + LIBS="$METIS_LIBS -lm $SAVE_LIBS" + AC_MSG_CHECKING([for METIS_PartGraphRecursive in $METIS_LIBS]) + AC_TRY_LINK_FUNC(METIS_PartGraphRecursive, + [psblas_cv_have_metis=yes;pac_metis_lib_ok=yes; ], + [psblas_cv_have_metis=no;pac_metis_lib_ok=no; METIS_LIBS=""]) + AC_MSG_RESULT($pac_metis_lib_ok) + fi +fi +LIBS="$SAVE_LIBS"; +CPPFLAGS="$SAVE_CPPFLAGS"; +])dnl + + diff --git a/configure b/configure index 624f3f93..54049f6d 100755 --- a/configure +++ b/configure @@ -790,6 +790,9 @@ with_blas with_lapack with_rsb with_metis +with_metisdir +with_metisincdir +with_metislibdir with_amd with_amddir with_amdincdir @@ -1473,8 +1476,12 @@ Optional Packages: bin/include/lib subdirs with a regular RSB installation resides, or nothing to make the configure script invoke librsb-config) - --with-metis=LIB Specify -lMETISLIBNAME or the absolute library - filename. + --with-metis=LIBNAME Specify the library name for METIS library. Default: + "-lmetis" + --with-metisdir=DIR Specify the directory for METIS library and + includes. + --with-metisincdir=DIR Specify the directory for METIS includes. + --with-metislibdir=DIR Specify the directory for METIS library. --with-amd=LIBNAME Specify the library name for AMD library. Default: "-lamd" --with-amddir=DIR Specify the directory for AMD library and includes. @@ -9395,27 +9402,505 @@ LIBS="$RSB_LIBS ${LIBS}" # Check whether --with-metis was given. if test "${with_metis+set}" = set; then - withval=$with_metis; psblas_cv_metis="$withval" + withval=$with_metis; psblas_cv_metis=$withval else - psblas_cv_metis='' + psblas_cv_metis='-lmetis' fi +# Check whether --with-metisdir was given. +if test "${with_metisdir+set}" = set; then + withval=$with_metisdir; psblas_cv_metisdir=$withval +else + psblas_cv_metisdir='' +fi + + +# Check whether --with-metisincdir was given. +if test "${with_metisincdir+set}" = set; then + withval=$with_metisincdir; psblas_cv_metisincdir=$withval +else + psblas_cv_metisincdir='' +fi + -if test "x$psblas_cv_metis" != "x" ; then - { $as_echo "$as_me:$LINENO: checking for METIS_PartGraphRecursive in -l\"m\"" >&5 -$as_echo_n "checking for METIS_PartGraphRecursive in -l\"m\"... " >&6; } -if test "${ac_cv_lib__m__METIS_PartGraphRecursive+set}" = set; then +# Check whether --with-metislibdir was given. +if test "${with_metislibdir+set}" = set; then + withval=$with_metislibdir; psblas_cv_metislibdir=$withval +else + psblas_cv_metislibdir='' +fi + + +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 + +SAVE_LIBS="$LIBS" +SAVE_CPPFLAGS="$CPPFLAGS" +if test "x$psblas_cv_metisdir" != "x"; then + METIS_LIBDIR="-L$psblas_cv_metisdir" + LIBS="-L$psblas_cv_metisdir $LIBS" + METIS_INCLUDES="-I$psblas_cv_metisdir" + CPPFLAGS="$METIS_INCLUDES $CPPFLAGS" +fi +if test "x$psblas_cv_metisincdir" != "x"; then + METIS_INCLUDES="-I$psblas_cv_metisincdir" + CPPFLAGS="$METIS_INCLUDES $CPPFLAGS" +fi +if test "x$psblas_cv_metislibdir" != "x"; then + LIBS="-L$psblas_cv_metislibdir $LIBS" + METIS_LIBDIR="-L$psblas_cv_metislibdir" +fi + +{ $as_echo "$as_me:$LINENO: metis dir $psblas_cv_metisdir" >&5 +$as_echo "$as_me: metis dir $psblas_cv_metisdir" >&6;} +if test "${ac_cv_header_metis_h+set}" = set; then + { $as_echo "$as_me:$LINENO: checking for metis.h" >&5 +$as_echo_n "checking for metis.h... " >&6; } +if test "${ac_cv_header_metis_h+set}" = set; then $as_echo_n "(cached) " >&6 +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_metis_h" >&5 +$as_echo "$ac_cv_header_metis_h" >&6; } else - ac_check_lib_save_LIBS=$LIBS -LIBS="-l"m" "$psblas_cv_metis" $LIBS" + # Is the header compilable? +{ $as_echo "$as_me:$LINENO: checking metis.h usability" >&5 +$as_echo_n "checking metis.h usability... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_header_compiler=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:$LINENO: checking metis.h presence" >&5 +$as_echo_n "checking metis.h presence... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + ac_header_preproc=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi + +rm -f conftest.err conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { $as_echo "$as_me:$LINENO: WARNING: metis.h: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: metis.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: metis.h: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { $as_echo "$as_me:$LINENO: WARNING: metis.h: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: metis.h: present but cannot be compiled" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: metis.h: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: metis.h: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: metis.h: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: proceeding with the preprocessor's result" >&5 +$as_echo "$as_me: WARNING: metis.h: proceeding with the preprocessor's result" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: in the future, the compiler will take precedence" >&5 +$as_echo "$as_me: WARNING: metis.h: in the future, the compiler will take precedence" >&2;} + ( cat <<\_ASBOX +## ---------------------------------------------- ## +## Report this to salvatore.filippone@uniroma2.it ## +## ---------------------------------------------- ## +_ASBOX + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +{ $as_echo "$as_me:$LINENO: checking for metis.h" >&5 +$as_echo_n "checking for metis.h... " >&6; } +if test "${ac_cv_header_metis_h+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_cv_header_metis_h=$ac_header_preproc +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_metis_h" >&5 +$as_echo "$ac_cv_header_metis_h" >&6; } + +fi +if test "x$ac_cv_header_metis_h" = x""yes; then + pac_metis_header_ok=yes +else + pac_metis_header_ok=no; METIS_INCLUDES="" +fi + + +if test "x$pac_metis_header_ok" == "xno" ; then + unset ac_cv_header_metis_h + METIS_INCLUDES="-I$psblas_cv_metisdir/include -I$psblas_cv_metisdir/Include " + CPPFLAGS="$METIS_INCLUDES $SAVE_CPPFLAGS" + + { $as_echo "$as_me:$LINENO: checking for metis_h in $METIS_INCLUDES" >&5 +$as_echo_n "checking for metis_h in $METIS_INCLUDES... " >&6; } + if test "${ac_cv_header_metis_h+set}" = set; then + { $as_echo "$as_me:$LINENO: checking for metis.h" >&5 +$as_echo_n "checking for metis.h... " >&6; } +if test "${ac_cv_header_metis_h+set}" = set; then + $as_echo_n "(cached) " >&6 +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_metis_h" >&5 +$as_echo "$ac_cv_header_metis_h" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:$LINENO: checking metis.h usability" >&5 +$as_echo_n "checking metis.h usability... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +$ac_includes_default +#include +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_header_compiler=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:$LINENO: checking metis.h presence" >&5 +$as_echo_n "checking metis.h presence... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + ac_header_preproc=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi + +rm -f conftest.err conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { $as_echo "$as_me:$LINENO: WARNING: metis.h: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: metis.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: metis.h: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { $as_echo "$as_me:$LINENO: WARNING: metis.h: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: metis.h: present but cannot be compiled" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: metis.h: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: metis.h: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: metis.h: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: proceeding with the preprocessor's result" >&5 +$as_echo "$as_me: WARNING: metis.h: proceeding with the preprocessor's result" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: in the future, the compiler will take precedence" >&5 +$as_echo "$as_me: WARNING: metis.h: in the future, the compiler will take precedence" >&2;} + ( cat <<\_ASBOX +## ---------------------------------------------- ## +## Report this to salvatore.filippone@uniroma2.it ## +## ---------------------------------------------- ## +_ASBOX + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +{ $as_echo "$as_me:$LINENO: checking for metis.h" >&5 +$as_echo_n "checking for metis.h... " >&6; } +if test "${ac_cv_header_metis_h+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_cv_header_metis_h=$ac_header_preproc +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_metis_h" >&5 +$as_echo "$ac_cv_header_metis_h" >&6; } + +fi +if test "x$ac_cv_header_metis_h" = x""yes; then + pac_metis_header_ok=yes +else + pac_metis_header_ok=no; METIS_INCLUDES="" +fi + + +fi +if test "x$pac_metis_header_ok" == "xno" ; then + unset ac_cv_header_metis_h + METIS_INCLUDES="-I$psblas_cv_metisdir/UFconfig -I$psblas_cv_metisdir/METIS/Include -I$psblas_cv_metisdir/METIS/Include" + CPPFLAGS="$METIS_INCLUDES $SAVE_CPPFLAGS" + if test "${ac_cv_header_metis_h+set}" = set; then + { $as_echo "$as_me:$LINENO: checking for metis.h" >&5 +$as_echo_n "checking for metis.h... " >&6; } +if test "${ac_cv_header_metis_h+set}" = set; then + $as_echo_n "(cached) " >&6 +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_metis_h" >&5 +$as_echo "$ac_cv_header_metis_h" >&6; } +else + # Is the header compilable? +{ $as_echo "$as_me:$LINENO: checking metis.h usability" >&5 +$as_echo_n "checking metis.h usability... " >&6; } cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext cat >>conftest.$ac_ext <<_ACEOF /* end confdefs.h. */ +$ac_includes_default +#include +_ACEOF +rm -f conftest.$ac_objext +if { (ac_try="$ac_compile" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_compile") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest.$ac_objext; then + ac_header_compiler=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_compiler=no +fi + +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5 +$as_echo "$ac_header_compiler" >&6; } + +# Is the header present? +{ $as_echo "$as_me:$LINENO: checking metis.h presence" >&5 +$as_echo_n "checking metis.h presence... " >&6; } +cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ +#include +_ACEOF +if { (ac_try="$ac_cpp conftest.$ac_ext" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } >/dev/null && { + test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" || + test ! -s conftest.err + }; then + ac_header_preproc=yes +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_header_preproc=no +fi + +rm -f conftest.err conftest.$ac_ext +{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5 +$as_echo "$ac_header_preproc" >&6; } + +# So? What about this header? +case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in + yes:no: ) + { $as_echo "$as_me:$LINENO: WARNING: metis.h: accepted by the compiler, rejected by the preprocessor!" >&5 +$as_echo "$as_me: WARNING: metis.h: accepted by the compiler, rejected by the preprocessor!" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: proceeding with the compiler's result" >&5 +$as_echo "$as_me: WARNING: metis.h: proceeding with the compiler's result" >&2;} + ac_header_preproc=yes + ;; + no:yes:* ) + { $as_echo "$as_me:$LINENO: WARNING: metis.h: present but cannot be compiled" >&5 +$as_echo "$as_me: WARNING: metis.h: present but cannot be compiled" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: check for missing prerequisite headers?" >&5 +$as_echo "$as_me: WARNING: metis.h: check for missing prerequisite headers?" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: see the Autoconf documentation" >&5 +$as_echo "$as_me: WARNING: metis.h: see the Autoconf documentation" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: section \"Present But Cannot Be Compiled\"" >&5 +$as_echo "$as_me: WARNING: metis.h: section \"Present But Cannot Be Compiled\"" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: proceeding with the preprocessor's result" >&5 +$as_echo "$as_me: WARNING: metis.h: proceeding with the preprocessor's result" >&2;} + { $as_echo "$as_me:$LINENO: WARNING: metis.h: in the future, the compiler will take precedence" >&5 +$as_echo "$as_me: WARNING: metis.h: in the future, the compiler will take precedence" >&2;} + ( cat <<\_ASBOX +## ---------------------------------------------- ## +## Report this to salvatore.filippone@uniroma2.it ## +## ---------------------------------------------- ## +_ASBOX + ) | sed "s/^/$as_me: WARNING: /" >&2 + ;; +esac +{ $as_echo "$as_me:$LINENO: checking for metis.h" >&5 +$as_echo_n "checking for metis.h... " >&6; } +if test "${ac_cv_header_metis_h+set}" = set; then + $as_echo_n "(cached) " >&6 +else + ac_cv_header_metis_h=$ac_header_preproc +fi +{ $as_echo "$as_me:$LINENO: result: $ac_cv_header_metis_h" >&5 +$as_echo "$ac_cv_header_metis_h" >&6; } + +fi +if test "x$ac_cv_header_metis_h" = x""yes; then + pac_metis_header_ok=yes +else + pac_metis_header_ok=no; METIS_INCLUDES="" +fi + + +fi + + +if test "x$pac_metis_header_ok" == "xyes" ; then + psblas_cv_metis_includes="$METIS_INCLUDES" + METIS_LIBS="$psblas_cv_metis $METIS_LIBDIR" + LIBS="$METIS_LIBS -lm $LIBS"; + { $as_echo "$as_me:$LINENO: checking for METIS_PartGraphRecursive in $METIS_LIBS" >&5 +$as_echo_n "checking for METIS_PartGraphRecursive in $METIS_LIBS... " >&6; } + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ /* Override any GCC internal prototype to avoid an error. Use char because int might match the return type of a GCC @@ -9453,38 +9938,90 @@ $as_echo "$ac_try_echo") >&5 test "$cross_compiling" = yes || $as_test_x conftest$ac_exeext }; then - ac_cv_lib__m__METIS_PartGraphRecursive=yes + psblas_cv_have_metis=yes;pac_metis_lib_ok=yes; else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib__m__METIS_PartGraphRecursive=no + psblas_cv_have_metis=no;pac_metis_lib_ok=no; METIS_LIBS="" fi rm -rf conftest.dSYM rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib__m__METIS_PartGraphRecursive" >&5 -$as_echo "$ac_cv_lib__m__METIS_PartGraphRecursive" >&6; } -if test "x$ac_cv_lib__m__METIS_PartGraphRecursive" = x""yes; then - psblas_cv_have_metis=yes; METIS_LIBS="$psblas_cv_metis" + { $as_echo "$as_me:$LINENO: result: $pac_metis_lib_ok" >&5 +$as_echo "$pac_metis_lib_ok" >&6; } + if test "x$pac_metis_lib_ok" == "xno" ; then + METIS_LIBDIR="-L$psblas_cv_metisdir/Lib -L$psblas_cv_metisdir/lib" + METIS_LIBS="$psblas_cv_metis $METIS_LIBDIR" + LIBS="$METIS_LIBS -lm $SAVE_LIBS" + + { $as_echo "$as_me:$LINENO: checking for METIS_PartGraphRecursive in $METIS_LIBS" >&5 +$as_echo_n "checking for METIS_PartGraphRecursive in $METIS_LIBS... " >&6; } + cat >conftest.$ac_ext <<_ACEOF +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char METIS_PartGraphRecursive (); +int +main () +{ +return METIS_PartGraphRecursive (); + ; + return 0; +} +_ACEOF +rm -f conftest.$ac_objext conftest$ac_exeext +if { (ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" +$as_echo "$ac_try_echo") >&5 + (eval "$ac_link") 2>conftest.er1 + ac_status=$? + grep -v '^ *+' conftest.er1 >conftest.err + rm -f conftest.er1 + cat conftest.err >&5 + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); } && { + test -z "$ac_c_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then + psblas_cv_have_metis=yes;pac_metis_lib_ok=yes; else - psblas_cv_have_metis=no + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + psblas_cv_have_metis=no;pac_metis_lib_ok=no; METIS_LIBS="" fi -else - save_LIBS="$LIBS"; - LIBS="-lm $LIBS"; - { $as_echo "$as_me:$LINENO: checking for METIS_PartGraphRecursive in -lmetis" >&5 -$as_echo_n "checking for METIS_PartGraphRecursive in -lmetis... " >&6; } -if test "${ac_cv_lib_metis_METIS_PartGraphRecursive+set}" = set; then - $as_echo_n "(cached) " >&6 -else - ac_check_lib_save_LIBS=$LIBS -LIBS="-lmetis $LIBS" -cat >conftest.$ac_ext <<_ACEOF +rm -rf conftest.dSYM +rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ + conftest$ac_exeext conftest.$ac_ext + { $as_echo "$as_me:$LINENO: result: $pac_metis_lib_ok" >&5 +$as_echo "$pac_metis_lib_ok" >&6; } + fi + if test "x$pac_metis_lib_ok" == "xno" ; then + METIS_LIBDIR="-L$psblas_cv_metisdir/METIS/Lib -L$psblas_cv_metisdir/METIS/Lib" + METIS_LIBS="$psblas_cv_metis $METIS_LIBDIR" + LIBS="$METIS_LIBS -lm $SAVE_LIBS" + { $as_echo "$as_me:$LINENO: checking for METIS_PartGraphRecursive in $METIS_LIBS" >&5 +$as_echo_n "checking for METIS_PartGraphRecursive in $METIS_LIBS... " >&6; } + cat >conftest.$ac_ext <<_ACEOF /* confdefs.h. */ _ACEOF cat confdefs.h >>conftest.$ac_ext @@ -9527,31 +10064,27 @@ $as_echo "$ac_try_echo") >&5 test "$cross_compiling" = yes || $as_test_x conftest$ac_exeext }; then - ac_cv_lib_metis_METIS_PartGraphRecursive=yes + psblas_cv_have_metis=yes;pac_metis_lib_ok=yes; else $as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 - ac_cv_lib_metis_METIS_PartGraphRecursive=no + psblas_cv_have_metis=no;pac_metis_lib_ok=no; METIS_LIBS="" fi rm -rf conftest.dSYM rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \ conftest$ac_exeext conftest.$ac_ext -LIBS=$ac_check_lib_save_LIBS -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_lib_metis_METIS_PartGraphRecursive" >&5 -$as_echo "$ac_cv_lib_metis_METIS_PartGraphRecursive" >&6; } -if test "x$ac_cv_lib_metis_METIS_PartGraphRecursive" = x""yes; then - psblas_cv_have_metis=yes;METIS_LIBS="-lmetis" -else - psblas_cv_have_metis=no + { $as_echo "$as_me:$LINENO: result: $pac_metis_lib_ok" >&5 +$as_echo "$pac_metis_lib_ok" >&6; } + fi fi +LIBS="$SAVE_LIBS"; +CPPFLAGS="$SAVE_CPPFLAGS"; - LIBS="$save_LIBS"; -fi if test "x$psblas_cv_have_metis" == "xyes" ; then - FDEFINES="$FDEFINES $psblas_cv_define_prepend-DHAVE_METIS" + FDEFINES="$mld_cv_define_prepend-DHAVE_METIS $FDEFINES" + CDEFINES="-DHAVE_METIS_ $psblas_cv_metis_includes $CDEFINES" fi diff --git a/configure.ac b/configure.ac index e7c33825..d7759d5c 100755 --- a/configure.ac +++ b/configure.ac @@ -699,21 +699,10 @@ RSB_LIBS="$want_rsb_libs" LIBS="$RSB_LIBS ${LIBS}" dnl AC_CHECK_HEADERS([rsb.h], [ LIBS="${LIBS} $want_rsb_libs"], []) -AC_ARG_WITH(metis, AC_HELP_STRING([--with-metis=LIB], [Specify -lMETISLIBNAME or the absolute library filename.]), - [psblas_cv_metis="$withval"], - [psblas_cv_metis='']) - - -if test "x$psblas_cv_metis" != "x" ; then - AC_CHECK_LIB("m",METIS_PartGraphRecursive, psblas_cv_have_metis=yes; METIS_LIBS="$psblas_cv_metis", psblas_cv_have_metis=no,["$psblas_cv_metis"]) -else - save_LIBS="$LIBS"; - LIBS="-lm $LIBS"; - AC_CHECK_LIB(metis,METIS_PartGraphRecursive,psblas_cv_have_metis=yes;METIS_LIBS="-lmetis", psblas_cv_have_metis=no) - LIBS="$save_LIBS"; -fi -if test "x$psblas_cv_have_metis" == "xyes" ; then - FDEFINES="$FDEFINES $psblas_cv_define_prepend-DHAVE_METIS" +PAC_CHECK_METIS +if test "x$psblas_cv_have_metis" == "xyes" ; then + FDEFINES="$mld_cv_define_prepend-DHAVE_METIS $FDEFINES" + CDEFINES="-DHAVE_METIS_ $psblas_cv_metis_includes $CDEFINES" fi PAC_CHECK_AMD diff --git a/util/Makefile b/util/Makefile index f5405ef1..cef52c09 100644 --- a/util/Makefile +++ b/util/Makefile @@ -18,8 +18,8 @@ IMPLOBJS= psb_s_hbio_impl.o psb_d_hbio_impl.o \ psb_c_renum_impl.o psb_z_renum_impl.o \ psb_d_genpde_impl.o psb_s_genpde_impl.o MODOBJS=psb_util_mod.o $(BASEOBJS) -COBJS=psb_amd_order.o -OBJS=$(MODOBJS) $(IMPLOBJS) $(COBJS) +COBJS=metis_int.o psb_amd_order.o +OBJS=$(COBJS) $(MODOBJS) $(IMPLOBJS)# $(COBJS) LOCAL_MODS=$(MODOBJS:.o=$(.mod)) LIBNAME=$(UTILLIBNAME) FINCLUDES=$(FMFLAG). $(FMFLAG)$(LIBDIR) @@ -35,6 +35,7 @@ $(HERE)/$(LIBNAME): $(OBJS) $(OBJS): $(LIBDIR)/$(BASEMODNAME)$(.mod) psb_util_mod.o: $(BASEOBJS) +psb_metispart_mod.o: metis_int.o $(IMPLOBJS): $(BASEOBJS) diff --git a/util/metis_int.c b/util/metis_int.c new file mode 100644 index 00000000..19dca9a5 --- /dev/null +++ b/util/metis_int.c @@ -0,0 +1,37 @@ +#include +#include "metis.h" + +/* extern int METIS_PartGraphRecursive(int *, int *, int *, int *, int *, int *, int *, int *, float *, float, int *, int *, int *); */ + + +int metis_PartGraphRecursive_C(int *n, int *ixadj, int *iadj, int *ivwg, + int *iajw, int *nparts, float *weights, + int *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_PartGraphRecursive((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_PartGraphRecursive((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_PartGraphRecursive((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; + } +} diff --git a/util/psb_d_genpde_impl.f90 b/util/psb_d_genpde_impl.f90 index 9d5f0af8..23b4fd99 100644 --- a/util/psb_d_genpde_impl.f90 +++ b/util/psb_d_genpde_impl.f90 @@ -34,7 +34,7 @@ ! the rhs. ! subroutine psb_d_gen_pde3d(ictxt,idim,a,bv,xv,desc_a,afmt,& - & a1,a2,a3,b1,b2,b3,c,g,info,f,amold,vmold,imold,nrl) + & a1,a2,a3,b1,b2,b3,c,g,info,f,amold,vmold,imold,nrl,iv) use psb_base_mod use psb_d_genpde_mod, psb_protect_name => psb_d_gen_pde3d ! @@ -64,7 +64,7 @@ subroutine psb_d_gen_pde3d(ictxt,idim,a,bv,xv,desc_a,afmt,& class(psb_d_base_sparse_mat), optional :: amold class(psb_d_base_vect_type), optional :: vmold class(psb_i_base_vect_type), optional :: imold - integer(psb_ipk_), optional :: nrl + integer(psb_ipk_), optional :: nrl,iv(:) ! Local variables. @@ -113,29 +113,44 @@ subroutine psb_d_gen_pde3d(ictxt,idim,a,bv,xv,desc_a,afmt,& nnz = ((n*9)/(np)) if(iam == psb_root_) write(psb_out_unit,'("Generating Matrix (size=",i0,")...")')n - if (present(nrl)) then - nr = nrl + if (.not.present(iv)) then + if (present(nrl)) then + nr = nrl + else + ! + ! Using a simple BLOCK distribution. + ! + nt = (m+np-1)/np + nr = max(0,min(nt,m-(iam*nt))) + end if + + nt = nr + call psb_sum(ictxt,nt) + if (nt /= m) then + write(psb_err_unit,*) iam, 'Initialization error ',nr,nt,m + info = -1 + call psb_barrier(ictxt) + call psb_abort(ictxt) + return + end if else - ! - ! Using a simple BLOCK distribution. - ! - nt = (m+np-1)/np - nr = max(0,min(nt,m-(iam*nt))) + if (size(iv) /= m) then + write(psb_err_unit,*) iam, 'Initialization error IV',size(iv),m + info = -1 + call psb_barrier(ictxt) + call psb_abort(ictxt) + return + end if + end if - - nt = nr - call psb_sum(ictxt,nt) - if (nt /= m) then - write(psb_err_unit,*) iam, 'Initialization error ',nr,nt,m - info = -1 - call psb_barrier(ictxt) - call psb_abort(ictxt) - return - end if - call psb_barrier(ictxt) t0 = psb_wtime() - call psb_cdall(ictxt,desc_a,info,nl=nr) + if (present(iv)) then + call psb_cdall(ictxt,desc_a,info,vg=iv) + else + call psb_cdall(ictxt,desc_a,info,nl=nr) + end if + if (info == psb_success_) call psb_spall(a,desc_a,info,nnz=nnz) ! define rhs from boundary conditions; also build initial guess if (info == psb_success_) call psb_geall(xv,desc_a,info) @@ -350,7 +365,7 @@ end subroutine psb_d_gen_pde3d ! the rhs. ! subroutine psb_d_gen_pde2d(ictxt,idim,a,bv,xv,desc_a,afmt,& - & a1,a2,b1,b2,c,g,info,f,amold,vmold,imold,nrl) + & a1,a2,b1,b2,c,g,info,f,amold,vmold,imold,nrl,iv) use psb_base_mod use psb_d_genpde_mod, psb_protect_name => psb_d_gen_pde2d ! @@ -380,7 +395,7 @@ subroutine psb_d_gen_pde2d(ictxt,idim,a,bv,xv,desc_a,afmt,& class(psb_d_base_sparse_mat), optional :: amold class(psb_d_base_vect_type), optional :: vmold class(psb_i_base_vect_type), optional :: imold - integer(psb_ipk_), optional :: nrl + integer(psb_ipk_), optional :: nrl, iv(:) ! Local variables. @@ -429,28 +444,43 @@ subroutine psb_d_gen_pde2d(ictxt,idim,a,bv,xv,desc_a,afmt,& nnz = ((n*7)/(np)) if(iam == psb_root_) write(psb_out_unit,'("Generating Matrix (size=",i0,")...")')n - if (present(nrl)) then - nr = nrl + if (.not.present(iv)) then + if (present(nrl)) then + nr = nrl + else + ! + ! Using a simple BLOCK distribution. + ! + nt = (m+np-1)/np + nr = max(0,min(nt,m-(iam*nt))) + end if + + nt = nr + call psb_sum(ictxt,nt) + if (nt /= m) then + write(psb_err_unit,*) iam, 'Initialization error ',nr,nt,m + info = -1 + call psb_barrier(ictxt) + call psb_abort(ictxt) + return + end if else - ! - ! Using a simple BLOCK distribution. - ! - nt = (m+np-1)/np - nr = max(0,min(nt,m-(iam*nt))) - end if - - nt = nr - call psb_sum(ictxt,nt) - if (nt /= m) then - write(psb_err_unit,*) iam, 'Initialization error ',nr,nt,m - info = -1 - call psb_barrier(ictxt) - call psb_abort(ictxt) - return + if (size(iv) /= m) then + write(psb_err_unit,*) iam, 'Initialization error IV',size(iv),m + info = -1 + call psb_barrier(ictxt) + call psb_abort(ictxt) + return + end if + end if call psb_barrier(ictxt) t0 = psb_wtime() - call psb_cdall(ictxt,desc_a,info,nl=nr) + if (present(iv)) then + call psb_cdall(ictxt,desc_a,info,vg=iv) + else + call psb_cdall(ictxt,desc_a,info,nl=nr) + end if if (info == psb_success_) call psb_spall(a,desc_a,info,nnz=nnz) ! define rhs from boundary conditions; also build initial guess if (info == psb_success_) call psb_geall(xv,desc_a,info) diff --git a/util/psb_d_genpde_mod.f90 b/util/psb_d_genpde_mod.f90 index 87994dea..b10f94b4 100644 --- a/util/psb_d_genpde_mod.f90 +++ b/util/psb_d_genpde_mod.f90 @@ -45,7 +45,7 @@ module psb_d_genpde_mod interface psb_gen_pde3d subroutine psb_d_gen_pde3d(ictxt,idim,a,bv,xv,desc_a,afmt, & - & a1,a2,a3,b1,b2,b3,c,g,info,f,amold,vmold,imold,nrl) + & a1,a2,a3,b1,b2,b3,c,g,info,f,amold,vmold,imold,nrl,iv) ! ! Discretizes the partial differential equation ! @@ -75,7 +75,7 @@ module psb_d_genpde_mod class(psb_d_base_sparse_mat), optional :: amold class(psb_d_base_vect_type), optional :: vmold class(psb_i_base_vect_type), optional :: imold - integer(psb_ipk_), optional :: nrl + integer(psb_ipk_), optional :: nrl,iv(:) end subroutine psb_d_gen_pde3d end interface @@ -90,7 +90,7 @@ module psb_d_genpde_mod interface psb_gen_pde2d subroutine psb_d_gen_pde2d(ictxt,idim,a,bv,xv,desc_a,afmt,& - & a1,a2,b1,b2,c,g,info,f,amold,vmold,imold,nrl) + & a1,a2,b1,b2,c,g,info,f,amold,vmold,imold,nrl,iv) ! ! Discretizes the partial differential equation ! @@ -120,7 +120,7 @@ module psb_d_genpde_mod class(psb_d_base_sparse_mat), optional :: amold class(psb_d_base_vect_type), optional :: vmold class(psb_i_base_vect_type), optional :: imold - integer(psb_ipk_), optional :: nrl + integer(psb_ipk_), optional :: nrl,iv(:) end subroutine psb_d_gen_pde2d end interface diff --git a/util/psb_metispart_mod.F90 b/util/psb_metispart_mod.F90 index 182a1fd4..76410c93 100644 --- a/util/psb_metispart_mod.F90 +++ b/util/psb_metispart_mod.F90 @@ -136,15 +136,26 @@ contains end if end subroutine getv_mtpart - subroutine d_mat_build_mtpart(a,nparts) + subroutine d_mat_build_mtpart(a,nparts,weights) use psb_base_mod type(psb_dspmat_type), intent(in) :: a integer(psb_ipk_) :: nparts + real(psb_dpk_), optional :: weights(:) + real(psb_spk_), allocatable :: wgh_(:) select type (aa=>a%a) type is (psb_d_csr_sparse_mat) - call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts) + if (present(weights)) then + if (size(weights)==nparts) then + wgh_ = weights + end if + end if + if (allocated(wgh_)) then + call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts,wgh_) + else + call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts,wgh_) + end if class default write(psb_err_unit,*) 'Sorry, right now we only take CSR input!' call psb_abort(ictxt) @@ -153,49 +164,62 @@ contains end subroutine d_mat_build_mtpart - subroutine s_mat_build_mtpart(a,nparts) + subroutine z_mat_build_mtpart(a,nparts,weights) use psb_base_mod - type(psb_sspmat_type), intent(in) :: a + type(psb_zspmat_type), intent(in) :: a integer(psb_ipk_) :: nparts + real(psb_dpk_), optional :: weights(:) + real(psb_spk_), allocatable :: wgh_(:) select type (aa=>a%a) - type is (psb_s_csr_sparse_mat) - call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts) + type is (psb_z_csr_sparse_mat) + if (present(weights)) then + if (size(weights)==nparts) then + wgh_ = weights + end if + end if + if (allocated(wgh_)) then + call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts,wgh_) + else + call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts,wgh_) + end if class default write(psb_err_unit,*) 'Sorry, right now we only take CSR input!' call psb_abort(ictxt) end select - end subroutine s_mat_build_mtpart + end subroutine z_mat_build_mtpart - subroutine z_mat_build_mtpart(a,nparts) + subroutine s_mat_build_mtpart(a,nparts,weights) use psb_base_mod - type(psb_zspmat_type), intent(in) :: a + type(psb_sspmat_type), intent(in) :: a integer(psb_ipk_) :: nparts + real(psb_spk_), optional :: weights(:) select type (aa=>a%a) - type is (psb_z_csr_sparse_mat) - call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts) + type is (psb_s_csr_sparse_mat) + call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts,weights) class default write(psb_err_unit,*) 'Sorry, right now we only take CSR input!' call psb_abort(ictxt) end select - - end subroutine z_mat_build_mtpart + + end subroutine s_mat_build_mtpart - subroutine c_mat_build_mtpart(a,nparts) + subroutine c_mat_build_mtpart(a,nparts,weights) use psb_base_mod type(psb_cspmat_type), intent(in) :: a integer(psb_ipk_) :: nparts + real(psb_spk_), optional :: weights(:) select type (aa=>a%a) type is (psb_c_csr_sparse_mat) - call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts) + call build_mtpart(aa%get_nrows(),aa%get_fmt(),aa%ja,aa%irp,nparts,weights) class default write(psb_err_unit,*) 'Sorry, right now we only take CSR input!' call psb_abort(ictxt) @@ -203,33 +227,51 @@ contains end subroutine c_mat_build_mtpart - - subroutine build_mtpart(n,fida,ia1,ia2,nparts) + subroutine build_mtpart(n,fida,ja,irp,nparts,weights) use psb_base_mod + implicit none integer(psb_ipk_) :: nparts - integer(psb_ipk_) :: ia1(:), ia2(:) + integer(psb_ipk_) :: ja(:), irp(:) integer(psb_ipk_) :: n, i,numflag,nedc,wgflag character(len=5) :: fida integer(psb_ipk_), parameter :: nb=512 real(psb_dpk_), parameter :: seed=12345.d0 - integer(psb_ipk_) :: iopt(10),idummy(2),jdummy(2) + integer(psb_ipk_) :: iopt(10),idummy(2),jdummy(2), info + real(psb_spk_),optional :: weights(:) + integer(psb_ipk_) :: nl,nptl + integer(psb_ipk_), allocatable :: irpl(:),jal(:),gvl(:) + real(psb_spk_),allocatable :: wgh_(:) #if defined(HAVE_METIS) interface - subroutine METIS_PartGraphRecursive(n,ixadj,iadj,ivwg,iajw,& - & wgflag,numflag,nparts,iopt,nedc,part) - import :: psb_ipk_ - integer(psb_ipk_) :: n,wgflag,numflag,nparts,nedc - integer(psb_ipk_) :: ixadj(*),iadj(*),ivwg(*),iajw(*),iopt(*),part(*) - end subroutine METIS_PartGraphRecursive - end interface - - allocate(graph_vect(n),stat=info) - + ! subroutine METIS_PartGraphRecursive(n,ixadj,iadj,ivwg,iajw,& + ! & wgflag,numflag,nparts,weights,iopt,nedc,part) bind(c) + ! use iso_c_binding + ! integer(c_int) :: n,wgflag,numflag,nparts,nedc + ! integer(c_int) :: ixadj(*),iadj(*),ivwg(*),iajw(*),iopt(*),part(*) + ! real(c_float) :: weights(*) + ! !integer(psb_ipk_) :: n,wgflag,numflag,nparts,nedc + ! !integer(psb_ipk_) :: ixadj(*),iadj(*),ivwg(*),iajw(*),iopt(*),part(*) + ! end subroutine METIS_PartGraphRecursive + + function METIS_PartGraphRecursive(n,ixadj,iadj,ivwg,iajw,& + & nparts,weights,part) bind(c,name="metis_PartGraphRecursive_C") result(res) + use iso_c_binding + integer(c_int) :: res + integer(c_int) :: n,nparts + integer(c_int) :: ixadj(*),iadj(*),ivwg(*),iajw(*),part(*) + real(c_float) :: weights(*) + !integer(psb_ipk_) :: n,wgflag,numflag,nparts,nedc + !integer(psb_ipk_) :: ixadj(*),iadj(*),ivwg(*),iajw(*),iopt(*),part(*) + end function METIS_PartGraphRecursive + end interface + + allocate(graph_vect(n),gvl(n),wgh_(nparts),stat=info) + if (info /= psb_success_) then - write(psb_err_unit,*) 'Fatal error in BUILD_MTPART: memory allocation ',& - & ' failure.' - return + write(psb_err_unit,*) 'Fatal error in BUILD_MTPART: memory allocation ',& + & ' failure.' + return endif if (nparts > 1) then if (psb_toupper(fida) == 'CSR') then @@ -237,11 +279,35 @@ contains numflag = 1 wgflag = 0 - call METIS_PartGraphRecursive(n,ia2,ia1,idummy,jdummy,& - & wgflag,numflag,nparts,iopt,nedc,graph_vect) + write(*,*) 'Before allocation',nparts + + irpl=irp + jal = ja + nl = n + nptl = nparts + wgh_ = -1.0 + if(present(weights)) then + if (size(weights) == nptl) then + write(*,*) 'weights present',weights + ! call METIS_PartGraphRecursive(n,irp,ja,idummy,jdummy,& + ! & wgflag,numflag,nparts,weights,iopt,nedc,graph_vect) + info = METIS_PartGraphRecursive(nl,irpl,jal,idummy,jdummy,& + & nptl,weights,gvl) + + else + write(*,*) 'weights absent',wgh_ + info = METIS_PartGraphRecursive(nl,irpl,jal,idummy,jdummy,& + & nptl,wgh_,gvl) + end if + else + write(*,*) 'weights absent',wgh_ + info = METIS_PartGraphRecursive(nl,irpl,jal,idummy,jdummy,& + & nptl,wgh_,gvl) + endif + write(*,*) 'after allocation',info do i=1, n - graph_vect(i) = graph_vect(i) - 1 + graph_vect(i) = gvl(i) - 1 enddo else write(psb_err_unit,*) 'Fatal error in BUILD_MTPART: matrix format ',& @@ -259,7 +325,7 @@ contains return - end subroutine build_mtpart + end subroutine build_mtpart subroutine free_part(info)