diff --git a/src/LIB/MPIvide/mpi.h b/src/LIB/MPIvide/mpi.h index 72a1b9a677de36d2a4923e7d4a9c2ae22108ab70..0676c6749831d4b43a2c5bd299881de5fe02efc7 100644 --- a/src/LIB/MPIvide/mpi.h +++ b/src/LIB/MPIvide/mpi.h @@ -4,6 +4,10 @@ * (C) 1993 by Argonne National Laboratory and Mississipi State University. * All rights reserved. See COPYRIGHT in top-level directory. */ +/* Modifications: + P.Wautelet 19/11/2021: add MPI_LOGICAL4 and MPI_LOGICAL8 optional types +! + modify MPI_REAL4/8 and MPI_INTEGER4/8 +*/ /* user include file for MPI programs */ @@ -94,6 +98,13 @@ typedef int MPI_Datatype; #define MPI_2DOUBLE_PRECISION ((MPI_Datatype)33) #define MPI_CHARACTER ((MPI_Datatype)1) +#define MPI_INTEGER4 ((MPI_Datatype)34) +#define MPI_INTEGER8 ((MPI_Datatype)35) +#define MPI_LOGICAL4 ((MPI_Datatype)36) +#define MPI_LOGICAL8 ((MPI_Datatype)37) +#define MPI_REAL4 ((MPI_Datatype)38) +#define MPI_REAL8 ((MPI_Datatype)39) + /* Communicators */ typedef int MPI_Comm; #define MPI_COMM_WORLD 91 diff --git a/src/LIB/MPIvide/mpif.h b/src/LIB/MPIvide/mpif.h index 97f91109c93e21ebb5e4b2f2131e79459448cb28..3557e3f48a6dc9f63d4bae9675f239d208534d7c 100644 --- a/src/LIB/MPIvide/mpif.h +++ b/src/LIB/MPIvide/mpif.h @@ -1,3 +1,6 @@ +!Modifications: +! P.Wautelet 19/11/2021: add MPI_LOGICAL4 and MPI_LOGICAL8 optional types +! + modify MPI_REAL4/8 and MPI_INTEGER4/8 ! ! ! (C) 1993 by Argonne National Laboratory and Mississipi State University. @@ -125,7 +128,7 @@ PARAMETER (MPI_2REAL=32,MPI_2DOUBLE_PRECISION=33,MPI_CHARACTER=1) PARAMETER (MPI_BYTE=3,MPI_UB=16,MPI_LB=15,MPI_PACKED=14) - INTEGER MPI_ORDER_C, MPI_ORDER_FORTRAN + INTEGER MPI_ORDER_C, MPI_ORDER_FORTRAN PARAMETER (MPI_ORDER_C=56, MPI_ORDER_FORTRAN=57) INTEGER MPI_DISTRIBUTE_BLOCK, MPI_DISTRIBUTE_CYCLIC INTEGER MPI_DISTRIBUTE_NONE, MPI_DISTRIBUTE_DFLT_DARG @@ -144,16 +147,19 @@ INTEGER MPI_INTEGER16 INTEGER MPI_REAL4, MPI_REAL8, MPI_REAL16 INTEGER MPI_COMPLEX8, MPI_COMPLEX16, MPI_COMPLEX32 + INTEGER MPI_LOGICAL4, MPI_LOGICAL8 PARAMETER (MPI_INTEGER1=1,MPI_INTEGER2=4) - PARAMETER (MPI_INTEGER4=6) - PARAMETER (MPI_INTEGER8=13) + PARAMETER (MPI_INTEGER4=34) + PARAMETER (MPI_INTEGER8=35) PARAMETER (MPI_INTEGER16=0) - PARAMETER (MPI_REAL4=10) - PARAMETER (MPI_REAL8=11) + PARAMETER (MPI_REAL4=38) + PARAMETER (MPI_REAL8=39) PARAMETER (MPI_REAL16=0) PARAMETER (MPI_COMPLEX8=23) PARAMETER (MPI_COMPLEX16=24) PARAMETER (MPI_COMPLEX32=0) + PARAMETER (MPI_LOGICAL4=36) + PARAMETER (MPI_LOGICAL8=37) COMMON /MPIPRIV/ MPI_BOTTOM,MPI_STATUS_IGNORE,MPI_STATUSES_IGNORE ! diff --git a/src/LIB/MPIvide/mpivide.c b/src/LIB/MPIvide/mpivide.c index 313f162a8e4d4717add7bf80eeb03ddd0a144f20..eebe91b71a8e3178634fb98688f9118c8325037b 100644 --- a/src/LIB/MPIvide/mpivide.c +++ b/src/LIB/MPIvide/mpivide.c @@ -1,51 +1,39 @@ -/* -MNH_LIC Copyright 1994-2014 CNRS, Meteo-France and Universite Paul Sabatier +/* +MNH_LIC Copyright 1994-2021 CNRS, Meteo-France and Universite Paul Sabatier MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence -MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt +MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt MNH_LIC for details. version 1. -*/ +*/ +/* Modifications : + P. Wautelet 19/11/2021: add function findtypesize + improve/add support for 32 and 64 bits variables + add mpi_reduce +*/ + +#include <stdio.h> #include <string.h> #include "mpi.h" -/* Variables defined in meso-nh code */ -#ifdef FUJI -#if MNH_REAL == 4 - #define MPI_PRECISION MPI_REAL - #define MPI_2PRECISION MPI_2REAL -#else - #define MPI_PRECISION MPI_DOUBLE_PRECISION - #define MPI_2PRECISION MPI_2DOUBLE_PRECISION -#endif -#else - #define MPI_PRECISION MPI_REAL - #define MPI_2PRECISION MPI_2REAL -#endif +/* MPI_INTEGER is defined in mpi.h */ +#define SIZEINTEGER4 4 +#define SIZEINTEGER8 8 -/* MPI_INTEGER is defined in mpi.h */ +#define SIZELOGICAL4 4 +#define SIZELOGICAL8 8 -#define MPI_INTEGER8 MPI_LONG_LONG_INT +#define SIZEREAL4 4 +#define SIZEREAL8 8 -#ifdef FUJI -#if MNH_INT == 8 +#if MNH_INT == 8 #define SIZEINTEGER 8 -#define SIZEINTEGER8 8 #define SIZELOGICAL 8 #else #define SIZEINTEGER 4 -#define SIZEINTEGER8 8 #define SIZELOGICAL 4 #endif #if MNH_REAL == 4 #define SIZEPRECISION 4 #define SIZE2PRECISION 8 #else -#define SIZEPRECISION 8 -#define SIZE2PRECISION 16 -#endif -#else -#define SIZEINTEGER 8 -#define SIZEINTEGER8 8 #define SIZEPRECISION 8 #define SIZE2PRECISION 16 #endif @@ -65,6 +53,57 @@ char *fct; /* printf("MPIVIDE::Passage dans %s \n", fct); */ } +int findtypesize(int type) +{ + int size; + + switch(type) + { + case MPI_INTEGER4: + size = SIZEINTEGER4 ; + break; + case MPI_INTEGER8: + size = SIZEINTEGER8 ; + break; + case MPI_LOGICAL4: + size = SIZELOGICAL4 ; + break; + case MPI_LOGICAL8: + size = SIZELOGICAL8 ; + break; + case MPI_REAL4: + size = SIZEREAL4 ; + break; + case MPI_REAL8: + size = SIZEREAL8 ; + break; + case MPI_2REAL: + size = 2*SIZEPRECISION ; + break; + case MPI_2DOUBLE_PRECISION: + size = 2*SIZE2PRECISION ; + break; + case MPI_INTEGER: + size = SIZEINTEGER; + break; + case MPI_REAL: + size = SIZEPRECISION; + break; + case MPI_DOUBLEDOUBLE: + size = SIZE_DOUBLEDOUBLE; + break; + case MPI_LOGICAL: + size = SIZELOGICAL ; + break; + default: + printf("ERROR : unknown precision in findtypesize (MPIVIDE library)\n"); + size = SIZEPRECISION; + break; + } + + return size; +} + #pragma weak mpi_cart_sub__ = mpi_cart_sub #pragma weak mpi_cart_sub_ = mpi_cart_sub void mpi_cart_sub @@ -127,26 +166,10 @@ void mpi_alltoallv(void *sendbuf, int *sendcounts, void *recvbuf, int *recvcounts, int *rdispls, int *recvtype, int *comm, int *__ierr) { - int size = SIZE2PRECISION; + int size; + disppass("alltoallv"); - switch(*sendtype) - { - case MPI_INTEGER: - size = SIZEINTEGER; - break; - case MPI_PRECISION: - size = SIZEPRECISION; - break; - case MPI_2PRECISION: - size = SIZE2PRECISION; - break; - case MPI_DOUBLEDOUBLE: - size = SIZE_DOUBLEDOUBLE; - break; - case MPI_LOGICAL: - size = SIZELOGICAL ; - break; - } + size = findtypesize(*sendtype); memcpy(recvbuf, sendbuf, (*recvcounts)*size); *__ierr = 0; @@ -176,30 +199,10 @@ int *recvtype; int *comm; int *__ierr; { - int size = SIZE2PRECISION; - disppass("allgatherv"); - - switch(*sendtype) - { - case MPI_INTEGER: - size = SIZEINTEGER; - break; - case MPI_INTEGER8: - size = SIZEINTEGER8; - break; - case MPI_PRECISION: - size = SIZEPRECISION; - break; - case MPI_2PRECISION: - size = SIZE2PRECISION; - break; - case MPI_DOUBLEDOUBLE: - size = SIZE_DOUBLEDOUBLE; - break; - case MPI_LOGICAL: - size = SIZELOGICAL ; - break; - } + int size; + + disppass("allgatherv"); + size = findtypesize(*sendtype); memcpy(recvbuf, sendbuf, (*recvcounts)*size); *__ierr = 0; } @@ -219,29 +222,10 @@ int *root; int *comm; int *__ierr; { - int size = SIZE2PRECISION; + int size; + disppass("gather"); - switch(*sendtype) - { - case MPI_INTEGER: - size = SIZEINTEGER; - break; - case MPI_PRECISION: - size = SIZEPRECISION; - break; - case MPI_2PRECISION: - size = SIZE2PRECISION; - break; - case MPI_DOUBLEDOUBLE: - size = SIZE_DOUBLEDOUBLE; - break; - case MPI_DOUBLE: - size = 8 ; - break; - case MPI_LOGICAL: - size = SIZELOGICAL ; - break; - } + size = findtypesize(*sendtype); memcpy(recvbuf, sendbuf, (*recvcount)*size); *__ierr = 0; @@ -263,26 +247,10 @@ int *root; int *comm; int *__ierr; { - int size = SIZE2PRECISION; + int size; + disppass("gatherv"); - switch(*sendtype) - { - case MPI_INTEGER: - size = SIZEINTEGER; - break; - case MPI_PRECISION: - size = SIZEPRECISION; - break; - case MPI_2PRECISION: - size = SIZE2PRECISION; - break; - case MPI_DOUBLEDOUBLE: - size = SIZE_DOUBLEDOUBLE; - break; - case MPI_LOGICAL: - size = SIZELOGICAL ; - break; - } + size = findtypesize(*sendtype); memcpy(recvbuf, sendbuf, (*recvcounts)*size); *__ierr = 0; @@ -352,26 +320,10 @@ int *recvtype; int *comm; int *__ierr; { - int size = SIZE2PRECISION; + int size; + disppass("allgather"); - switch(*sendtype) - { - case MPI_INTEGER: - size = SIZEINTEGER; - break; - case MPI_PRECISION: - size = SIZEPRECISION; - break; - case MPI_2PRECISION: - size = SIZE2PRECISION; - break; - case MPI_DOUBLEDOUBLE: - size = SIZE_DOUBLEDOUBLE; - break; - case MPI_LOGICAL: - size = SIZELOGICAL ; - break; - } + size = findtypesize(*sendtype); memcpy(recvbuf, sendbuf, (*recvcount)*size); *__ierr = 0; @@ -425,28 +377,32 @@ int *comm; int *op; int *__ierr; { - int size = SIZE2PRECISION; + int size; disppass("allreduce"); - switch(*datatype) - { - case MPI_INTEGER: - size = SIZEINTEGER; - break; - case MPI_PRECISION: - size = SIZEPRECISION; - break; - case MPI_2PRECISION: - size = SIZE2PRECISION; - break; - case MPI_DOUBLE: - size = 8 ; - break; - case MPI_LOGICAL: - size = SIZELOGICAL ; - break; - } - memcpy(recvbuf, sendbuf, (*count)*size); + size = findtypesize(*datatype); + memcpy(recvbuf, sendbuf, (*count)*size); + *__ierr = 0; +} + +#pragma weak mpi_reduce__ = mpi_reduce +#pragma weak mpi_reduce_ = mpi_reduce +void mpi_reduce +( sendbuf, recvbuf, count, datatype, op, root, comm, __ierr ) +void *sendbuf; +void *recvbuf; +int *count; +int *datatype; +int *root; +int *comm; +int *op; +int *__ierr; +{ + int size; + + disppass("reduce"); + size = findtypesize(*datatype); + memcpy(recvbuf, sendbuf, (*count)*size); *__ierr = 0; } diff --git a/src/Makefile.MESONH.mk b/src/Makefile.MESONH.mk index c5770feb3d53e10292fe3041a0aa9d2585780adf..72a5827a7f72fce43c57c373f3a00eadac2a000d 100644 --- a/src/Makefile.MESONH.mk +++ b/src/Makefile.MESONH.mk @@ -337,7 +337,7 @@ INC_MPI = -I$(B)$(DIR_MPI) DIR_MASTER += $(DIR_MPI) OBJS_LISTE_MASTER += mpivide.o INC += $(INC_MPI) -mpivide.o : CPPFLAGS += -DFUJI -DMNH_INT=$(MNH_INT) -DMNH_REAL=$(MNH_REAL) \ +mpivide.o : CPPFLAGS += -DMNH_INT=$(MNH_INT) -DMNH_REAL=$(MNH_REAL) \ -I$(DIR_MPI)/include VPATH += $(DIR_MPI) endif