From: Arnaud Giersch Date: Fri, 15 Nov 2013 22:25:21 +0000 (+0100) Subject: Some constants need to be defined as static variables in Fortran. X-Git-Tag: v3_11_beta~288 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/07bacc793410c12a213226b8be422a67157dd9de Some constants need to be defined as static variables in Fortran. See for example section 2.5.4 (Named constants) of the MPI2 standard. http://www.mcs.anl.gov/research/projects/mpi/mpi-standard/mpi-report-2.0/node13.htm --- diff --git a/include/smpi/mpif.h.in b/include/smpi/mpif.h.in index 213fe84904..56ab46b983 100644 --- a/include/smpi/mpif.h.in +++ b/include/smpi/mpif.h.in @@ -18,7 +18,7 @@ integer MPI_MAX_DATAREP_STRIN, MPI_MAX_INFO_KEY integer MPI_MAX_INFO_VAL, MPI_MAX_OBJECT_NAME, MPI_MAX_PORT_NAME integer MPI_ANY_SOURCE, MPI_PROC_NULL, MPI_ANY_TAG, MPI_UNDEFINED - integer MPI_IN_PLACE, MPI_BOTTOM, MPI_TAG_UB, MPI_TAG_LB + integer MPI_TAG_UB, MPI_TAG_LB integer MPI_SOURCE, MPI_TAG, MPI_ERROR integer MPI_VERSION, MPI_SUBVERSION parameter(MPI_MAX_PROCESSOR_NAME=100) @@ -32,8 +32,6 @@ parameter(MPI_PROC_NULL=-666) parameter(MPI_ANY_TAG=-444) parameter(MPI_UNDEFINED=-333) - parameter(MPI_IN_PLACE=-222) - parameter(MPI_BOTTOM=-111) parameter(MPI_SOURCE=1) parameter(MPI_TAG=2) parameter(MPI_ERROR=3) @@ -109,12 +107,14 @@ parameter(MPI_ERRHANDLER_NULL=2) ! This should be equal to the number of int fields in MPI_Status - integer MPI_STATUS_SIZE, MPI_STATUSES_IGNORE + integer MPI_STATUS_SIZE parameter(MPI_STATUS_SIZE=4) - parameter(MPI_STATUSES_IGNORE=-1) - integer MPI_STATUS_IGNORE - parameter(MPI_STATUS_IGNORE=-1) +! These should be ordered as in smpi_f77.c + integer MPI_IN_PLACE, MPI_BOTTOM + integer MPI_STATUS_IGNORE, MPI_STATUSES_IGNORE + common /smpi/ MPI_IN_PLACE, MPI_BOTTOM + common /smpi/ MPI_STATUS_IGNORE, MPI_STATUSES_IGNORE integer MPI_REQUEST_NULL parameter(MPI_REQUEST_NULL=-1) @@ -122,7 +122,6 @@ integer MPI_INTEGER_KIND parameter(MPI_INTEGER_KIND=4) -! These should be ordered as in smpi_f77.c integer MPI_DATATYPE_NULL, MPI_BYTE, MPI_CHARACTER, MPI_LOGICAL integer MPI_INTEGER, MPI_INTEGER1, MPI_INTEGER2, MPI_INTEGER4 integer MPI_INTEGER8, MPI_REAL, MPI_REAL4, MPI_REAL8 diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 3901734b77..4b91260cdf 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -41,12 +41,10 @@ SG_BEGIN_DECL() #define SMPI_RAND_SEED 5 #define MPI_ANY_SOURCE -555 #define MPI_BOTTOM (void *)-111 -#define MPI_FORTRAN_BOTTOM -111 #define MPI_PROC_NULL -666 #define MPI_ANY_TAG -444 #define MPI_UNDEFINED -333 #define MPI_IN_PLACE (void *)-222 -#define MPI_FORTRAN_IN_PLACE -222 // errorcodes #define MPI_SUCCESS 0 @@ -167,8 +165,6 @@ typedef struct { #define MPI_STATUS_IGNORE ((MPI_Status*)NULL) #define MPI_STATUSES_IGNORE ((MPI_Status*)NULL) -#define MPI_FORTRAN_STATUS_IGNORE -1 -#define MPI_FORTRAN_STATUSES_IGNORE -1 #define MPI_DATATYPE_NULL ((MPI_Datatype)NULL) XBT_PUBLIC_DATA( MPI_Datatype ) MPI_CHAR; diff --git a/src/smpi/smpi_f77.c b/src/smpi/smpi_f77.c index 0f49e2ee0a..43c93d3510 100644 --- a/src/smpi/smpi_f77.c +++ b/src/smpi/smpi_f77.c @@ -20,13 +20,32 @@ static xbt_dict_t datatype_lookup = NULL; static xbt_dict_t op_lookup = NULL; static int running_processes = 0; - - -/* Convert between Fortran and C MPI_BOTTOM */ -#define F2C_BOTTOM(addr) ((addr!=MPI_IN_PLACE && *(int*)addr == MPI_FORTRAN_BOTTOM) ? MPI_BOTTOM : (addr)) -#define F2C_IN_PLACE(addr) ((addr!=MPI_BOTTOM &&*(int*)addr == MPI_FORTRAN_IN_PLACE) ? MPI_IN_PLACE : (addr)) -#define F2C_STATUS_IGNORE(addr) ((*(int*)addr == MPI_FORTRAN_STATUS_IGNORE) ? MPI_STATUS_IGNORE : (addr)) -#define F2C_STATUSES_IGNORE(addr) ((*(int*)addr == MPI_FORTRAN_STATUSES_IGNORE) ? MPI_STATUSES_IGNORE : (addr)) +/* Bindings for MPI special values */ +union u_smpi_common { + struct s_smpi_common { + integer mpi_in_place; + integer mpi_bottom; + integer mpi_status_ignore; + integer mpi_statuses_ignore; + } f90; /* with gftortran */ + struct s_smpi_common *f77; /* with f2c */ +} smpi_; + +/* Convert between Fortran and C */ +static XBT_INLINE void *f2c_addr(void *addr, void *cval, void *chk1, void *chk2) +{ + return (addr == chk1 || addr == chk2) ? cval : addr; +} +#define F2C_ADDR(addr, cval, fval) \ + f2c_addr(addr, cval, &smpi_.f90.fval, &smpi_.f77[smpi_current_rank].fval) +#define F2C_BOTTOM(addr) \ + F2C_ADDR(addr, MPI_BOTTOM, mpi_bottom) +#define F2C_IN_PLACE(addr) \ + F2C_ADDR(addr, MPI_IN_PLACE, mpi_in_place) +#define F2C_STATUS_IGNORE(addr) \ + F2C_ADDR(addr, MPI_STATUS_IGNORE, mpi_status_ignore) +#define F2C_STATUSES_IGNORE(addr) \ + F2C_ADDR(addr, MPI_STATUSES_IGNORE, mpi_statuses_ignore) #define KEY_SIZE (sizeof(int) * 2 + 1)