X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/281f8c29e177852dcb1591fc31e363e1176857c8..22099d0593f8067506657185076e10cbeafe5760:/src/smpi/smpi_f77.c?ds=sidebyside diff --git a/src/smpi/smpi_f77.c b/src/smpi/smpi_f77.c index 0f49e2ee0a..87fe053d2b 100644 --- a/src/smpi/smpi_f77.c +++ b/src/smpi/smpi_f77.c @@ -1,8 +1,8 @@ -/* Copyright (c) 2010-2013. The SimGrid Team. +/* Copyright (c) 2010-2014. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ #include #include @@ -10,23 +10,41 @@ #include "private.h" #include "xbt.h" -extern int xargc; -extern char** xargv; - static xbt_dict_t comm_lookup = NULL; static xbt_dict_t group_lookup = NULL; static xbt_dict_t request_lookup = NULL; static xbt_dict_t datatype_lookup = NULL; static xbt_dict_t op_lookup = NULL; +static xbt_dict_t win_lookup = NULL; static int running_processes = 0; +#if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__) +typedef int integer; +typedef unsigned int uinteger; +#else +typedef long int integer; +typedef unsigned long int uinteger; +#endif + +/* Bindings for MPI special values */ + + struct s_smpi_common { + integer _MPI_IN_PLACE; + integer _MPI_BOTTOM; + integer _MPI_STATUS_IGNORE; + integer _MPI_STATUSES_IGNORE; + } smpi_; + -/* 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)) +/* Convert between Fortran and C */ +#define FORT_ADDR(addr, val) \ + (((void *)(addr) == (void*) &(smpi_._ ## val)) \ + ? (val) : (void *)(addr)) +#define FORT_BOTTOM(addr) FORT_ADDR(addr, MPI_BOTTOM) +#define FORT_IN_PLACE(addr) FORT_ADDR(addr, MPI_IN_PLACE) +#define FORT_STATUS_IGNORE(addr) FORT_ADDR(addr, MPI_STATUS_IGNORE) +#define FORT_STATUSES_IGNORE(addr) FORT_ADDR(addr, MPI_STATUSES_IGNORE) #define KEY_SIZE (sizeof(int) * 2 + 1) @@ -152,19 +170,44 @@ static void free_op(int op) { xbt_dict_remove(op_lookup, get_key(key, op)); } +static int new_win(MPI_Win win) { + static int win_id = 0; + char key[KEY_SIZE]; + xbt_dict_set(win_lookup, get_key(key, win_id), win, NULL); + win_id++; + return win_id-1; +} + +static MPI_Win get_win(int win) { + char key[KEY_SIZE]; + return win >= 0 + ? (MPI_Win)xbt_dict_get_or_null(win_lookup, get_key(key, win)) + : MPI_WIN_NULL; +} + +static void free_win(int win) { + char key[KEY_SIZE]; + xbt_dict_remove(win_lookup, get_key(key, win)); +} + + void mpi_init_(int* ierr) { if(!comm_lookup){ comm_lookup = xbt_dict_new_homogeneous(NULL); new_comm(MPI_COMM_WORLD); group_lookup = xbt_dict_new_homogeneous(NULL); - request_lookup = xbt_dict_new_homogeneous(NULL); - datatype_lookup = xbt_dict_new_homogeneous(NULL); + win_lookup = xbt_dict_new_homogeneous(NULL); new_datatype(MPI_BYTE); new_datatype(MPI_CHAR); + #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__) new_datatype(MPI_INT); new_datatype(MPI_INT); + #else + new_datatype(MPI_LONG); + new_datatype(MPI_LONG); + #endif new_datatype(MPI_INT8_T); new_datatype(MPI_INT16_T); new_datatype(MPI_INT32_T); @@ -175,7 +218,11 @@ void mpi_init_(int* ierr) { new_datatype(MPI_DOUBLE); new_datatype(MPI_C_FLOAT_COMPLEX); new_datatype(MPI_C_DOUBLE_COMPLEX); + #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__) new_datatype(MPI_2INT); + #else + new_datatype(MPI_2LONG); + #endif new_datatype(MPI_UINT8_T); new_datatype(MPI_UINT16_T); new_datatype(MPI_UINT32_T); @@ -203,7 +250,6 @@ void mpi_init_(int* ierr) { new_op(MPI_BOR); new_op(MPI_BXOR); } - /* smpif2c is responsible for generating a call with the final arguments */ *ierr = MPI_Init(NULL, NULL); running_processes++; } @@ -315,7 +361,7 @@ void mpi_send_init_(void *buf, int* count, int* datatype, int* dst, int* tag, void mpi_isend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) { MPI_Request req; - buf = (char *) F2C_BOTTOM(buf); + buf = (char *) FORT_BOTTOM(buf); *ierr = MPI_Isend(buf, *count, get_datatype(*datatype), *dst, *tag, get_comm(*comm), &req); if(*ierr == MPI_SUCCESS) { @@ -326,7 +372,7 @@ void mpi_isend_(void *buf, int* count, int* datatype, int* dst, void mpi_irsend_(void *buf, int* count, int* datatype, int* dst, int* tag, int* comm, int* request, int* ierr) { MPI_Request req; - buf = (char *) F2C_BOTTOM(buf); + buf = (char *) FORT_BOTTOM(buf); *ierr = MPI_Irsend(buf, *count, get_datatype(*datatype), *dst, *tag, get_comm(*comm), &req); if(*ierr == MPI_SUCCESS) { @@ -352,7 +398,7 @@ void mpi_sendrecv_(void* sendbuf, int* sendcount, int* sendtype, int* dst, int* comm, MPI_Status* status, int* ierr) { *ierr = MPI_Sendrecv(sendbuf, *sendcount, get_datatype(*sendtype), *dst, *sendtag, recvbuf, *recvcount,get_datatype(*recvtype), *src, *recvtag, - get_comm(*comm), F2C_STATUS_IGNORE(status)); + get_comm(*comm), FORT_STATUS_IGNORE(status)); } void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag, @@ -369,7 +415,7 @@ void mpi_recv_init_(void *buf, int* count, int* datatype, int* src, int* tag, void mpi_irecv_(void *buf, int* count, int* datatype, int* src, int* tag, int* comm, int* request, int* ierr) { MPI_Request req; - buf = (char *) F2C_BOTTOM(buf); + buf = (char *) FORT_BOTTOM(buf); *ierr = MPI_Irecv(buf, *count, get_datatype(*datatype), *src, *tag, get_comm(*comm), &req); if(*ierr == MPI_SUCCESS) { @@ -404,7 +450,7 @@ void mpi_startall_(int* count, int* requests, int* ierr) { void mpi_wait_(int* request, MPI_Status* status, int* ierr) { MPI_Request req = find_request(*request); - *ierr = MPI_Wait(&req, F2C_STATUS_IGNORE(status)); + *ierr = MPI_Wait(&req, FORT_STATUS_IGNORE(status)); if(req==MPI_REQUEST_NULL){ free_request(*request); *request=MPI_FORTRAN_REQUEST_NULL; @@ -435,7 +481,7 @@ void mpi_waitall_(int* count, int* requests, MPI_Status* status, int* ierr) { for(i = 0; i < *count; i++) { reqs[i] = find_request(requests[i]); } - *ierr = MPI_Waitall(*count, reqs, F2C_STATUSES_IGNORE(status)); + *ierr = MPI_Waitall(*count, reqs, FORT_STATUSES_IGNORE(status)); for(i = 0; i < *count; i++) { if(reqs[i]==MPI_REQUEST_NULL){ free_request(requests[i]); @@ -456,23 +502,23 @@ void mpi_bcast_(void *buf, int* count, int* datatype, int* root, int* comm, int* void mpi_reduce_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* root, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); - sendbuf = (char *) F2C_BOTTOM(sendbuf); - recvbuf = (char *) F2C_BOTTOM(recvbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_BOTTOM(sendbuf); + recvbuf = (char *) FORT_BOTTOM(recvbuf); *ierr = MPI_Reduce(sendbuf, recvbuf, *count, get_datatype(*datatype), get_op(*op), *root, get_comm(*comm)); } void mpi_allreduce_(void* sendbuf, void* recvbuf, int* count, int* datatype, int* op, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); *ierr = MPI_Allreduce(sendbuf, recvbuf, *count, get_datatype(*datatype), get_op(*op), get_comm(*comm)); } void mpi_reduce_scatter_(void* sendbuf, void* recvbuf, int* recvcounts, int* datatype, int* op, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); *ierr = MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, get_datatype(*datatype), get_op(*op), get_comm(*comm)); } @@ -480,7 +526,7 @@ void mpi_reduce_scatter_(void* sendbuf, void* recvbuf, int* recvcounts, int* dat void mpi_scatter_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype, int* root, int* comm, int* ierr) { - recvbuf = (char *) F2C_IN_PLACE(recvbuf); + recvbuf = (char *) FORT_IN_PLACE(recvbuf); *ierr = MPI_Scatter(sendbuf, *sendcount, get_datatype(*sendtype), recvbuf, *recvcount, get_datatype(*recvtype), *root, get_comm(*comm)); } @@ -489,7 +535,7 @@ void mpi_scatter_(void* sendbuf, int* sendcount, int* sendtype, void mpi_scatterv_(void* sendbuf, int* sendcounts, int* displs, int* sendtype, void* recvbuf, int* recvcount, int* recvtype, int* root, int* comm, int* ierr) { - recvbuf = (char *) F2C_IN_PLACE(recvbuf); + recvbuf = (char *) FORT_IN_PLACE(recvbuf); *ierr = MPI_Scatterv(sendbuf, sendcounts, displs, get_datatype(*sendtype), recvbuf, *recvcount, get_datatype(*recvtype), *root, get_comm(*comm)); } @@ -497,9 +543,9 @@ void mpi_scatterv_(void* sendbuf, int* sendcounts, int* displs, int* sendtype, void mpi_gather_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype, int* root, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); - sendbuf = (char *) F2C_BOTTOM(sendbuf); - recvbuf = (char *) F2C_BOTTOM(recvbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_BOTTOM(sendbuf); + recvbuf = (char *) FORT_BOTTOM(recvbuf); *ierr = MPI_Gather(sendbuf, *sendcount, get_datatype(*sendtype), recvbuf, *recvcount, get_datatype(*recvtype), *root, get_comm(*comm)); } @@ -507,9 +553,9 @@ void mpi_gather_(void* sendbuf, int* sendcount, int* sendtype, void mpi_gatherv_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcounts, int* displs, int* recvtype, int* root, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); - sendbuf = (char *) F2C_BOTTOM(sendbuf); - recvbuf = (char *) F2C_BOTTOM(recvbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_BOTTOM(sendbuf); + recvbuf = (char *) FORT_BOTTOM(recvbuf); *ierr = MPI_Gatherv(sendbuf, *sendcount, get_datatype(*sendtype), recvbuf, recvcounts, displs, get_datatype(*recvtype), *root, get_comm(*comm)); } @@ -517,7 +563,7 @@ void mpi_gatherv_(void* sendbuf, int* sendcount, int* sendtype, void mpi_allgather_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcount, int* recvtype, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); *ierr = MPI_Allgather(sendbuf, *sendcount, get_datatype(*sendtype), recvbuf, *recvcount, get_datatype(*recvtype), get_comm(*comm)); } @@ -525,7 +571,7 @@ void mpi_allgather_(void* sendbuf, int* sendcount, int* sendtype, void mpi_allgatherv_(void* sendbuf, int* sendcount, int* sendtype, void* recvbuf, int* recvcounts,int* displs, int* recvtype, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); *ierr = MPI_Allgatherv(sendbuf, *sendcount, get_datatype(*sendtype), recvbuf, recvcounts, displs, get_datatype(*recvtype), get_comm(*comm)); } @@ -550,7 +596,7 @@ void mpi_alltoallv_(void* sendbuf, int* sendcounts, int* senddisps, int* sendtyp void mpi_test_ (int * request, int *flag, MPI_Status * status, int* ierr){ MPI_Request req = find_request(*request); - *ierr= MPI_Test(&req, flag, F2C_STATUS_IGNORE(status)); + *ierr= MPI_Test(&req, flag, FORT_STATUS_IGNORE(status)); if(req==MPI_REQUEST_NULL){ free_request(*request); *request=MPI_FORTRAN_REQUEST_NULL; @@ -565,7 +611,7 @@ void mpi_testall_ (int* count, int * requests, int *flag, MPI_Status * statuses for(i = 0; i < *count; i++) { reqs[i] = find_request(requests[i]); } - *ierr= MPI_Testall(*count, reqs, flag, F2C_STATUSES_IGNORE(statuses)); + *ierr= MPI_Testall(*count, reqs, flag, FORT_STATUSES_IGNORE(statuses)); for(i = 0; i < *count; i++) { if(reqs[i]==MPI_REQUEST_NULL){ free_request(requests[i]); @@ -580,7 +626,7 @@ void mpi_get_processor_name_(char *name, int *resultlen, int* ierr){ } void mpi_get_count_(MPI_Status * status, int* datatype, int *count, int* ierr){ - *ierr = MPI_Get_count(F2C_STATUS_IGNORE(status), get_datatype(*datatype), count); + *ierr = MPI_Get_count(FORT_STATUS_IGNORE(status), get_datatype(*datatype), count); } void mpi_attr_get_(int* comm, int* keyval, void* attr_value, int* flag, int* ierr ){ @@ -654,15 +700,33 @@ void mpi_error_string_(int* errorcode, char* string, int* resultlen, int* ierr){ } void mpi_win_fence_( int* assert, int* win, int* ierr){ - *ierr = MPI_Win_fence(* assert, *(MPI_Win*)win); + *ierr = MPI_Win_fence(* assert, get_win(*win)); } void mpi_win_free_( int* win, int* ierr){ - *ierr = MPI_Win_free( (MPI_Win*)win); + MPI_Win tmp = get_win(*win); + *ierr = MPI_Win_free(&tmp); + if(*ierr == MPI_SUCCESS) { + free_win(*win); + } } void mpi_win_create_( int *base, MPI_Aint* size, int* disp_unit, int* info, int* comm, int *win, int* ierr){ - *ierr = MPI_Win_create( (void*)base, *size, *disp_unit, *(MPI_Info*)info, get_comm(*comm),(MPI_Win*)win); + MPI_Win tmp; + *ierr = MPI_Win_create( (void*)base, *size, *disp_unit, *(MPI_Info*)info, get_comm(*comm),&tmp); + if(*ierr == MPI_SUCCESS) { + *win = new_win(tmp); + } +} + +void mpi_win_set_name_ (int* win, char * name, int* ierr){ + + *ierr = MPI_Win_set_name(get_win(*win), name); +} + +void mpi_win_get_name_ (int* win, char * name, int* len, int* ierr){ + + *ierr = MPI_Win_get_name(get_win(*win),name,len); } void mpi_info_create_( int *info, int* ierr){ @@ -680,7 +744,19 @@ void mpi_info_free_(int* info, int* ierr){ void mpi_get_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank, MPI_Aint* target_disp, int *target_count, int* target_datatype, int* win, int* ierr){ *ierr = MPI_Get( (void*)origin_addr,*origin_count, get_datatype(*origin_datatype),*target_rank, - *target_disp, *target_count,get_datatype(*target_datatype), *(MPI_Win *)win); + *target_disp, *target_count,get_datatype(*target_datatype), get_win(*win)); +} + +void mpi_accumulate_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank, + MPI_Aint* target_disp, int *target_count, int* target_datatype, int* op, int* win, int* ierr){ + *ierr = MPI_Accumulate( (void*)origin_addr,*origin_count, get_datatype(*origin_datatype),*target_rank, + *target_disp, *target_count,get_datatype(*target_datatype), get_op(*op), get_win(*win)); +} + +void mpi_put_( int *origin_addr, int* origin_count, int* origin_datatype, int *target_rank, + MPI_Aint* target_disp, int *target_count, int* target_datatype, int* win, int* ierr){ + *ierr = MPI_Put( (void*)origin_addr,*origin_count, get_datatype(*origin_datatype),*target_rank, + *target_disp, *target_count,get_datatype(*target_datatype), get_win(*win)); } @@ -735,7 +811,7 @@ void mpi_init_thread_ (int* required, int *provided, int* ierr){ new_op(MPI_BOR); new_op(MPI_BXOR); } - /* smpif2c is responsible for generating a call with the final arguments */ + *ierr = MPI_Init_thread(NULL, NULL,*required, provided); } @@ -965,7 +1041,7 @@ void mpi_sendrecv_replace_ (void *buf, int* count, int* datatype, int* dst, int* { *ierr = MPI_Sendrecv_replace(buf, *count, get_datatype(*datatype), *dst, *sendtag, *src, - *recvtag, get_comm(*comm), F2C_STATUS_IGNORE(status)); + *recvtag, get_comm(*comm), FORT_STATUS_IGNORE(status)); } void mpi_testany_ (int* count, int* requests, int *index, int *flag, MPI_Status* status, int* ierr) @@ -977,7 +1053,7 @@ void mpi_testany_ (int* count, int* requests, int *index, int *flag, MPI_Status* for(i = 0; i < *count; i++) { reqs[i] = find_request(requests[i]); } - *ierr = MPI_Testany(*count, reqs, index, flag, F2C_STATUS_IGNORE(status)); + *ierr = MPI_Testany(*count, reqs, index, flag, FORT_STATUS_IGNORE(status)); if(*index!=MPI_UNDEFINED) if(reqs[*index]==MPI_REQUEST_NULL){ free_request(requests[*index]); @@ -1012,7 +1088,7 @@ void mpi_reduce_local_ (void *inbuf, void *inoutbuf, int* count, int* datatype, void mpi_reduce_scatter_block_ (void *sendbuf, void *recvbuf, int* recvcount, int* datatype, int* op, int* comm, int* ierr) { - sendbuf = (char *) F2C_IN_PLACE(sendbuf); + sendbuf = (char *) FORT_IN_PLACE(sendbuf); *ierr = MPI_Reduce_scatter_block(sendbuf, recvbuf, *recvcount, get_datatype(*datatype), get_op(*op), get_comm(*comm)); } @@ -1153,7 +1229,7 @@ void mpi_testsome_ (int* incount, int* requests, int* outcount, int* indices, M reqs[i] = find_request(requests[i]); indices[i]=0; } - *ierr = MPI_Testsome(*incount, reqs, outcount, indices, F2C_STATUSES_IGNORE(statuses)); + *ierr = MPI_Testsome(*incount, reqs, outcount, indices, FORT_STATUSES_IGNORE(statuses)); for(i=0;i<*incount;i++){ if(indices[i]){ if(reqs[indices[i]]==MPI_REQUEST_NULL){ @@ -1310,7 +1386,7 @@ void mpi_issend_ (void* buf, int* count, int* datatype, int *dest, int* tag, int } void mpi_probe_ (int* source, int* tag, int* comm, MPI_Status* status, int* ierr) { - *ierr = MPI_Probe(*source, *tag, get_comm(*comm), F2C_STATUS_IGNORE(status)); + *ierr = MPI_Probe(*source, *tag, get_comm(*comm), FORT_STATUS_IGNORE(status)); } void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) {