diff --git a/ParLib.src/Makefile b/ParLib.src/Makefile index c81ae8c1ba1da7017c8c85e3a3bc6badec10d390..61696a02fca935f94ba441de2d1719ea6e44c34d 100644 --- a/ParLib.src/Makefile +++ b/ParLib.src/Makefile @@ -3,7 +3,7 @@ AR = ar crl RANLIB = ranlib -INSTALLDIR = $(HOME)/ParLib.v2.1 +INSTALLDIR = $(HOME)/ParLib.v2.2 #INSTALLDIR = $(HOME) @@ -76,7 +76,7 @@ install: libparlib.a libparlibf.a plutils.o: plutils.h parlib.o: parlib.h plutils.h -parlibf.o: parlib.h plutils.h +parlib.o: parlib.h plutils.h bexchange.o: parlib.h plutils.h bexchangef.o: parlib.h plutils.h transpose.o: parlib.h plutils.h diff --git a/ParLib.src/bexchange.c b/ParLib.src/bexchange.c index 52e66f75a38440bcb7a6ec47bd8068f205417308..e273a8f45edc236e59b7238d43a77d14417d833e 100644 --- a/ParLib.src/bexchange.c +++ b/ParLib.src/bexchange.c @@ -16,12 +16,13 @@ * 999 - incorrect exchange mode (only for generic calls) */ -int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, - comm, period, bexchange ) +int P_BExchange_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange) + int ndims, *stride, *blklen, bdim, overlap[2]; MPI_Datatype datatype; MPI_Comm comm; - int period; + int period, only_period; BExchange *bexchange; { int nproc, iproc, direct, idim, sendproc[2], recvproc[2]; @@ -30,15 +31,15 @@ int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, MPI_Datatype oldtype, btype[2]; -// Setting degenerate-success cases conditions for consistency -// including: overlap[]=0, nproc=0, iproc=MPI_UNDEFINED + // Setting degenerate-success cases conditions for consistency + // including: overlap[]=0, nproc=0, iproc=MPI_UNDEFINED for (direct = 0; direct < 2; direct++) { bexchange->overlap[direct] = 0; } -// -// Check input parameters -// + // + // Check input parameters + // if (ndims < 1) { return 1; } if (bdim < 1 || bdim > ndims) { return 2; } if (overlap[0] == 0 && overlap[1] == 0) { return 0; } /* success */ @@ -49,10 +50,11 @@ int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, if (overlap[direct] < 0) { return 3; } if (overlap[direct] > blklen[bdim - 1]) { return 5; } } + if ((only_period) && (!period)) { return 0; } -// -// Define the number of processors in the group and the rank -// + // + // Define the number of processors in the group and the rank + // if (comm == MPI_COMM_NULL) { return 0; } // empty communicator MPI_Comm_size(comm, &nproc); @@ -63,14 +65,14 @@ int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, recvproc[0] = (iproc == nproc - 1 ? 0 : iproc + 1); sendproc[1] = recvproc[0]; recvproc[1] = sendproc[0]; - send[0] = iproc > 0 || period; - recv[0] = iproc < nproc - 1 || period; + send[0] = ((iproc > 0) && (!only_period)) || ((iproc == 0) && period); + recv[0] = ((iproc < nproc - 1) && (!only_period)) || ((iproc == nproc - 1) && period); send[1] = recv[0]; recv[1] = send[0]; MPI_Type_get_extent(datatype, &lb, &fsize); -// -// Define data types for the boundaries -// + // + // Define data types for the boundaries + // // checking if one data type will suffice ... const int ndsize = (overlap[0] == overlap[1]) ? 1 : 2; @@ -107,9 +109,9 @@ int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, if (ndsize == 1) btype[1] = btype[0]; // using same MPI-datatype -// -// Determine the begining of boundaries -// + // + // Determine the begining of boundaries + // strd = 1; for (idim = 0; idim < bdim - 1; idim++) { strd = strd * stride[idim]; @@ -135,6 +137,21 @@ int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int P_BExchange_init ( ndims, stride, blklen, bdim, overlap, datatype, + comm, period, bexchange ) + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; + int period; + BExchange *bexchange; +{ + const int only_period = 0; + return P_BExchange_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange); +} +// -------------------------------------------------------------------------- // + // -------------------------------------------------------------------------- // int P_BExchange_start ( a, bexchange ) void *a; @@ -227,24 +244,49 @@ int P_BExchange ( a, ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int P_BExchange_period( a, ndims, stride, blklen, bdim, overlap, datatype, + comm) + + void *a; + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; +{ + const int only_period = 1; + const int period = 1; + + BExchange bexchange; + int ierr; + if (ierr = P_BExchange_ginit(ndims, stride, blklen, bdim, overlap, + datatype, comm, period, only_period, &bexchange) != 0) { + return ierr; + } + P_BExchange_start(a, &bexchange); + P_BExchange_end(&bexchange); + P_BExchange_free(&bexchange); + return 0; +} +// -------------------------------------------------------------------------- // + // v.1.3 - persistent exchanges // // -------------------------------------------------------------------------- // -int PST_BExchange_init ( a, ndims, stride, blklen, bdim, overlap, datatype, - comm, period, bexchange ) +int PST_BExchange_ginit ( a, ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange ) void *a; int ndims, *stride, *blklen, bdim, overlap[2]; MPI_Datatype datatype; MPI_Comm comm; - int period; + int period, only_period; BExchange *bexchange; { int direct; char *ach = (char *)a; - int ierr = P_BExchange_init(ndims, stride, blklen, bdim, overlap, datatype, - comm, period, bexchange); + int ierr = P_BExchange_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange); if (ierr != 0) return ierr; for (direct = 0; direct < 2; direct++) { @@ -265,6 +307,23 @@ int PST_BExchange_init ( a, ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int PST_BExchange_init ( a, ndims, stride, blklen, bdim, overlap, datatype, + comm, period, bexchange ) + + void *a; + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; + int period; + BExchange *bexchange; +{ + const int only_period = 0; + return PST_BExchange_ginit(a, ndims, stride, blklen, bdim, overlap, + datatype, comm, period, only_period, bexchange); +} +// -------------------------------------------------------------------------- // + // -------------------------------------------------------------------------- // int PST_BExchange_start ( bexchange ) BExchange *bexchange; @@ -353,15 +412,41 @@ int PST_BExchange( a, ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int PST_BExchange_period( a, ndims, stride, blklen, bdim, overlap, datatype, + comm ) + + void *a; + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; +{ + const int only_period = 1; + const int period = 1; + + BExchange bexchange; + int ierr; + if (ierr = PST_BExchange_ginit(a, ndims, stride, blklen, bdim, overlap, + datatype, comm, period, only_period, &bexchange) != 0) { + return ierr; + } + PST_BExchange_start(&bexchange); + PST_BExchange_end(&bexchange); + PST_BExchange_free(&bexchange); + return 0; +} +// -------------------------------------------------------------------------- // + + // v.1.4 - manual packing // // -------------------------------------------------------------------------- // -int P_BExchange_mp_init ( ndims, stride, blklen, bdim, overlap, datatype, - comm, period, bexchange ) +int P_BExchange_mp_ginit ( ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange ) int ndims, *stride, *blklen, bdim, overlap[2]; MPI_Datatype datatype; MPI_Comm comm; - int period; + int period, only_period; BExchange *bexchange; { int nproc, iproc, direct, idim, sendproc[2], recvproc[2]; @@ -393,6 +478,8 @@ int P_BExchange_mp_init ( ndims, stride, blklen, bdim, overlap, datatype, if (overlap[direct] > blklen[bdim - 1]) { return 5; } } if (ndims > MAX_PARLIB_MP_DIMS) { return 6; } + + if ((only_period) && (!period)) { return 0; } // // Define the number of processors in the group and the rank // @@ -406,8 +493,8 @@ int P_BExchange_mp_init ( ndims, stride, blklen, bdim, overlap, datatype, recvproc[0] = (iproc == nproc - 1 ? 0 : iproc + 1); sendproc[1] = recvproc[0]; recvproc[1] = sendproc[0]; - send[0] = iproc > 0 || period; - recv[0] = iproc < nproc - 1 || period; + send[0] = ((iproc > 0) && (!only_period)) || ((iproc == 0) && period); + recv[0] = ((iproc < nproc - 1) && (!only_period)) || ((iproc == nproc - 1) && period); send[1] = recv[0]; recv[1] = send[0]; MPI_Type_get_extent(datatype, &lb, &fsize); @@ -505,6 +592,22 @@ int P_BExchange_mp_init ( ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // + +int P_BExchange_mp_init ( ndims, stride, blklen, bdim, overlap, datatype, + comm, period, bexchange ) + + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; + int period; + BExchange *bexchange; +{ + const int only_period = 0; + return P_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange); +} +// -------------------------------------------------------------------------- // + // -------------------------------------------------------------------------- // int P_BExchange_mp_start( a, bexchange ) void *a; @@ -621,22 +724,47 @@ int P_BExchange_mp(a, ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int P_BExchange_period_mp(a, ndims, stride, blklen, bdim, overlap, datatype, + comm) + + void *a; + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; +{ + const int only_period = 1; + const int period = 1; + + BExchange bexchange; + int ierr; + if (ierr = P_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, + datatype, comm, period, only_period, &bexchange) != 0) { + return ierr; + } + P_BExchange_mp_start(a, &bexchange); + P_BExchange_mp_end(a, &bexchange); + P_BExchange_mp_free(&bexchange); + return 0; +} +// -------------------------------------------------------------------------- // + // v.1.5 - persistent exchanges for manual packing // // -------------------------------------------------------------------------- // -int PST_BExchange_mp_init(ndims, stride, blklen, bdim, overlap, datatype, - comm, period, bexchange) +int PST_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange) int ndims, *stride, *blklen, bdim, overlap[2]; MPI_Datatype datatype; MPI_Comm comm; - int period; + int period, only_period; BExchange *bexchange; { int direct; - int ierr = P_BExchange_mp_init(ndims, stride, blklen, bdim, overlap, datatype, - comm, period, bexchange); + int ierr = P_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, bexchange); if (ierr != 0) return ierr; for (direct = 0; direct < 2; direct++) { @@ -657,6 +785,22 @@ int PST_BExchange_mp_init(ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int PST_BExchange_mp_init(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, bexchange) + + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; + int period; + BExchange *bexchange; +{ + const int only_period = 0; + return PST_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, + datatype, comm, period, only_period, bexchange); +} +// -------------------------------------------------------------------------- // + // -------------------------------------------------------------------------- // int PST_BExchange_mp_start( a, bexchange ) void *a; @@ -748,6 +892,31 @@ int PST_BExchange_mp( a, ndims, stride, blklen, bdim, overlap, datatype, } // -------------------------------------------------------------------------- // +// -------------------------------------------------------------------------- // +int PST_BExchange_period_mp( a, ndims, stride, blklen, bdim, overlap, datatype, + comm ) + + void *a; + MPI_Datatype datatype; + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Comm comm; +{ + const int only_period = 1; + const int period = 1; + + BExchange bexchange; + int ierr; + if (ierr = PST_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, + datatype, comm, period, only_period, &bexchange) != 0) { + return ierr; + } + PST_BExchange_mp_start(a, &bexchange); + PST_BExchange_mp_end(a, &bexchange); + PST_BExchange_mp_free(&bexchange); + return 0; +} +// -------------------------------------------------------------------------- // + // v.1.95 - choice subroutines // // -------------------------------------------------------------------------- // int P_BExchange_opt_init ( a, ndims, stride, blklen, bdim, overlap, datatype, @@ -911,4 +1080,68 @@ int P_BExchange_opt ( a, ndims, stride, blklen, bdim, overlap, datatype, return 999; } -// -------------------------------------------------------------------------- // \ No newline at end of file +// -------------------------------------------------------------------------- // + +// -------------------------------------------------------------------------- // +int P_BExchange_period_opt ( a, ndims, stride, blklen, bdim, overlap, datatype, + comm, exch_mode ) + + void *a; + int ndims, *stride, *blklen, bdim, overlap[2]; + MPI_Datatype datatype; + MPI_Comm comm; + int exch_mode; +{ + const int period = 1; + const int only_period = 1; + + BExchange bexchange; + int ierr; + + if (exch_mode == IS_MPI_TYPED) { + if (ierr = P_BExchange_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, &bexchange) != 0) { + return ierr; + } + + P_BExchange_start(a, &bexchange); + P_BExchange_end(&bexchange); + P_BExchange_free(&bexchange); + return 0; + } + if (exch_mode == IS_MPI_MANUAL_PACK) { + if (ierr = P_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, &bexchange) != 0) { + return ierr; + } + + P_BExchange_mp_start(a, &bexchange); + P_BExchange_mp_end(a, &bexchange); + P_BExchange_mp_free(&bexchange); + return 0; + } + if (exch_mode == IS_MPI_TYPED_PERSISTENT) { + if (ierr = PST_BExchange_ginit(a, ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, &bexchange) != 0) { + return ierr; + } + + PST_BExchange_start(&bexchange); + PST_BExchange_end(&bexchange); + PST_BExchange_free(&bexchange); + return 0; + } + if (exch_mode == IS_MPI_MANUAL_PACK_PERSISTENT) { + if (ierr = PST_BExchange_mp_ginit(ndims, stride, blklen, bdim, overlap, datatype, + comm, period, only_period, &bexchange) != 0) { + return ierr; + } + PST_BExchange_mp_start(a, &bexchange); + PST_BExchange_mp_end(a, &bexchange); + PST_BExchange_mp_free(&bexchange); + return 0; + } + + return 999; +} +// -------------------------------------------------------------------------- // diff --git a/ParLib.src/bexchangef.c b/ParLib.src/bexchangef.c index 9129931bd53566c30bc68fb2175bec98a690e8c3..39e4184dc24882642be12d4517660ab76dbe6508 100644 --- a/ParLib.src/bexchangef.c +++ b/ParLib.src/bexchangef.c @@ -448,6 +448,29 @@ void p_bexchange_opt ( a, ndims, stride, blklen, bdim, overlap, datatype, (int)*bdim, (int *)overlap, MPI_Type_f2c(*datatype), MPI_Comm_f2c(*comm), (int)*period, (int)*exch_mode); } + +// v.2.2: periodicity conditions only +#ifdef FORTRANUNDERSCORE +void p_bexchange_period_opt_ ( a, ndims, stride, blklen, bdim, overlap, datatype, + comm, exch_mode, ierr ) +#elif defined(FORTRANDOUBLEUNDERSCORE) +void p_bexchange_period_opt__ ( a, ndims, stride, blklen, bdim, overlap, datatype, + comm, exch_mode, ierr ) +#else +void p_bexchange_period_opt ( a, ndims, stride, blklen, bdim, overlap, datatype, + comm, exch_mode, ierr ) +#endif + + void *a; + MPI_Fint *ndims, *stride, *blklen, *bdim, *overlap, *ierr; + MPI_Fint *datatype; + MPI_Fint *comm; + MPI_Fint *exch_mode; +{ + *ierr = P_BExchange_period_opt(a, (int)*ndims, (int *)stride, (int *)blklen, + (int)*bdim, (int *)overlap, MPI_Type_f2c(*datatype), + MPI_Comm_f2c(*comm), (int)*exch_mode); +} // -------------------------------------------------------------------------- // diff --git a/ParLib.src/parlib.h b/ParLib.src/parlib.h index f02678a5956a2149c40668482a82fd3ccca593e9..617853de4b71addc7ee19b05bea10518b940520a 100644 --- a/ParLib.src/parlib.h +++ b/ParLib.src/parlib.h @@ -59,6 +59,13 @@ void remove_bexch_handle(int exch_id); // -------------------------------------------------------------------------- // + +// -------------------------------------------------------------------------- // +// v.2.2: general exchange init call +// : includes periodic only case by using additional parameter +int P_BExchange_ginit(int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm, int, int, BExchange*); + int P_BExchange_init ( int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int, BExchange* ); int P_BExchange_start ( void*, BExchange* ); @@ -66,10 +73,19 @@ int P_BExchange_end ( BExchange* ); int P_BExchange_free ( BExchange* ); int P_BExchange ( void*, int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int ); + +// v.2.2: periodicity conditions only +int P_BExchange_period(void*, int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm); // -------------------------------------------------------------------------- // // v.1.3 - persistent exchanges // // -------------------------------------------------------------------------- // +// v.2.2: general exchange init call +// : includes periodic only case by using additional parameter +int PST_BExchange_ginit(void*, int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm, int, int, BExchange*); + int PST_BExchange_init(void*, int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int, BExchange*); int PST_BExchange_start(BExchange*); @@ -77,10 +93,19 @@ int PST_BExchange_end(BExchange*); int PST_BExchange_free(BExchange*); int PST_BExchange(void*, int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int); + +// v.2.2: periodicity conditions only +int PST_BExchange_period(void*, int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm); // -------------------------------------------------------------------------- // // v.1.4 - manual packing // // -------------------------------------------------------------------------- // +// v.2.2: general exchange init call +// : includes periodic only case by using additional parameter +int P_BExchange_mp_ginit(int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm, int, int, BExchange*); + int P_BExchange_mp_init(int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int, BExchange*); int P_BExchange_mp_start(void*, BExchange*); @@ -88,10 +113,19 @@ int P_BExchange_mp_end(void*, BExchange*); int P_BExchange_mp_free(BExchange*); int P_BExchange_mp(void*, int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int); + +// v.2.2: periodicity conditions only +int P_BExchange_period_mp(void*, int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm); // -------------------------------------------------------------------------- // // v.1.4 - persistent exchanges for manual packing // // -------------------------------------------------------------------------- // +// v.2.2: general exchange init call +// : includes periodic only case by using additional parameter +int PST_BExchange_mp_ginit(int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm, int, int, BExchange*); + int PST_BExchange_mp_init(int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int, BExchange*); int PST_BExchange_mp_start(void*, BExchange*); @@ -99,6 +133,10 @@ int PST_BExchange_mp_end(void*, BExchange*); int PST_BExchange_mp_free(BExchange*); int PST_BExchange_mp(void*, int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int); + +// v.2.2: periodicity conditions only +int PST_BExchange_period_mp(void*, int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm); // -------------------------------------------------------------------------- // @@ -111,6 +149,10 @@ int P_BExchange_opt_end(void*, BExchange*, int); int P_BExchange_opt_free(BExchange*, int); int P_BExchange_opt(void*, int, int*, int*, int, int*, MPI_Datatype, MPI_Comm, int, int); + +// v.2.2: periodicity conditions only +int P_BExchange_period_opt(void*, int, int*, int*, int, int*, MPI_Datatype, + MPI_Comm, int); // -------------------------------------------------------------------------- //