diff --git a/examples/arkode/F2003_parallel/CMakeLists.txt b/examples/arkode/F2003_parallel/CMakeLists.txt index 04285a9414..0dfc11dc2b 100644 --- a/examples/arkode/F2003_parallel/CMakeLists.txt +++ b/examples/arkode/F2003_parallel/CMakeLists.txt @@ -16,12 +16,14 @@ # Example lists are tuples "name\;nodes\;tasks\;type" where the # type is develop for examples excluded from 'make test' in releases - -# Examples using SUNDIALS linear solvers -set(FARKODE_examples - "ark_brusselator1D_task_local_nls_f2003\;--monitor\;1\;4\;develop\;2" - "ark_brusselator1D_task_local_nls_f2003\;--monitor --global-nls\;1\;4\;develop\;2" - "ark_brusselator1D_task_local_nls_f2003\;--monitor --explicit --tf 3\;1\;4\;develop\;2") +if(SUNDIALS_LOGGING_ENABLE_MPI) + set(FARKODE_examples + "ark_brusselator1D_task_local_nls_f2003\;--monitor\;1\;4\;develop\;2" + "ark_brusselator1D_task_local_nls_f2003\;--monitor --global-nls\;1\;4\;develop\;2" + "ark_brusselator1D_task_local_nls_f2003\;--monitor --explicit --tf 3\;1\;4\;develop\;2") +else() + set(FARKODE_examples ) +endif() if(MPI_Fortran_COMPILER) # use MPI wrapper as the compiler diff --git a/include/nvector/nvector_manyvector.h b/include/nvector/nvector_manyvector.h index 8c424ec9b9..2fe2a0df05 100644 --- a/include/nvector/nvector_manyvector.h +++ b/include/nvector/nvector_manyvector.h @@ -49,10 +49,10 @@ extern "C" { ----------------------------------------------------------------- */ struct _N_VectorContent_ManyVector { - sunindextype num_subvectors; /* number of vectors attached */ - sunindextype global_length; /* overall manyvector length */ - N_Vector* subvec_array; /* pointer to N_Vector array */ - booleantype own_data; /* flag indicating data ownership */ + sunindextype num_subvectors; /* number of vectors attached */ + sunindextype global_length; /* overall global manyvector length */ + N_Vector* subvec_array; /* pointer to N_Vector array */ + booleantype own_data; /* flag indicating data ownership */ }; typedef struct _N_VectorContent_ManyVector *N_VectorContent_ManyVector; @@ -86,6 +86,7 @@ SUNDIALS_EXPORT void N_VDestroy_ManyVector(N_Vector v); SUNDIALS_EXPORT void N_VSpace_ManyVector(N_Vector v, sunindextype *lrw, sunindextype *liw); SUNDIALS_EXPORT sunindextype N_VGetLength_ManyVector(N_Vector v); +SUNDIALS_EXPORT sunindextype N_VGetSubvectorLocalLength_ManyVector(N_Vector v, sunindextype vec_num); SUNDIALS_EXPORT void N_VLinearSum_ManyVector(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); diff --git a/include/nvector/nvector_mpimanyvector.h b/include/nvector/nvector_mpimanyvector.h index 0229b5a438..fbfd7feff7 100644 --- a/include/nvector/nvector_mpimanyvector.h +++ b/include/nvector/nvector_mpimanyvector.h @@ -52,10 +52,10 @@ extern "C" { struct _N_VectorContent_MPIManyVector { MPI_Comm comm; /* overall MPI communicator */ - sunindextype num_subvectors; /* number of vectors attached */ - sunindextype global_length; /* overall manyvector length */ - N_Vector* subvec_array; /* pointer to N_Vector array */ - booleantype own_data; /* flag indicating data ownership */ + sunindextype num_subvectors; /* number of vectors attached */ + sunindextype global_length; /* overall global manyvector length */ + N_Vector* subvec_array; /* pointer to N_Vector array */ + booleantype own_data; /* flag indicating data ownership */ }; typedef struct _N_VectorContent_MPIManyVector *N_VectorContent_MPIManyVector; @@ -95,6 +95,7 @@ SUNDIALS_EXPORT void N_VSpace_MPIManyVector(N_Vector v, sunindextype *lrw, sunindextype *liw); SUNDIALS_EXPORT void *N_VGetCommunicator_MPIManyVector(N_Vector v); SUNDIALS_EXPORT sunindextype N_VGetLength_MPIManyVector(N_Vector v); +SUNDIALS_EXPORT sunindextype N_VGetSubvectorLocalLength_MPIManyVector(N_Vector v, sunindextype vec_num); SUNDIALS_EXPORT void N_VLinearSum_MPIManyVector(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z); diff --git a/include/sundials/sundials_nvector.h b/include/sundials/sundials_nvector.h index d87a2fa1b8..262bea7b0f 100644 --- a/include/sundials/sundials_nvector.h +++ b/include/sundials/sundials_nvector.h @@ -182,6 +182,10 @@ struct _generic_N_Vector_Ops void (*nvprint)(N_Vector); void (*nvprintfile)(N_Vector, FILE*); + /* WARNING: this function should not be used, it is here as a temporary + fix for https://github.com/LLNL/sundials/issues/160 (fortran getarraypointer bug). */ + sunindextype (*nvgetlocallength)(N_Vector); + #ifdef __cplusplus _generic_N_Vector_Ops() = default; #endif @@ -315,6 +319,11 @@ SUNDIALS_EXPORT void N_VSetVecAtIndexVectorArray(N_Vector* vs, int index, N_Vect SUNDIALS_EXPORT void N_VPrint(N_Vector v); SUNDIALS_EXPORT void N_VPrintFile(N_Vector v, FILE* outfile); + + /* WARNING: this function should not be used, it is here as a temporary + fix for https://github.com/LLNL/sundials/issues/160 (fortran getarraypointer bug). */ + SUNDIALS_DEPRECATED_EXPORT sunindextype N_VGetLocalLength(N_Vector v); + #ifdef __cplusplus } #endif diff --git a/src/arkode/fmod/farkode_erkstep_mod.f90 b/src/arkode/fmod/farkode_erkstep_mod.f90 index aebc460e6e..00b4271ea1 100644 --- a/src/arkode/fmod/farkode_erkstep_mod.f90 +++ b/src/arkode/fmod/farkode_erkstep_mod.f90 @@ -1097,18 +1097,18 @@ function FERKStepSetTable(arkode_mem, b) & swig_result = fresult end function -function FERKStepSetTableNum(arkode_mem, itable) & +function FERKStepSetTableNum(arkode_mem, etable) & result(swig_result) use, intrinsic :: ISO_C_BINDING integer(C_INT) :: swig_result type(C_PTR) :: arkode_mem -integer(ARKODE_ERKTableID), intent(in) :: itable +integer(ARKODE_ERKTableID), intent(in) :: etable integer(C_INT) :: fresult type(C_PTR) :: farg1 integer(C_INT) :: farg2 farg1 = arkode_mem -farg2 = itable +farg2 = etable fresult = swigc_FERKStepSetTableNum(farg1, farg2) swig_result = fresult end function @@ -1131,19 +1131,19 @@ subroutine SWIG_string_to_chararray(string, chars, wrap) wrap%size = len(string) end subroutine -function FERKStepSetTableName(arkode_mem, table) & +function FERKStepSetTableName(arkode_mem, etable) & result(swig_result) use, intrinsic :: ISO_C_BINDING integer(C_INT) :: swig_result type(C_PTR) :: arkode_mem -character(kind=C_CHAR, len=*), target :: table +character(kind=C_CHAR, len=*), target :: etable character(kind=C_CHAR), dimension(:), allocatable, target :: farg2_chars integer(C_INT) :: fresult type(C_PTR) :: farg1 type(SwigArrayWrapper) :: farg2 farg1 = arkode_mem -call SWIG_string_to_chararray(table, farg2_chars, farg2) +call SWIG_string_to_chararray(etable, farg2_chars, farg2) fresult = swigc_FERKStepSetTableName(farg1, farg2) swig_result = fresult end function diff --git a/src/nvector/manyvector/fmod/fnvector_manyvector_mod.c b/src/nvector/manyvector/fmod/fnvector_manyvector_mod.c index 4efd496e07..fafcbb9222 100644 --- a/src/nvector/manyvector/fmod/fnvector_manyvector_mod.c +++ b/src/nvector/manyvector/fmod/fnvector_manyvector_mod.c @@ -366,6 +366,20 @@ SWIGEXPORT int64_t _wrap_FN_VGetLength_ManyVector(N_Vector farg1) { } +SWIGEXPORT int64_t _wrap_FN_VGetSubvectorLocalLength_ManyVector(N_Vector farg1, int64_t const *farg2) { + int64_t fresult ; + N_Vector arg1 = (N_Vector) 0 ; + sunindextype arg2 ; + sunindextype result; + + arg1 = (N_Vector)(farg1); + arg2 = (sunindextype)(*farg2); + result = N_VGetSubvectorLocalLength_ManyVector(arg1,arg2); + fresult = (sunindextype)(result); + return fresult; +} + + SWIGEXPORT void _wrap_FN_VLinearSum_ManyVector(double const *farg1, N_Vector farg2, double const *farg3, N_Vector farg4, N_Vector farg5) { realtype arg1 ; N_Vector arg2 = (N_Vector) 0 ; diff --git a/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 b/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 index 9a02df30df..4b804c5dd4 100644 --- a/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 +++ b/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 @@ -40,6 +40,7 @@ module fnvector_manyvector_mod public :: FN_VDestroy_ManyVector public :: FN_VSpace_ManyVector public :: FN_VGetLength_ManyVector + public :: FN_VGetSubvectorLocalLength_ManyVector public :: FN_VLinearSum_ManyVector public :: FN_VConst_ManyVector public :: FN_VProd_ManyVector @@ -191,6 +192,15 @@ function swigc_FN_VGetLength_ManyVector(farg1) & integer(C_INT64_T) :: fresult end function +function swigc_FN_VGetSubvectorLocalLength_ManyVector(farg1, farg2) & +bind(C, name="_wrap_FN_VGetSubvectorLocalLength_ManyVector") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT64_T), intent(in) :: farg2 +integer(C_INT64_T) :: fresult +end function + subroutine swigc_FN_VLinearSum_ManyVector(farg1, farg2, farg3, farg4, farg5) & bind(C, name="_wrap_FN_VLinearSum_ManyVector") use, intrinsic :: ISO_C_BINDING @@ -642,7 +652,7 @@ function FN_VGetSubvectorArrayPointer_ManyVector(v, vec_num) & farg1 = c_loc(v) farg2 = vec_num fresult = swigc_FN_VGetSubvectorArrayPointer_ManyVector(farg1, farg2) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetSubvectorLocalLength_ManyVector(v, vec_num)]) end function function FN_VSetSubvectorArrayPointer_ManyVector(v_data, v, vec_num) & @@ -774,6 +784,22 @@ function FN_VGetLength_ManyVector(v) & swig_result = fresult end function +function FN_VGetSubvectorLocalLength_ManyVector(v, vec_num) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT64_T) :: swig_result +type(N_Vector), target, intent(inout) :: v +integer(C_INT64_T), intent(in) :: vec_num +integer(C_INT64_T) :: fresult +type(C_PTR) :: farg1 +integer(C_INT64_T) :: farg2 + +farg1 = c_loc(v) +farg2 = vec_num +fresult = swigc_FN_VGetSubvectorLocalLength_ManyVector(farg1, farg2) +swig_result = fresult +end function + subroutine FN_VLinearSum_ManyVector(a, x, b, y, z) use, intrinsic :: ISO_C_BINDING real(C_DOUBLE), intent(in) :: a diff --git a/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.c b/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.c index f28b01e272..91f4425206 100644 --- a/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.c +++ b/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.c @@ -400,6 +400,20 @@ SWIGEXPORT int64_t _wrap_FN_VGetLength_MPIManyVector(N_Vector farg1) { } +SWIGEXPORT int64_t _wrap_FN_VGetSubvectorLocalLength_MPIManyVector(N_Vector farg1, int64_t const *farg2) { + int64_t fresult ; + N_Vector arg1 = (N_Vector) 0 ; + sunindextype arg2 ; + sunindextype result; + + arg1 = (N_Vector)(farg1); + arg2 = (sunindextype)(*farg2); + result = N_VGetSubvectorLocalLength_MPIManyVector(arg1,arg2); + fresult = (sunindextype)(result); + return fresult; +} + + SWIGEXPORT void _wrap_FN_VLinearSum_MPIManyVector(double const *farg1, N_Vector farg2, double const *farg3, N_Vector farg4, N_Vector farg5) { realtype arg1 ; N_Vector arg2 = (N_Vector) 0 ; diff --git a/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 b/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 index aa2548d3fc..1fd9c2e8fc 100644 --- a/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 +++ b/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 @@ -42,6 +42,7 @@ module fnvector_mpimanyvector_mod public :: FN_VSpace_MPIManyVector public :: FN_VGetCommunicator_MPIManyVector public :: FN_VGetLength_MPIManyVector + public :: FN_VGetSubvectorLocalLength_MPIManyVector public :: FN_VLinearSum_MPIManyVector public :: FN_VConst_MPIManyVector public :: FN_VProd_MPIManyVector @@ -220,6 +221,15 @@ function swigc_FN_VGetLength_MPIManyVector(farg1) & integer(C_INT64_T) :: fresult end function +function swigc_FN_VGetSubvectorLocalLength_MPIManyVector(farg1, farg2) & +bind(C, name="_wrap_FN_VGetSubvectorLocalLength_MPIManyVector") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT64_T), intent(in) :: farg2 +integer(C_INT64_T) :: fresult +end function + subroutine swigc_FN_VLinearSum_MPIManyVector(farg1, farg2, farg3, farg4, farg5) & bind(C, name="_wrap_FN_VLinearSum_MPIManyVector") use, intrinsic :: ISO_C_BINDING @@ -764,7 +774,7 @@ function FN_VGetSubvectorArrayPointer_MPIManyVector(v, vec_num) & farg1 = c_loc(v) farg2 = vec_num fresult = swigc_FN_VGetSubvectorArrayPointer_MPIManyVector(farg1, farg2) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetSubvectorLocalLength_MPIManyVector(v, vec_num)]) end function function FN_VSetSubvectorArrayPointer_MPIManyVector(v_data, v, vec_num) & @@ -909,6 +919,22 @@ function FN_VGetLength_MPIManyVector(v) & swig_result = fresult end function +function FN_VGetSubvectorLocalLength_MPIManyVector(v, vec_num) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT64_T) :: swig_result +type(N_Vector), target, intent(inout) :: v +integer(C_INT64_T), intent(in) :: vec_num +integer(C_INT64_T) :: fresult +type(C_PTR) :: farg1 +integer(C_INT64_T) :: farg2 + +farg1 = c_loc(v) +farg2 = vec_num +fresult = swigc_FN_VGetSubvectorLocalLength_MPIManyVector(farg1, farg2) +swig_result = fresult +end function + subroutine FN_VLinearSum_MPIManyVector(a, x, b, y, z) use, intrinsic :: ISO_C_BINDING real(C_DOUBLE), intent(in) :: a diff --git a/src/nvector/manyvector/nvector_manyvector.c b/src/nvector/manyvector/nvector_manyvector.c index 1d102e4e46..2b39bcf660 100644 --- a/src/nvector/manyvector/nvector_manyvector.c +++ b/src/nvector/manyvector/nvector_manyvector.c @@ -18,6 +18,7 @@ #include #include #include +#include "sundials/sundials_nvector.h" #ifdef MANYVECTOR_BUILD_WITH_MPI #include #else @@ -271,7 +272,7 @@ N_Vector N_VNew_ManyVector(sunindextype num_subvectors, { N_Vector v; N_VectorContent_ManyVector content; - sunindextype i; + sunindextype i, local_length; /* Check that input N_Vectors are non-NULL */ if (vec_array == NULL) return(NULL); @@ -368,15 +369,16 @@ N_Vector N_VNew_ManyVector(sunindextype num_subvectors, content->subvec_array[i] = vec_array[i]; /* Determine overall ManyVector length: sum contributions from all subvectors */ - content->global_length = 0; + local_length = 0; for (i=0; iops->nvgetlength) { - content->global_length += N_VGetLength(vec_array[i]); + local_length += N_VGetLength(vec_array[i]); } else { N_VDestroy(v); return(NULL); } } + content->global_length = local_length; return(v); } @@ -560,6 +562,10 @@ sunindextype MVAPPEND(N_VGetLength)(N_Vector v) return(MANYVECTOR_GLOBLENGTH(v)); } +sunindextype MVAPPEND(N_VGetSubvectorLocalLength)(N_Vector v, sunindextype vec_num) +{ + return(N_VGetLocalLength(MVAPPEND(N_VGetSubvector)(v, vec_num))); +} /* Performs the linear sum z = a*x + b*y by calling N_VLinearSum on all subvectors; this routine does not check that x, y and z are ManyVectors, if they have the diff --git a/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 b/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 index 6017afe8a0..388de003d4 100644 --- a/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 +++ b/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 @@ -157,7 +157,7 @@ function FN_VGetArrayPointer_MPIPlusX(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetArrayPointer_MPIPlusX(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength_MPIPlusX(v)]) end function subroutine FN_VSetArrayPointer_MPIPlusX(vdata, v) diff --git a/src/nvector/mpiplusx/nvector_mpiplusx.c b/src/nvector/mpiplusx/nvector_mpiplusx.c index bfb84e1db7..ecb777a6e3 100644 --- a/src/nvector/mpiplusx/nvector_mpiplusx.c +++ b/src/nvector/mpiplusx/nvector_mpiplusx.c @@ -36,6 +36,7 @@ N_Vector N_VMake_MPIPlusX(MPI_Comm comm, N_Vector X, SUNContext sunctx) v->ops->nvgetvectorid = N_VGetVectorID_MPIPlusX; v->ops->nvgetarraypointer = N_VGetArrayPointer_MPIPlusX; v->ops->nvsetarraypointer = N_VSetArrayPointer_MPIPlusX; + v->ops->nvgetlocallength = N_VGetLocalLength_MPIPlusX; /* debugging functions */ if (X->ops->nvprint) diff --git a/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 b/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 index 03ea9427d4..7cfd400335 100644 --- a/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 +++ b/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 @@ -767,7 +767,7 @@ function FN_VGetArrayPointer_OpenMP(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetArrayPointer_OpenMP(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLength_OpenMP(v)]) end function subroutine FN_VSetArrayPointer_OpenMP(v_data, v) diff --git a/src/nvector/openmp/nvector_openmp.c b/src/nvector/openmp/nvector_openmp.c index 8e04c27fe0..265eb38829 100644 --- a/src/nvector/openmp/nvector_openmp.c +++ b/src/nvector/openmp/nvector_openmp.c @@ -94,6 +94,7 @@ N_Vector N_VNewEmpty_OpenMP(sunindextype length, int num_threads, SUNContext sun v->ops->nvgetarraypointer = N_VGetArrayPointer_OpenMP; v->ops->nvsetarraypointer = N_VSetArrayPointer_OpenMP; v->ops->nvgetlength = N_VGetLength_OpenMP; + v->ops->nvgetlocallength = N_VGetLength_OpenMP; /* standard vector operations */ v->ops->nvlinearsum = N_VLinearSum_OpenMP; diff --git a/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 b/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 index 78d5ee8a63..c55a0ee39a 100644 --- a/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 +++ b/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 @@ -911,7 +911,7 @@ function FN_VGetArrayPointer_Parallel(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetArrayPointer_Parallel(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength_Parallel(v)]) end function subroutine FN_VSetArrayPointer_Parallel(v_data, v) diff --git a/src/nvector/parallel/nvector_parallel.c b/src/nvector/parallel/nvector_parallel.c index 84a5b1a5f3..a12ef7de07 100644 --- a/src/nvector/parallel/nvector_parallel.c +++ b/src/nvector/parallel/nvector_parallel.c @@ -107,6 +107,7 @@ N_Vector N_VNewEmpty_Parallel(MPI_Comm comm, v->ops->nvsetarraypointer = N_VSetArrayPointer_Parallel; v->ops->nvgetcommunicator = N_VGetCommunicator_Parallel; v->ops->nvgetlength = N_VGetLength_Parallel; + v->ops->nvgetlocallength = N_VGetLocalLength_Parallel; /* standard vector operations */ v->ops->nvlinearsum = N_VLinearSum_Parallel; diff --git a/src/nvector/parhyp/nvector_parhyp.c b/src/nvector/parhyp/nvector_parhyp.c index 437bbb2535..41bd36487b 100644 --- a/src/nvector/parhyp/nvector_parhyp.c +++ b/src/nvector/parhyp/nvector_parhyp.c @@ -23,6 +23,7 @@ #include #include +#include "sundials/sundials_nvector.h" #define ZERO RCONST(0.0) #define HALF RCONST(0.5) diff --git a/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 b/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 index 668cd37584..69186fe306 100644 --- a/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 +++ b/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 @@ -767,7 +767,7 @@ function FN_VGetArrayPointer_Pthreads(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetArrayPointer_Pthreads(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLength_Pthreads(v)]) end function subroutine FN_VSetArrayPointer_Pthreads(v_data, v) diff --git a/src/nvector/pthreads/nvector_pthreads.c b/src/nvector/pthreads/nvector_pthreads.c index 100784fdb4..6e19d87661 100644 --- a/src/nvector/pthreads/nvector_pthreads.c +++ b/src/nvector/pthreads/nvector_pthreads.c @@ -162,6 +162,7 @@ N_Vector N_VNewEmpty_Pthreads(sunindextype length, int num_threads, v->ops->nvgetarraypointer = N_VGetArrayPointer_Pthreads; v->ops->nvsetarraypointer = N_VSetArrayPointer_Pthreads; v->ops->nvgetlength = N_VGetLength_Pthreads; + v->ops->nvgetlocallength = N_VGetLength_Pthreads; /* standard vector operations */ v->ops->nvlinearsum = N_VLinearSum_Pthreads; diff --git a/src/nvector/serial/fmod/fnvector_serial_mod.f90 b/src/nvector/serial/fmod/fnvector_serial_mod.f90 index 26d50b4dca..d0d18663ee 100644 --- a/src/nvector/serial/fmod/fnvector_serial_mod.f90 +++ b/src/nvector/serial/fmod/fnvector_serial_mod.f90 @@ -755,7 +755,7 @@ function FN_VGetArrayPointer_Serial(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetArrayPointer_Serial(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLength_Serial(v)]) end function subroutine FN_VSetArrayPointer_Serial(v_data, v) diff --git a/src/nvector/serial/nvector_serial.c b/src/nvector/serial/nvector_serial.c index 958ea2cc06..daa8ccc40a 100644 --- a/src/nvector/serial/nvector_serial.c +++ b/src/nvector/serial/nvector_serial.c @@ -21,6 +21,7 @@ #include #include +#include "sundials/sundials_nvector.h" #define ZERO RCONST(0.0) #define HALF RCONST(0.5) @@ -88,6 +89,7 @@ N_Vector N_VNewEmpty_Serial(sunindextype length, SUNContext sunctx) v->ops->nvgetarraypointer = N_VGetArrayPointer_Serial; v->ops->nvsetarraypointer = N_VSetArrayPointer_Serial; v->ops->nvgetlength = N_VGetLength_Serial; + v->ops->nvgetlocallength = N_VGetLength_Serial; /* standard vector operations */ v->ops->nvlinearsum = N_VLinearSum_Serial; diff --git a/src/sundials/fmod/fsundials_linearsolver_mod.f90 b/src/sundials/fmod/fsundials_linearsolver_mod.f90 index 7b83287dde..e5fc92eb13 100644 --- a/src/sundials/fmod/fsundials_linearsolver_mod.f90 +++ b/src/sundials/fmod/fsundials_linearsolver_mod.f90 @@ -83,13 +83,16 @@ module fsundials_linearsolver_mod enumerator :: SUNLINEARSOLVER_CUSOLVERSP_BATCHQR enumerator :: SUNLINEARSOLVER_MAGMADENSE enumerator :: SUNLINEARSOLVER_ONEMKLDENSE + enumerator :: SUNLINEARSOLVER_GINKGO + enumerator :: SUNLINEARSOLVER_KOKKOSDENSE enumerator :: SUNLINEARSOLVER_CUSTOM end enum integer, parameter, public :: SUNLinearSolver_ID = kind(SUNLINEARSOLVER_BAND) public :: SUNLINEARSOLVER_BAND, SUNLINEARSOLVER_DENSE, SUNLINEARSOLVER_KLU, SUNLINEARSOLVER_LAPACKBAND, & SUNLINEARSOLVER_LAPACKDENSE, SUNLINEARSOLVER_PCG, SUNLINEARSOLVER_SPBCGS, SUNLINEARSOLVER_SPFGMR, SUNLINEARSOLVER_SPGMR, & SUNLINEARSOLVER_SPTFQMR, SUNLINEARSOLVER_SUPERLUDIST, SUNLINEARSOLVER_SUPERLUMT, SUNLINEARSOLVER_CUSOLVERSP_BATCHQR, & - SUNLINEARSOLVER_MAGMADENSE, SUNLINEARSOLVER_ONEMKLDENSE, SUNLINEARSOLVER_CUSTOM + SUNLINEARSOLVER_MAGMADENSE, SUNLINEARSOLVER_ONEMKLDENSE, SUNLINEARSOLVER_GINKGO, SUNLINEARSOLVER_KOKKOSDENSE, & + SUNLINEARSOLVER_CUSTOM ! struct struct _generic_SUNLinearSolver_Ops type, bind(C), public :: SUNLinearSolver_Ops type(C_FUNPTR), public :: gettype diff --git a/src/sundials/fmod/fsundials_matrix_mod.f90 b/src/sundials/fmod/fsundials_matrix_mod.f90 index 316f2da524..815cbfab7a 100644 --- a/src/sundials/fmod/fsundials_matrix_mod.f90 +++ b/src/sundials/fmod/fsundials_matrix_mod.f90 @@ -23,11 +23,13 @@ module fsundials_matrix_mod enumerator :: SUNMATRIX_SPARSE enumerator :: SUNMATRIX_SLUNRLOC enumerator :: SUNMATRIX_CUSPARSE + enumerator :: SUNMATRIX_GINKGO + enumerator :: SUNMATRIX_KOKKOSDENSE enumerator :: SUNMATRIX_CUSTOM end enum integer, parameter, public :: SUNMatrix_ID = kind(SUNMATRIX_DENSE) public :: SUNMATRIX_DENSE, SUNMATRIX_MAGMADENSE, SUNMATRIX_ONEMKLDENSE, SUNMATRIX_BAND, SUNMATRIX_SPARSE, SUNMATRIX_SLUNRLOC, & - SUNMATRIX_CUSPARSE, SUNMATRIX_CUSTOM + SUNMATRIX_CUSPARSE, SUNMATRIX_GINKGO, SUNMATRIX_KOKKOSDENSE, SUNMATRIX_CUSTOM ! struct struct _generic_SUNMatrix_Ops type, bind(C), public :: SUNMatrix_Ops type(C_FUNPTR), public :: getid diff --git a/src/sundials/fmod/fsundials_nvector_mod.c b/src/sundials/fmod/fsundials_nvector_mod.c index 8be604c16e..23b0fb4fe8 100644 --- a/src/sundials/fmod/fsundials_nvector_mod.c +++ b/src/sundials/fmod/fsundials_nvector_mod.c @@ -1026,4 +1026,16 @@ SWIGEXPORT void _wrap_FN_VPrintFile(N_Vector farg1, void *farg2) { } +SWIGEXPORT int64_t _wrap_FN_VGetLocalLength(N_Vector farg1) { + int64_t fresult ; + N_Vector arg1 = (N_Vector) 0 ; + sunindextype result; + + arg1 = (N_Vector)(farg1); + result = N_VGetLocalLength(arg1); + fresult = (sunindextype)(result); + return fresult; +} + + diff --git a/src/sundials/fmod/fsundials_nvector_mod.f90 b/src/sundials/fmod/fsundials_nvector_mod.f90 index bab2b4172a..e8998c0491 100644 --- a/src/sundials/fmod/fsundials_nvector_mod.f90 +++ b/src/sundials/fmod/fsundials_nvector_mod.f90 @@ -23,6 +23,7 @@ module fsundials_nvector_mod enumerator :: SUNDIALS_NVEC_HIP enumerator :: SUNDIALS_NVEC_SYCL enumerator :: SUNDIALS_NVEC_RAJA + enumerator :: SUNDIALS_NVEC_KOKKOS enumerator :: SUNDIALS_NVEC_OPENMPDEV enumerator :: SUNDIALS_NVEC_TRILINOS enumerator :: SUNDIALS_NVEC_MANYVECTOR @@ -32,8 +33,9 @@ module fsundials_nvector_mod end enum integer, parameter, public :: N_Vector_ID = kind(SUNDIALS_NVEC_SERIAL) public :: SUNDIALS_NVEC_SERIAL, SUNDIALS_NVEC_PARALLEL, SUNDIALS_NVEC_OPENMP, SUNDIALS_NVEC_PTHREADS, SUNDIALS_NVEC_PARHYP, & - SUNDIALS_NVEC_PETSC, SUNDIALS_NVEC_CUDA, SUNDIALS_NVEC_HIP, SUNDIALS_NVEC_SYCL, SUNDIALS_NVEC_RAJA, SUNDIALS_NVEC_OPENMPDEV, & - SUNDIALS_NVEC_TRILINOS, SUNDIALS_NVEC_MANYVECTOR, SUNDIALS_NVEC_MPIMANYVECTOR, SUNDIALS_NVEC_MPIPLUSX, SUNDIALS_NVEC_CUSTOM + SUNDIALS_NVEC_PETSC, SUNDIALS_NVEC_CUDA, SUNDIALS_NVEC_HIP, SUNDIALS_NVEC_SYCL, SUNDIALS_NVEC_RAJA, SUNDIALS_NVEC_KOKKOS, & + SUNDIALS_NVEC_OPENMPDEV, SUNDIALS_NVEC_TRILINOS, SUNDIALS_NVEC_MANYVECTOR, SUNDIALS_NVEC_MPIMANYVECTOR, & + SUNDIALS_NVEC_MPIPLUSX, SUNDIALS_NVEC_CUSTOM ! struct struct _generic_N_Vector_Ops type, bind(C), public :: N_Vector_Ops type(C_FUNPTR), public :: nvgetvectorid @@ -91,6 +93,7 @@ module fsundials_nvector_mod type(C_FUNPTR), public :: nvbufunpack type(C_FUNPTR), public :: nvprint type(C_FUNPTR), public :: nvprintfile + type(C_FUNPTR), public :: nvgetlocallength end type N_Vector_Ops ! struct struct _generic_N_Vector type, bind(C), public :: N_Vector @@ -160,6 +163,7 @@ module fsundials_nvector_mod public :: FN_VSetVecAtIndexVectorArray public :: FN_VPrint public :: FN_VPrintFile + public :: FN_VGetLocalLength ! WRAPPER DECLARATIONS interface @@ -705,6 +709,14 @@ subroutine swigc_FN_VPrintFile(farg1, farg2) & type(C_PTR), value :: farg2 end subroutine +function swigc_FN_VGetLocalLength(farg1) & +bind(C, name="_wrap_FN_VGetLocalLength") & +result(fresult) +use, intrinsic :: ISO_C_BINDING +type(C_PTR), value :: farg1 +integer(C_INT64_T) :: fresult +end function + end interface @@ -821,7 +833,7 @@ function FN_VGetArrayPointer(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetArrayPointer(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength(v)]) end function function FN_VGetDeviceArrayPointer(v) & @@ -834,7 +846,7 @@ function FN_VGetDeviceArrayPointer(v) & farg1 = c_loc(v) fresult = swigc_FN_VGetDeviceArrayPointer(farg1) -call c_f_pointer(fresult, swig_result, [1]) +call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength(v)]) end function subroutine FN_VSetArrayPointer(v_data, v) @@ -1688,5 +1700,18 @@ subroutine FN_VPrintFile(v, outfile) call swigc_FN_VPrintFile(farg1, farg2) end subroutine +function FN_VGetLocalLength(v) & +result(swig_result) +use, intrinsic :: ISO_C_BINDING +integer(C_INT64_T) :: swig_result +type(N_Vector), target, intent(inout) :: v +integer(C_INT64_T) :: fresult +type(C_PTR) :: farg1 + +farg1 = c_loc(v) +fresult = swigc_FN_VGetLocalLength(farg1) +swig_result = fresult +end function + end module diff --git a/src/sundials/sundials_nvector.c b/src/sundials/sundials_nvector.c index c753d4e217..5f5807e7a1 100644 --- a/src/sundials/sundials_nvector.c +++ b/src/sundials/sundials_nvector.c @@ -118,6 +118,8 @@ N_Vector N_VNewEmpty(SUNContext sunctx) * OPTIONAL operations with no default implementation. */ + ops->nvgetlocallength = NULL; + /* local reduction operations (optional) */ ops->nvdotprodlocal = NULL; ops->nvmaxnormlocal = NULL; @@ -192,6 +194,7 @@ int N_VCopyOps(N_Vector w, N_Vector v) v->ops->nvsetarraypointer = w->ops->nvsetarraypointer; v->ops->nvgetcommunicator = w->ops->nvgetcommunicator; v->ops->nvgetlength = w->ops->nvgetlength; + v->ops->nvgetlocallength = w->ops->nvgetlocallength; /* standard vector operations */ v->ops->nvlinearsum = w->ops->nvlinearsum; @@ -349,6 +352,11 @@ sunindextype N_VGetLength(N_Vector v) return((sunindextype) v->ops->nvgetlength(v)); } +sunindextype N_VGetLocalLength(N_Vector v) +{ + return((sunindextype) v->ops->nvgetlocallength(v)); +} + /* ----------------------------------------------------------------- * standard vector operations * -----------------------------------------------------------------*/ diff --git a/swig/Makefile b/swig/Makefile index 00aaf06559..ce18570c81 100644 --- a/swig/Makefile +++ b/swig/Makefile @@ -28,9 +28,9 @@ SUNNONLINSOL=newton fixedpoint INCLUDES=-I../include -.PHONY: generic arkode cvode cvodes ida idas kinsol nvector sunmatrix sunlinsol sunnonlinsol +.PHONY: generic arkode cvode cvodes ida idas kinsol nvector sunmatrix sunlinsol sunnonlinsol patch -all: generic arkode cvode cvodes ida idas kinsol nvector sunmatrix sunlinsol sunnonlinsol +all: generic arkode cvode cvodes ida idas kinsol nvector sunmatrix sunlinsol sunnonlinsol patch arkode: $(ARKODE:%:arkode/%.i) @for i in ${ARKODE} ; do \ @@ -102,5 +102,10 @@ sunnonlinsol: $(SUNNONLINSOL:%:sunnonlinsol/fsunnonlinsol_%_mod.i) swig -fortran -outdir ../src/sunnonlinsol/$${i}/fmod -o ../src/sunnonlinsol/$${i}/fmod/fsunnonlinsol_$${i}_mod.c ${INCLUDES} sunnonlinsol/fsunnonlinsol_$${i}_mod.i ; \ done +patch: .FORCE + cd ..; git apply swig/fnvector-getarraypointer.patch + clean: rm ../src/**/fmod/*.c; rm ../src/**/fmod/*.f90 + +.FORCE: ; diff --git a/swig/fnvector-getarraypointer.patch b/swig/fnvector-getarraypointer.patch new file mode 100644 index 0000000000..7c07638d04 --- /dev/null +++ b/swig/fnvector-getarraypointer.patch @@ -0,0 +1,113 @@ +diff --git a/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 b/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 +index 4849a847f..1618ff1c7 100644 +--- a/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 ++++ b/src/nvector/manyvector/fmod/fnvector_manyvector_mod.f90 +@@ -652,7 +652,7 @@ integer(C_INT64_T) :: farg2 + farg1 = c_loc(v) + farg2 = vec_num + fresult = swigc_FN_VGetSubvectorArrayPointer_ManyVector(farg1, farg2) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetSubvectorLocalLength_ManyVector(v, vec_num)]) + end function + + function FN_VSetSubvectorArrayPointer_ManyVector(v_data, v, vec_num) & +diff --git a/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 b/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 +index 58c5de9ba..90fb73775 100644 +--- a/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 ++++ b/src/nvector/manyvector/fmod/fnvector_mpimanyvector_mod.f90 +@@ -774,7 +774,7 @@ integer(C_INT64_T) :: farg2 + farg1 = c_loc(v) + farg2 = vec_num + fresult = swigc_FN_VGetSubvectorArrayPointer_MPIManyVector(farg1, farg2) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetSubvectorLocalLength_MPIManyVector(v, vec_num)]) + end function + + function FN_VSetSubvectorArrayPointer_MPIManyVector(v_data, v, vec_num) & +diff --git a/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 b/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 +index 6017afe8a..934d1d1c1 100644 +--- a/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 ++++ b/src/nvector/mpiplusx/fmod/fnvector_mpiplusx_mod.f90 +@@ -157,7 +157,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetArrayPointer_MPIPlusX(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength_MPIPlusX(v)]) + end function + + subroutine FN_VSetArrayPointer_MPIPlusX(vdata, v) +diff --git a/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 b/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 +index 03ea9427d..154a6832a 100644 +--- a/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 ++++ b/src/nvector/openmp/fmod/fnvector_openmp_mod.f90 +@@ -767,7 +767,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetArrayPointer_OpenMP(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLength_OpenMP(v)]) + end function + + subroutine FN_VSetArrayPointer_OpenMP(v_data, v) +diff --git a/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 b/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 +index 78d5ee8a6..b25809fa7 100644 +--- a/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 ++++ b/src/nvector/parallel/fmod/fnvector_parallel_mod.f90 +@@ -911,7 +911,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetArrayPointer_Parallel(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLength_Parallel(v)]) + end function + + subroutine FN_VSetArrayPointer_Parallel(v_data, v) +diff --git a/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 b/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 +index 668cd3758..953c99063 100644 +--- a/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 ++++ b/src/nvector/pthreads/fmod/fnvector_pthreads_mod.f90 +@@ -767,7 +767,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetArrayPointer_Pthreads(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLength_Pthreads(v)]) + end function + + subroutine FN_VSetArrayPointer_Pthreads(v_data, v) +diff --git a/src/nvector/serial/fmod/fnvector_serial_mod.f90 b/src/nvector/serial/fmod/fnvector_serial_mod.f90 +index 26d50b4dc..d9c556447 100644 +--- a/src/nvector/serial/fmod/fnvector_serial_mod.f90 ++++ b/src/nvector/serial/fmod/fnvector_serial_mod.f90 +@@ -755,7 +755,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetArrayPointer_Serial(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLength_Serial(v)]) + end function + + subroutine FN_VSetArrayPointer_Serial(v_data, v) +diff --git a/src/sundials/fmod/fsundials_nvector_mod.f90 b/src/sundials/fmod/fsundials_nvector_mod.f90 +index 1c2117570..02aa723ac 100644 +--- a/src/sundials/fmod/fsundials_nvector_mod.f90 ++++ b/src/sundials/fmod/fsundials_nvector_mod.f90 +@@ -833,7 +833,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetArrayPointer(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength(v)]) + end function + + function FN_VGetDeviceArrayPointer(v) & +@@ -846,7 +846,7 @@ type(C_PTR) :: farg1 + + farg1 = c_loc(v) + fresult = swigc_FN_VGetDeviceArrayPointer(farg1) +-call c_f_pointer(fresult, swig_result, [1]) ++call c_f_pointer(fresult, swig_result, [FN_VGetLocalLength(v)]) + end function + + subroutine FN_VSetArrayPointer(v_data, v)