From: Augustin Degomme Date: Tue, 10 Dec 2019 01:10:08 +0000 (+0100) Subject: input sanitization continued. X-Git-Tag: v3.25~312 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8ca88f5944989c937734b5c28bfdd074aa990367 input sanitization continued. --- diff --git a/src/smpi/bindings/smpi_pmpi_comm.cpp b/src/smpi/bindings/smpi_pmpi_comm.cpp index 19d511ad25..1624842b2e 100644 --- a/src/smpi/bindings/smpi_pmpi_comm.cpp +++ b/src/smpi/bindings/smpi_pmpi_comm.cpp @@ -17,117 +17,84 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); int PMPI_Comm_rank(MPI_Comm comm, int *rank) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (rank == nullptr) { - return MPI_ERR_ARG; - } else { - *rank = comm->rank(); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, rank) + *rank = comm->rank(); + return MPI_SUCCESS; } int PMPI_Comm_size(MPI_Comm comm, int *size) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (size == nullptr) { - return MPI_ERR_ARG; - } else { - *size = comm->size(); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, size) + *size = comm->size(); + return MPI_SUCCESS; } int PMPI_Comm_get_name (MPI_Comm comm, char* name, int* len) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (name == nullptr || len == nullptr) { - return MPI_ERR_ARG; - } else { - comm->get_name(name, len); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, name) + CHECK_NULL(3, MPI_ERR_ARG, len) + comm->get_name(name, len); + return MPI_SUCCESS; } int PMPI_Comm_set_name (MPI_Comm comm, const char* name) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (name == nullptr) { - return MPI_ERR_ARG; - } else { - comm->set_name(name); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, name) + comm->set_name(name); + return MPI_SUCCESS; } int PMPI_Comm_group(MPI_Comm comm, MPI_Group * group) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (group == nullptr) { - return MPI_ERR_ARG; - } else { - *group = comm->group(); - if (*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY) - (*group)->ref(); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, group) + *group = comm->group(); + if (*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_NULL && *group != MPI_GROUP_EMPTY) + (*group)->ref(); + return MPI_SUCCESS; } int PMPI_Comm_compare(MPI_Comm comm1, MPI_Comm comm2, int *result) { - if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (result == nullptr) { - return MPI_ERR_ARG; + CHECK_COMM2(1, comm1) + CHECK_COMM2(2, comm2) + CHECK_NULL(3, MPI_ERR_ARG, result) + if (comm1 == comm2) { /* Same communicators means same groups */ + *result = MPI_IDENT; } else { - if (comm1 == comm2) { /* Same communicators means same groups */ - *result = MPI_IDENT; - } else { - *result = comm1->group()->compare(comm2->group()); - if (*result == MPI_IDENT) { - *result = MPI_CONGRUENT; - } + *result = comm1->group()->compare(comm2->group()); + if (*result == MPI_IDENT) { + *result = MPI_CONGRUENT; } - return MPI_SUCCESS; } + return MPI_SUCCESS; } int PMPI_Comm_dup(MPI_Comm comm, MPI_Comm * newcomm) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (newcomm == nullptr) { - return MPI_ERR_ARG; - } else { - return comm->dup(newcomm); - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, newcomm) + return comm->dup(newcomm); } int PMPI_Comm_dup_with_info(MPI_Comm comm, MPI_Info info, MPI_Comm * newcomm) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (newcomm == nullptr) { - return MPI_ERR_ARG; - } else { - comm->dup_with_info(info, newcomm); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, newcomm) + comm->dup_with_info(info, newcomm); + return MPI_SUCCESS; } int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newcomm == nullptr) { - return MPI_ERR_ARG; - } else if (group->rank(simgrid::s4u::this_actor::get_pid()) == MPI_UNDEFINED) { + CHECK_COMM(1) + CHECK_GROUP(2, group) + CHECK_NULL(3, MPI_ERR_ARG, newcomm) + if (group->rank(simgrid::s4u::this_actor::get_pid()) == MPI_UNDEFINED) { *newcomm= MPI_COMM_NULL; return MPI_SUCCESS; }else{ @@ -139,81 +106,51 @@ int PMPI_Comm_create(MPI_Comm comm, MPI_Group group, MPI_Comm * newcomm) int PMPI_Comm_free(MPI_Comm * comm) { - if (comm == nullptr) { - return MPI_ERR_ARG; - } else if (*comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else { - simgrid::smpi::Comm::destroy(*comm); - *comm = MPI_COMM_NULL; - return MPI_SUCCESS; - } + CHECK_NULL(1, MPI_ERR_ARG, comm) + CHECK_COMM2(1, *comm) + simgrid::smpi::Comm::destroy(*comm); + *comm = MPI_COMM_NULL; + return MPI_SUCCESS; } int PMPI_Comm_disconnect(MPI_Comm * comm) { /* TODO: wait until all communication in comm are done */ - if (comm == nullptr) { - return MPI_ERR_ARG; - } else if (*comm == MPI_COMM_NULL) { - return MPI_ERR_COMM; - } else { - simgrid::smpi::Comm::destroy(*comm); - *comm = MPI_COMM_NULL; - return MPI_SUCCESS; - } + CHECK_NULL(1, MPI_ERR_ARG, comm) + CHECK_COMM2(1, *comm) + simgrid::smpi::Comm::destroy(*comm); + *comm = MPI_COMM_NULL; + return MPI_SUCCESS; } int PMPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm* comm_out) { - int retval = 0; + CHECK_NULL(4, MPI_ERR_ARG, comm_out) + CHECK_COMM2(1, comm) smpi_bench_end(); - - if (comm_out == nullptr) { - retval = MPI_ERR_ARG; - } else if (comm == MPI_COMM_NULL) { - retval = MPI_ERR_COMM; - } else { - *comm_out = comm->split(color, key); - retval = MPI_SUCCESS; - } + *comm_out = comm->split(color, key); smpi_bench_begin(); - - return retval; + return MPI_SUCCESS; } int PMPI_Comm_split_type(MPI_Comm comm, int split_type, int key, MPI_Info info, MPI_Comm *newcomm) { - int retval = 0; + CHECK_COMM(1) + CHECK_NULL(5, MPI_ERR_ARG, newcomm) smpi_bench_end(); - - if (newcomm == nullptr) { - retval = MPI_ERR_ARG; - } else if (comm == MPI_COMM_NULL) { - retval = MPI_ERR_COMM; - } else { - *newcomm = comm->split_type(split_type, key, info); - retval = MPI_SUCCESS; - } + *newcomm = comm->split_type(split_type, key, info); smpi_bench_begin(); - - return retval; + return MPI_SUCCESS; } int PMPI_Comm_create_group(MPI_Comm comm, MPI_Group group, int, MPI_Comm* comm_out) { - int retval = 0; + CHECK_COMM(1) + CHECK_GROUP(2, group) + CHECK_NULL(5, MPI_ERR_ARG, comm_out) smpi_bench_end(); - - if (comm_out == nullptr) { - retval = MPI_ERR_ARG; - } else if (comm == MPI_COMM_NULL) { - retval = MPI_ERR_COMM; - } else { - retval = MPI_Comm_create(comm, group, comm_out); - } + int retval = MPI_Comm_create(comm, group, comm_out); smpi_bench_begin(); - return retval; } @@ -241,22 +178,17 @@ int PMPI_Comm_set_attr (MPI_Comm comm, int comm_keyval, void *attribute_val) int PMPI_Comm_get_info(MPI_Comm comm, MPI_Info* info) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_WIN; - } else { - *info = comm->info(); - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_ARG, info) + *info = comm->info(); + return MPI_SUCCESS; } int PMPI_Comm_set_info(MPI_Comm comm, MPI_Info info) { - if (comm == MPI_COMM_NULL) { - return MPI_ERR_TYPE; - } else { - comm->set_info(info); - return MPI_SUCCESS; - } + CHECK_COMM(1) + comm->set_info(info); + return MPI_SUCCESS; } int PMPI_Comm_delete_attr (MPI_Comm comm, int comm_keyval) @@ -275,11 +207,10 @@ int PMPI_Comm_free_keyval(int* keyval) { } int PMPI_Attr_delete(MPI_Comm comm, int keyval) { + CHECK_COMM(1) if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE) return MPI_ERR_ARG; - else if (comm==MPI_COMM_NULL) - return MPI_ERR_COMM; else return comm->attr_delete(keyval); } @@ -291,10 +222,9 @@ int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) { static int last_used_code = MPI_ERR_LASTCODE; static int universe_size; - if (comm==MPI_COMM_NULL){ - *flag = 0; - return MPI_ERR_COMM; - } + CHECK_NULL(4, MPI_ERR_ARG, flag) + *flag = 0; + CHECK_COMM(1) switch (keyval) { case MPI_HOST: @@ -326,52 +256,42 @@ int PMPI_Attr_get(MPI_Comm comm, int keyval, void* attr_value, int* flag) { } int PMPI_Attr_put(MPI_Comm comm, int keyval, void* attr_value) { + CHECK_COMM(1) if(keyval == MPI_TAG_UB||keyval == MPI_HOST||keyval == MPI_IO ||keyval == MPI_WTIME_IS_GLOBAL||keyval == MPI_APPNUM ||keyval == MPI_UNIVERSE_SIZE||keyval == MPI_LASTUSEDCODE) return MPI_ERR_ARG; - else if (comm==MPI_COMM_NULL) - return MPI_ERR_COMM; else return comm->attr_put(keyval, attr_value); } int PMPI_Errhandler_free(MPI_Errhandler* errhandler){ - if (errhandler==nullptr){ - return MPI_ERR_ARG; - } + CHECK_NULL(1, MPI_ERR_ARG, errhandler) simgrid::smpi::Errhandler::unref(*errhandler); return MPI_SUCCESS; } int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler){ + CHECK_NULL(2, MPI_ERR_ARG, errhandler) *errhandler=new simgrid::smpi::Errhandler(function); return MPI_SUCCESS; } int PMPI_Errhandler_get(MPI_Comm comm, MPI_Errhandler* errhandler){ - if (comm == nullptr) { - return MPI_ERR_COMM; - } else if (errhandler==nullptr){ - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_ARG, errhandler) *errhandler=comm->errhandler(); return MPI_SUCCESS; } int PMPI_Errhandler_set(MPI_Comm comm, MPI_Errhandler errhandler){ - if (comm == nullptr) { - return MPI_ERR_COMM; - } else if (errhandler==nullptr){ - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_ARG, errhandler) comm->set_errhandler(errhandler); return MPI_SUCCESS; } int PMPI_Comm_call_errhandler(MPI_Comm comm,int errorcode){ - if (comm == nullptr) { - return MPI_ERR_COMM; - } + CHECK_COMM(1) comm->errhandler()->call(comm, errorcode); return MPI_SUCCESS; } diff --git a/src/smpi/bindings/smpi_pmpi_file.cpp b/src/smpi/bindings/smpi_pmpi_file.cpp index 32e175092c..1f6e472f15 100644 --- a/src/smpi/bindings/smpi_pmpi_file.cpp +++ b/src/smpi/bindings/smpi_pmpi_file.cpp @@ -9,14 +9,38 @@ #include "smpi_datatype.hpp" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); +#define CHECK_FLAGS(fh) \ + if ((fh)->flags() & MPI_MODE_SEQUENTIAL) \ + return MPI_ERR_AMODE; +#define CHECK_RDONLY(fh) \ + if ((fh)->flags() & MPI_MODE_RDONLY) \ + return MPI_ERR_AMODE; +#define PASS_ZEROCOUNT(count) \ + if ((count) == 0) { \ + status->count = 0; \ + return MPI_SUCCESS; \ + } + +#define CHECK_FILE_INPUTS \ + CHECK_FILE(1, fh) \ + CHECK_BUFFER(2, buf, count) \ + CHECK_COUNT(3, count) \ + CHECK_TYPE(4, datatype) \ + CHECK_NULL(5, MPI_ERR_ARG, status) + +#define CHECK_FILE_INPUT_OFFSET \ + CHECK_FILE(1, fh) \ + CHECK_BUFFER(2, buf, count) \ + CHECK_OFFSET(3, offset) \ + CHECK_COUNT(4, count) \ + CHECK_TYPE(5, datatype) \ + CHECK_NULL(6, MPI_ERR_ARG, status) extern MPI_Errhandler SMPI_default_File_Errhandler; int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh){ - if (comm == MPI_COMM_NULL) - return MPI_ERR_COMM; - if (filename == nullptr) - return MPI_ERR_FILE; + CHECK_COMM(1) + CHECK_NULL(2, MPI_ERR_FILE, filename) if (amode < 0) return MPI_ERR_AMODE; smpi_bench_end(); @@ -32,8 +56,7 @@ int PMPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info } int PMPI_File_close(MPI_File *fh){ - if (fh==nullptr) - return MPI_ERR_ARG; + CHECK_NULL(2, MPI_ERR_ARG, fh) smpi_bench_end(); int ret = simgrid::smpi::File::close(fh); *fh = MPI_FILE_NULL; @@ -41,26 +64,6 @@ int PMPI_File_close(MPI_File *fh){ return ret; } - -#define CHECK_OFFSET(offset) \ - if ((offset) < 0) \ - return MPI_ERR_DISP; -#define CHECK_STATUS(status) \ - if ((status) == nullptr) \ - return MPI_ERR_ARG; -#define CHECK_FLAGS(fh) \ - if ((fh)->flags() & MPI_MODE_SEQUENTIAL) \ - return MPI_ERR_AMODE; -#define CHECK_RDONLY(fh) \ - if ((fh)->flags() & MPI_MODE_RDONLY) \ - return MPI_ERR_AMODE; - -#define PASS_ZEROCOUNT(count) \ - if ((count) == 0) { \ - status->count = 0; \ - return MPI_SUCCESS; \ - } - int PMPI_File_seek(MPI_File fh, MPI_Offset offset, int whence){ CHECK_FILE(1, fh) smpi_bench_end(); @@ -78,8 +81,8 @@ int PMPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence){ } int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){ - if (offset==nullptr) - return MPI_ERR_DISP; + CHECK_FILE(1, fh) + CHECK_NULL(2, MPI_ERR_DISP, offset) smpi_bench_end(); int ret = fh->get_position(offset); smpi_bench_begin(); @@ -88,8 +91,7 @@ int PMPI_File_get_position(MPI_File fh, MPI_Offset* offset){ int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){ CHECK_FILE(1, fh) - if (offset==nullptr) - return MPI_ERR_DISP; + CHECK_NULL(2, MPI_ERR_DISP, offset) smpi_bench_end(); int ret = fh->get_position_shared(offset); smpi_bench_begin(); @@ -97,11 +99,7 @@ int PMPI_File_get_position_shared(MPI_File fh, MPI_Offset* offset){ } int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FLAGS(fh) PASS_ZEROCOUNT(count) smpi_bench_end(); @@ -114,11 +112,7 @@ int PMPI_File_read(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_ } int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) PASS_ZEROCOUNT(count) smpi_bench_end(); @@ -132,11 +126,7 @@ int PMPI_File_read_shared(MPI_File fh, void *buf, int count,MPI_Datatype datatyp } int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) CHECK_RDONLY(fh) PASS_ZEROCOUNT(count) @@ -150,11 +140,7 @@ int PMPI_File_write(MPI_File fh, const void *buf, int count,MPI_Datatype datatyp } int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) CHECK_RDONLY(fh) PASS_ZEROCOUNT(count) @@ -169,11 +155,7 @@ int PMPI_File_write_shared(MPI_File fh, const void *buf, int count,MPI_Datatype } int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) smpi_bench_end(); int rank_traced = simgrid::s4u::this_actor::get_pid(); @@ -185,11 +167,7 @@ int PMPI_File_read_all(MPI_File fh, void *buf, int count,MPI_Datatype datatype, } int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) smpi_bench_end(); int rank_traced = simgrid::s4u::this_actor::get_pid(); @@ -202,11 +180,7 @@ int PMPI_File_read_ordered(MPI_File fh, void *buf, int count,MPI_Datatype dataty } int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) CHECK_RDONLY(fh) smpi_bench_end(); @@ -219,11 +193,7 @@ int PMPI_File_write_all(MPI_File fh, const void *buf, int count,MPI_Datatype dat } int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) CHECK_RDONLY(fh) smpi_bench_end(); @@ -237,12 +207,7 @@ int PMPI_File_write_ordered(MPI_File fh, const void *buf, int count,MPI_Datatype } int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_OFFSET(offset) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUTS CHECK_FLAGS(fh) PASS_ZEROCOUNT(count); smpi_bench_end(); @@ -258,12 +223,7 @@ int PMPI_File_read_at(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_D } int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_OFFSET(offset) - CHECK_COUNT(3, count) - CHECK_TYPE(4, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUT_OFFSET CHECK_FLAGS(fh) smpi_bench_end(); int rank_traced = simgrid::s4u::this_actor::get_pid(); @@ -279,12 +239,7 @@ int PMPI_File_read_at_all(MPI_File fh, MPI_Offset offset, void *buf, int count,M } int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_OFFSET(offset) - CHECK_COUNT(4, count) - CHECK_TYPE(5, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUT_OFFSET CHECK_FLAGS(fh) CHECK_RDONLY(fh) PASS_ZEROCOUNT(count); @@ -301,12 +256,7 @@ int PMPI_File_write_at(MPI_File fh, MPI_Offset offset, const void *buf, int coun } int PMPI_File_write_at_all(MPI_File fh, MPI_Offset offset, const void *buf, int count,MPI_Datatype datatype, MPI_Status *status){ - CHECK_FILE(1, fh) - CHECK_BUFFER(2, buf, count) - CHECK_OFFSET(offset) - CHECK_COUNT(4, count) - CHECK_TYPE(5, datatype) - CHECK_STATUS(status) + CHECK_FILE_INPUT_OFFSET CHECK_FLAGS(fh) CHECK_RDONLY(fh) smpi_bench_end(); diff --git a/src/smpi/bindings/smpi_pmpi_group.cpp b/src/smpi/bindings/smpi_pmpi_group.cpp index 197b283d1c..03c5f78dfc 100644 --- a/src/smpi/bindings/smpi_pmpi_group.cpp +++ b/src/smpi/bindings/smpi_pmpi_group.cpp @@ -16,166 +16,125 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); int PMPI_Group_free(MPI_Group * group) { - if (group == nullptr) { - return MPI_ERR_ARG; - } else { - if(*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_EMPTY) - simgrid::smpi::Group::unref(*group); - *group = MPI_GROUP_NULL; - return MPI_SUCCESS; - } + CHECK_NULL(1, MPI_ERR_ARG, group) + if(*group != MPI_COMM_WORLD->group() && *group != MPI_GROUP_EMPTY) + simgrid::smpi::Group::unref(*group); + *group = MPI_GROUP_NULL; + return MPI_SUCCESS; } int PMPI_Group_size(MPI_Group group, int *size) { - if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (size == nullptr) { - return MPI_ERR_ARG; - } else { - *size = group->size(); - return MPI_SUCCESS; - } + CHECK_GROUP(1, group) + CHECK_NULL(2, MPI_ERR_ARG, size) + *size = group->size(); + return MPI_SUCCESS; } int PMPI_Group_rank(MPI_Group group, int *rank) { - if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (rank == nullptr) { - return MPI_ERR_ARG; - } else { - *rank = group->rank(simgrid::s4u::this_actor::get_pid()); - return MPI_SUCCESS; - } + CHECK_GROUP(1, group) + CHECK_NULL(2, MPI_ERR_ARG, rank) + *rank = group->rank(simgrid::s4u::this_actor::get_pid()); + return MPI_SUCCESS; } int PMPI_Group_translate_ranks(MPI_Group group1, int n, const int *ranks1, MPI_Group group2, int *ranks2) { - if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else { - for (int i = 0; i < n; i++) { - if(ranks1[i]==MPI_PROC_NULL){ - ranks2[i]=MPI_PROC_NULL; - }else{ - simgrid::s4u::Actor* actor = group1->actor(ranks1[i]); - ranks2[i] = group2->rank(actor); - } + CHECK_GROUP(1, group1) + CHECK_GROUP(4, group2) + for (int i = 0; i < n; i++) { + if(ranks1[i]==MPI_PROC_NULL){ + ranks2[i]=MPI_PROC_NULL; + }else{ + simgrid::s4u::Actor* actor = group1->actor(ranks1[i]); + ranks2[i] = group2->rank(actor); } - return MPI_SUCCESS; } + return MPI_SUCCESS; } int PMPI_Group_compare(MPI_Group group1, MPI_Group group2, int *result) { - if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (result == nullptr) { - return MPI_ERR_ARG; - } else { - *result = group1->compare(group2); - return MPI_SUCCESS; - } + CHECK_GROUP(1, group1) + CHECK_GROUP(2, group2) + CHECK_NULL(3, MPI_ERR_ARG, result) + *result = group1->compare(group2); + return MPI_SUCCESS; } int PMPI_Group_union(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup) { - if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; - } else { - return group1->group_union(group2, newgroup); - } + CHECK_GROUP(1, group1) + CHECK_GROUP(2, group2) + CHECK_NULL(3, MPI_ERR_ARG, newgroup) + return group1->group_union(group2, newgroup); } int PMPI_Group_intersection(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup) { - if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; - } else { - return group1->intersection(group2,newgroup); - } + CHECK_GROUP(1, group1) + CHECK_GROUP(2, group2) + CHECK_NULL(3, MPI_ERR_ARG, newgroup) + return group1->intersection(group2,newgroup); } int PMPI_Group_difference(MPI_Group group1, MPI_Group group2, MPI_Group * newgroup) { - if (group1 == MPI_GROUP_NULL || group2 == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; - } else { - return group1->difference(group2,newgroup); - } + CHECK_GROUP(1, group1) + CHECK_GROUP(2, group2) + CHECK_NULL(3, MPI_ERR_ARG, newgroup) + return group1->difference(group2,newgroup); } int PMPI_Group_incl(MPI_Group group, int n, const int *ranks, MPI_Group * newgroup) { - if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; - } else { - return group->incl(n, ranks, newgroup); - } + CHECK_GROUP(1, group) + CHECK_NULL(4, MPI_ERR_ARG, newgroup) + return group->incl(n, ranks, newgroup); } int PMPI_Group_excl(MPI_Group group, int n, const int *ranks, MPI_Group * newgroup) { - if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; + CHECK_GROUP(1, group) + CHECK_NULL(4, MPI_ERR_ARG, newgroup) + if (n == 0) { + *newgroup = group; + if (group != MPI_COMM_WORLD->group() && group != MPI_COMM_SELF->group() && group != MPI_GROUP_EMPTY) + group->ref(); + return MPI_SUCCESS; + } else if (n == group->size()) { + *newgroup = MPI_GROUP_EMPTY; + return MPI_SUCCESS; } else { - if (n == 0) { - *newgroup = group; - if (group != MPI_COMM_WORLD->group() && group != MPI_COMM_SELF->group() && group != MPI_GROUP_EMPTY) - group->ref(); - return MPI_SUCCESS; - } else if (n == group->size()) { - *newgroup = MPI_GROUP_EMPTY; - return MPI_SUCCESS; - } else { - return group->excl(n,ranks,newgroup); - } + return group->excl(n,ranks,newgroup); } } int PMPI_Group_range_incl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup) { - if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; + CHECK_GROUP(1, group) + CHECK_NULL(4, MPI_ERR_ARG, newgroup) + if (n == 0) { + *newgroup = MPI_GROUP_EMPTY; + return MPI_SUCCESS; } else { - if (n == 0) { - *newgroup = MPI_GROUP_EMPTY; - return MPI_SUCCESS; - } else { - return group->range_incl(n,ranges,newgroup); - } + return group->range_incl(n,ranges,newgroup); } } int PMPI_Group_range_excl(MPI_Group group, int n, int ranges[][3], MPI_Group * newgroup) { - if (group == MPI_GROUP_NULL) { - return MPI_ERR_GROUP; - } else if (newgroup == nullptr) { - return MPI_ERR_ARG; + CHECK_GROUP(1, group) + CHECK_NULL(4, MPI_ERR_ARG, newgroup) + if (n == 0) { + *newgroup = group; + if (group != MPI_COMM_WORLD->group() && group != MPI_COMM_SELF->group() && + group != MPI_GROUP_EMPTY) + group->ref(); + return MPI_SUCCESS; } else { - if (n == 0) { - *newgroup = group; - if (group != MPI_COMM_WORLD->group() && group != MPI_COMM_SELF->group() && - group != MPI_GROUP_EMPTY) - group->ref(); - return MPI_SUCCESS; - } else { - return group->range_excl(n,ranges,newgroup); - } + return group->range_excl(n,ranges,newgroup); } } diff --git a/src/smpi/bindings/smpi_pmpi_info.cpp b/src/smpi/bindings/smpi_pmpi_info.cpp index 0a694f22b1..70dfc803ec 100644 --- a/src/smpi/bindings/smpi_pmpi_info.cpp +++ b/src/smpi/bindings/smpi_pmpi_info.cpp @@ -11,71 +11,70 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); /* PMPI User level calls */ int PMPI_Info_create( MPI_Info *info){ - if (info == nullptr) - return MPI_ERR_ARG; + CHECK_NULL(1, MPI_ERR_ARG, info) *info = new simgrid::smpi::Info(); return MPI_SUCCESS; } int PMPI_Info_set( MPI_Info info, const char *key, const char *value){ - if (info == nullptr || key == nullptr || value == nullptr) - return MPI_ERR_ARG; + CHECK_INFO(1, info) + CHECK_NULL(2, MPI_ERR_INFO_KEY, key) + CHECK_NULL(3, MPI_ERR_INFO_VALUE, value) info->set(key, value); return MPI_SUCCESS; } int PMPI_Info_free( MPI_Info *info){ - if (info == nullptr || *info==nullptr) - return MPI_ERR_ARG; + CHECK_NULL(1, MPI_ERR_ARG, info) + CHECK_INFO(1, *info) simgrid::smpi::Info::unref(*info); *info=MPI_INFO_NULL; return MPI_SUCCESS; } int PMPI_Info_get(MPI_Info info, const char *key,int valuelen, char *value, int *flag){ - *flag=false; - if (info == nullptr || valuelen <0) + CHECK_INFO(1, info) + if (valuelen <0) return MPI_ERR_ARG; - if (key == nullptr) - return MPI_ERR_INFO_KEY; - if (value == nullptr) - return MPI_ERR_INFO_VALUE; + CHECK_NULL(2, MPI_ERR_INFO_KEY, key) + CHECK_NULL(3, MPI_ERR_INFO_VALUE, value) + CHECK_NULL(4, MPI_ERR_ARG, flag) + *flag=false; return info->get(key, valuelen, value, flag); } int PMPI_Info_dup(MPI_Info info, MPI_Info *newinfo){ - if (info == nullptr || newinfo==nullptr) - return MPI_ERR_ARG; + CHECK_INFO(1, info) + CHECK_NULL(2, MPI_ERR_ARG, newinfo) *newinfo = new simgrid::smpi::Info(info); return MPI_SUCCESS; } int PMPI_Info_delete(MPI_Info info, const char *key){ - if (info == nullptr || key==nullptr) - return MPI_ERR_ARG; + CHECK_INFO(1, info) + CHECK_NULL(2, MPI_ERR_INFO_KEY, key) return info->remove(key); } int PMPI_Info_get_nkeys( MPI_Info info, int *nkeys){ - if (info == nullptr || nkeys==nullptr) - return MPI_ERR_ARG; + CHECK_INFO(1, info) + CHECK_NULL(2, MPI_ERR_ARG, nkeys) return info->get_nkeys(nkeys); } int PMPI_Info_get_nthkey( MPI_Info info, int n, char *key){ - if (info == nullptr || key==nullptr || n<0 || n> MPI_MAX_INFO_KEY) + CHECK_INFO(1, info) + CHECK_NULL(2, MPI_ERR_INFO_KEY, key) + if (n<0 || n> MPI_MAX_INFO_KEY) return MPI_ERR_ARG; return info->get_nthkey(n, key); } int PMPI_Info_get_valuelen( MPI_Info info, const char *key, int *valuelen, int *flag){ *flag=false; - if (info == nullptr) - return MPI_ERR_ARG; - if (key == nullptr) - return MPI_ERR_INFO_KEY; - if (valuelen == nullptr) - return MPI_ERR_INFO_VALUE; + CHECK_INFO(1, info) + CHECK_NULL(2, MPI_ERR_INFO_KEY, key) + CHECK_NULL(2, MPI_ERR_INFO_VALUE, valuelen) return info->get_valuelen(key, valuelen, flag); } diff --git a/src/smpi/bindings/smpi_pmpi_op.cpp b/src/smpi/bindings/smpi_pmpi_op.cpp index b52c51804d..414ffc955e 100644 --- a/src/smpi/bindings/smpi_pmpi_op.cpp +++ b/src/smpi/bindings/smpi_pmpi_op.cpp @@ -12,36 +12,26 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); int PMPI_Op_create(MPI_User_function * function, int commute, MPI_Op * op) { - if (function == nullptr || op == nullptr) { - return MPI_ERR_ARG; - } else { - *op = new simgrid::smpi::Op(function, (commute!=0)); - return MPI_SUCCESS; - } + CHECK_NULL(1, MPI_ERR_ARG, function) + CHECK_NULL(3, MPI_ERR_ARG, op) + *op = new simgrid::smpi::Op(function, (commute!=0)); + return MPI_SUCCESS; } int PMPI_Op_free(MPI_Op * op) { - if (op == nullptr) { - return MPI_ERR_ARG; - } else if (*op == MPI_OP_NULL) { - return MPI_ERR_OP; - } else { - simgrid::smpi::Op::unref(op); - *op = MPI_OP_NULL; - return MPI_SUCCESS; - } + CHECK_NULL(1, MPI_ERR_ARG, op) + CHECK_MPI_NULL(1, MPI_OP_NULL, MPI_ERR_OP, *op) + simgrid::smpi::Op::unref(op); + *op = MPI_OP_NULL; + return MPI_SUCCESS; } int PMPI_Op_commutative(MPI_Op op, int* commute){ - if (op == MPI_OP_NULL) { - return MPI_ERR_OP; - } else if (commute==nullptr){ - return MPI_ERR_ARG; - } else { - *commute = op->is_commutative(); - return MPI_SUCCESS; - } + CHECK_OP(1) + CHECK_NULL(1, MPI_ERR_ARG, commute) + *commute = op->is_commutative(); + return MPI_SUCCESS; } MPI_Op PMPI_Op_f2c(MPI_Fint op){ diff --git a/src/smpi/bindings/smpi_pmpi_request.cpp b/src/smpi/bindings/smpi_pmpi_request.cpp index 3caec9503d..71609468c0 100644 --- a/src/smpi/bindings/smpi_pmpi_request.cpp +++ b/src/smpi/bindings/smpi_pmpi_request.cpp @@ -23,6 +23,7 @@ static int getPid(MPI_Comm comm, int id) CHECK_COUNT(2, count)\ CHECK_TYPE(3, datatype)\ CHECK_PROC(4, dst)\ + CHECK_RANK(4, dst, comm)\ CHECK_TAG(5, tag)\ CHECK_COMM(6)\ @@ -38,6 +39,8 @@ static int getPid(MPI_Comm comm, int id) CHECK_COUNT(2, count)\ CHECK_TYPE(3, datatype)\ CHECK_PROC(4, src)\ + if(src!=MPI_ANY_SOURCE)\ + CHECK_RANK(4, src, comm)\ CHECK_TAG(5, tag)\ CHECK_COMM(6) /* PMPI User level calls */ @@ -174,25 +177,15 @@ int PMPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MP CHECK_IRECV_INPUTS smpi_bench_end(); - int retval = 0; - if (src!=MPI_ANY_SOURCE && (src >= comm->group()->size() || src <0)){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("irecv", src, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - - *request = simgrid::smpi::Request::irecv(buf, count, datatype, src, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); - } - + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("irecv", src, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + *request = simgrid::smpi::Request::irecv(buf, count, datatype, src, tag, comm); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } @@ -202,24 +195,16 @@ int PMPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dst, int t smpi_bench_end(); int retval = 0; - if (dst >= comm->group()->size() || dst <0){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - int trace_dst = getPid(comm, dst); - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("isend", dst, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - - TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size()); - - *request = simgrid::smpi::Request::isend(buf, count, datatype, dst, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); - } - + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + int trace_dst = getPid(comm, dst); + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("isend", dst, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size()); + *request = simgrid::smpi::Request::isend(buf, count, datatype, dst, tag, comm); + retval = MPI_SUCCESS; + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; @@ -236,26 +221,17 @@ int PMPI_Issend(const void* buf, int count, MPI_Datatype datatype, int dst, int CHECK_ISEND_INPUTS smpi_bench_end(); - int retval = 0; - if (dst >= comm->group()->size() || dst <0){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - int trace_dst = getPid(comm, dst); - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("ISsend", dst, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size()); - - *request = simgrid::smpi::Request::issend(buf, count, datatype, dst, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); - } - + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + int trace_dst = getPid(comm, dst); + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("ISsend", dst, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size()); + *request = simgrid::smpi::Request::issend(buf, count, datatype, dst, tag, comm); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status * status) @@ -309,28 +285,19 @@ int PMPI_Send(const void *buf, int count, MPI_Datatype datatype, int dst, int ta CHECK_SEND_INPUTS smpi_bench_end(); - int retval = 0; - if (dst >= comm->group()->size() || dst <0){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - int dst_traced = getPid(comm, dst); - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("send", dst, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - if (not TRACE_smpi_view_internals()) { - TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size()); - } - - simgrid::smpi::Request::send(buf, count, datatype, dst, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + int dst_traced = getPid(comm, dst); + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("send", dst, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + if (not TRACE_smpi_view_internals()) { + TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size()); } - + simgrid::smpi::Request::send(buf, count, datatype, dst, tag, comm); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Rsend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm) @@ -343,34 +310,25 @@ int PMPI_Bsend(const void* buf, int count, MPI_Datatype datatype, int dst, int t CHECK_SEND_INPUTS smpi_bench_end(); - int retval = 0; - if (dst >= comm->group()->size() || dst <0){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - int dst_traced = getPid(comm, dst); - int bsend_buf_size = 0; - void* bsend_buf = nullptr; - smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size); - int size = datatype->get_extent() * count; - if(bsend_buf==nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD ) - return MPI_ERR_BUFFER; - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("bsend", dst, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - if (not TRACE_smpi_view_internals()) { - TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size()); - } - - simgrid::smpi::Request::bsend(buf, count, datatype, dst, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + int dst_traced = getPid(comm, dst); + int bsend_buf_size = 0; + void* bsend_buf = nullptr; + smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size); + int size = datatype->get_extent() * count; + if(bsend_buf==nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD ) + return MPI_ERR_BUFFER; + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("bsend", dst, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + if (not TRACE_smpi_view_internals()) { + TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size()); } - + simgrid::smpi::Request::bsend(buf, count, datatype, dst, tag, comm); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Ibsend(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) @@ -378,35 +336,23 @@ int PMPI_Ibsend(const void* buf, int count, MPI_Datatype datatype, int dst, int CHECK_ISEND_INPUTS smpi_bench_end(); - int retval = 0; - if (dst >= comm->group()->size() || dst <0){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - int trace_dst = getPid(comm, dst); - int bsend_buf_size = 0; - void* bsend_buf = nullptr; - smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size); - int size = datatype->get_extent() * count; - if(bsend_buf==nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD ) - return MPI_ERR_BUFFER; - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("ibsend", dst, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - - TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size()); - - *request = simgrid::smpi::Request::ibsend(buf, count, datatype, dst, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); - } - + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + int trace_dst = getPid(comm, dst); + int bsend_buf_size = 0; + void* bsend_buf = nullptr; + smpi_process()->bsend_buffer(&bsend_buf, &bsend_buf_size); + int size = datatype->get_extent() * count; + if(bsend_buf==nullptr || bsend_buf_size < size + MPI_BSEND_OVERHEAD ) + return MPI_ERR_BUFFER; + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("ibsend", dst, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + TRACE_smpi_send(my_proc_id, my_proc_id, trace_dst, tag, count * datatype->size()); + *request = simgrid::smpi::Request::ibsend(buf, count, datatype, dst, tag, comm); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); - if (retval != MPI_SUCCESS && request!=nullptr) - *request = MPI_REQUEST_NULL; - return retval; + return MPI_SUCCESS; } int PMPI_Bsend_init(const void* buf, int count, MPI_Datatype datatype, int dst, int tag, MPI_Comm comm, MPI_Request* request) @@ -433,34 +379,23 @@ int PMPI_Ssend(const void* buf, int count, MPI_Datatype datatype, int dst, int t CHECK_SEND_INPUTS smpi_bench_end(); - int retval = 0; - if (dst >= comm->group()->size() || dst <0){ - retval = MPI_ERR_RANK; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - int dst_traced = getPid(comm, dst); - TRACE_smpi_comm_in(my_proc_id, __func__, - new simgrid::instr::Pt2PtTIData("Ssend", dst, - datatype->is_replayable() ? count : count * datatype->size(), - tag, simgrid::smpi::Datatype::encode(datatype))); - TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size()); - - simgrid::smpi::Request::ssend(buf, count, datatype, dst, tag, comm); - retval = MPI_SUCCESS; - - TRACE_smpi_comm_out(my_proc_id); - } - + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + int dst_traced = getPid(comm, dst); + TRACE_smpi_comm_in(my_proc_id, __func__, + new simgrid::instr::Pt2PtTIData("Ssend", dst, + datatype->is_replayable() ? count : count * datatype->size(), + tag, simgrid::smpi::Datatype::encode(datatype))); + TRACE_smpi_send(my_proc_id, my_proc_id, dst_traced, tag, count * datatype->size()); + simgrid::smpi::Request::ssend(buf, count, datatype, dst, tag, comm); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Sendrecv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, int dst, int sendtag, void* recvbuf, int recvcount, MPI_Datatype recvtype, int src, int recvtag, MPI_Comm comm, MPI_Status* status) { int retval = 0; - - smpi_bench_end(); CHECK_BUFFER(1, sendbuf, sendcount) CHECK_COUNT(2, sendcount) CHECK_TYPE(3, sendtype) @@ -470,6 +405,8 @@ int PMPI_Sendrecv(const void* sendbuf, int sendcount, MPI_Datatype sendtype, int CHECK_TYPE(8, recvtype) CHECK_TAG(10, recvtag) CHECK_COMM(11) + smpi_bench_end(); + if (src == MPI_PROC_NULL) { if(status!=MPI_STATUS_IGNORE){ simgrid::smpi::Status::empty(status); @@ -674,7 +611,7 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status) simgrid::smpi::Status::empty(status); - CHECK_REQUEST(1) + CHECK_NULL(1, MPI_ERR_ARG, request) if (*request == MPI_REQUEST_NULL) { retval = MPI_SUCCESS; } else { diff --git a/src/smpi/bindings/smpi_pmpi_topo.cpp b/src/smpi/bindings/smpi_pmpi_topo.cpp index 9b0779bcb5..8165328c90 100644 --- a/src/smpi/bindings/smpi_pmpi_topo.cpp +++ b/src/smpi/bindings/smpi_pmpi_topo.cpp @@ -15,32 +15,28 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); * MPIR_Topo_Type field, and replace the MPI_Topology field by an union)*/ int PMPI_Cart_create(MPI_Comm comm_old, int ndims, const int* dims, const int* periodic, int reorder, MPI_Comm* comm_cart) { - if (comm_old == MPI_COMM_NULL){ - return MPI_ERR_COMM; - } else if (ndims < 0 || (ndims > 0 && (dims == nullptr || periodic == nullptr)) || comm_cart == nullptr) { - return MPI_ERR_ARG; + CHECK_COMM2(1, comm_old) + if (ndims > 0){ + CHECK_NULL(3, MPI_ERR_ARG, dims) + CHECK_NULL(4, MPI_ERR_ARG, periodic) + CHECK_NULL(6, MPI_ERR_ARG, comm_cart) + } + CHECK_NEGATIVE(2, MPI_ERR_ARG, ndims) + for (int i = 0; i < ndims; i++) + CHECK_NEGATIVE(2, MPI_ERR_ARG, dims[i]) + simgrid::smpi::Topo_Cart* topo = new simgrid::smpi::Topo_Cart(comm_old, ndims, dims, periodic, reorder, comm_cart); + if (*comm_cart == MPI_COMM_NULL) { + delete topo; } else { - for (int i = 0; i < ndims; i++) - if (dims[i] < 0) - return MPI_ERR_ARG; - - simgrid::smpi::Topo_Cart* topo = new simgrid::smpi::Topo_Cart(comm_old, ndims, dims, periodic, reorder, comm_cart); - if (*comm_cart == MPI_COMM_NULL) { - delete topo; - } else { - xbt_assert((*comm_cart)->topo() == topo); - } - return MPI_SUCCESS; + xbt_assert((*comm_cart)->topo() == topo); } + return MPI_SUCCESS; } int PMPI_Cart_rank(MPI_Comm comm, const int* coords, int* rank) { - if(comm == MPI_COMM_NULL || comm->topo() == nullptr) { - return MPI_ERR_TOPOLOGY; - } - if (coords == nullptr) { - return MPI_SUCCESS; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_TOPOLOGY, comm->topo()) + CHECK_NULL(2, MPI_SUCCESS, coords) MPIR_Cart_Topology topo = static_cast(comm->topo()); if (topo==nullptr) { return MPI_ERR_ARG; @@ -49,12 +45,11 @@ int PMPI_Cart_rank(MPI_Comm comm, const int* coords, int* rank) { } int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* dest) { - if(comm == MPI_COMM_NULL || comm->topo() == nullptr) { - return MPI_ERR_TOPOLOGY; - } - if (source == nullptr || dest == nullptr || direction < 0 ) { - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_TOPOLOGY, comm->topo()) + CHECK_NEGATIVE(3, MPI_ERR_ARG, direction) + CHECK_NULL(4, MPI_ERR_ARG, source) + CHECK_NULL(5, MPI_ERR_ARG, dest) MPIR_Cart_Topology topo = static_cast(comm->topo()); if (topo==nullptr) { return MPI_ERR_ARG; @@ -63,15 +58,10 @@ int PMPI_Cart_shift(MPI_Comm comm, int direction, int displ, int* source, int* d } int PMPI_Cart_coords(MPI_Comm comm, int rank, int maxdims, int* coords) { - if(comm == MPI_COMM_NULL || comm->topo() == nullptr) { - return MPI_ERR_TOPOLOGY; - } - if (rank < 0 || rank >= comm->size()) { - return MPI_ERR_RANK; - } - if (maxdims < 0) { - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_TOPOLOGY, comm->topo()) + CHECK_NEGATIVE(3, MPI_ERR_ARG, maxdims) + CHECK_RANK(2, rank, comm) if(maxdims==0 || coords == nullptr) { return MPI_SUCCESS; } @@ -86,12 +76,9 @@ int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coor if(dims == nullptr || periods == nullptr || coords == nullptr){ return MPI_SUCCESS; } - if(comm == nullptr || comm->topo() == nullptr) { - return MPI_ERR_TOPOLOGY; - } - if(maxdims <= 0) { - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_TOPOLOGY, comm->topo()) + CHECK_NEGATIVE(3, MPI_ERR_ARG, maxdims) MPIR_Cart_Topology topo = static_cast(comm->topo()); if (topo==nullptr) { return MPI_ERR_ARG; @@ -100,12 +87,9 @@ int PMPI_Cart_get(MPI_Comm comm, int maxdims, int* dims, int* periods, int* coor } int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) { - if (comm == MPI_COMM_NULL || comm->topo() == nullptr) { - return MPI_ERR_TOPOLOGY; - } - if (ndims == nullptr) { - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_TOPOLOGY, comm->topo()) + CHECK_NULL(2, MPI_ERR_ARG, ndims) MPIR_Cart_Topology topo = static_cast(comm->topo()); if (topo==nullptr) { return MPI_ERR_ARG; @@ -114,9 +98,7 @@ int PMPI_Cartdim_get(MPI_Comm comm, int* ndims) { } int PMPI_Dims_create(int nnodes, int ndims, int* dims) { - if(dims == nullptr) { - return MPI_SUCCESS; - } + CHECK_NULL(3, MPI_SUCCESS, dims) if (ndims < 1 || nnodes < 1) { return MPI_ERR_DIMS; } @@ -124,12 +106,9 @@ int PMPI_Dims_create(int nnodes, int ndims, int* dims) { } int PMPI_Cart_sub(MPI_Comm comm, const int* remain_dims, MPI_Comm* comm_new) { - if(comm == MPI_COMM_NULL || comm->topo() == nullptr) { - return MPI_ERR_TOPOLOGY; - } - if (comm_new == nullptr) { - return MPI_ERR_ARG; - } + CHECK_COMM(1) + CHECK_NULL(1, MPI_ERR_TOPOLOGY, comm->topo()) + CHECK_NULL(3, MPI_ERR_ARG, comm_new) MPIR_Cart_Topology topo = static_cast(comm->topo()); if (topo==nullptr) { return MPI_ERR_ARG; diff --git a/src/smpi/bindings/smpi_pmpi_type.cpp b/src/smpi/bindings/smpi_pmpi_type.cpp index 5e35a9dcaa..473daa2044 100644 --- a/src/smpi/bindings/smpi_pmpi_type.cpp +++ b/src/smpi/bindings/smpi_pmpi_type.cpp @@ -23,37 +23,26 @@ int PMPI_Type_free(MPI_Datatype * datatype) int PMPI_Type_size(MPI_Datatype datatype, int *size) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (size == nullptr) { - return MPI_ERR_ARG; - } else { - *size = static_cast(datatype->size()); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, size) + *size = static_cast(datatype->size()); + return MPI_SUCCESS; } int PMPI_Type_size_x(MPI_Datatype datatype, MPI_Count *size) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (size == nullptr) { - return MPI_ERR_ARG; - } else { - *size = static_cast(datatype->size()); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, size) + *size = static_cast(datatype->size()); + return MPI_SUCCESS; } int PMPI_Type_get_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (lb == nullptr || extent == nullptr) { - return MPI_ERR_ARG; - } else { - return datatype->extent(lb, extent); - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, lb) + CHECK_NULL(3, MPI_ERR_ARG, extent) + return datatype->extent(lb, extent); } int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent) @@ -63,96 +52,66 @@ int PMPI_Type_get_true_extent(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * e int PMPI_Type_extent(MPI_Datatype datatype, MPI_Aint * extent) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (extent == nullptr) { - return MPI_ERR_ARG; - } else { - *extent = datatype->get_extent(); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, extent) + *extent = datatype->get_extent(); + return MPI_SUCCESS; } int PMPI_Type_lb(MPI_Datatype datatype, MPI_Aint * disp) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (disp == nullptr) { - return MPI_ERR_ARG; - } else { - *disp = datatype->lb(); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, disp) + *disp = datatype->lb(); + return MPI_SUCCESS; } int PMPI_Type_ub(MPI_Datatype datatype, MPI_Aint * disp) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (disp == nullptr) { - return MPI_ERR_ARG; - } else { - *disp = datatype->ub(); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, disp) + *disp = datatype->ub(); + return MPI_SUCCESS; } int PMPI_Type_dup(MPI_Datatype datatype, MPI_Datatype *newtype){ int retval = MPI_SUCCESS; - if (datatype == MPI_DATATYPE_NULL) { - retval=MPI_ERR_TYPE; - } else { - *newtype = new simgrid::smpi::Datatype(datatype, &retval); - //error when duplicating, free the new datatype - if(retval!=MPI_SUCCESS){ - simgrid::smpi::Datatype::unref(*newtype); - *newtype = MPI_DATATYPE_NULL; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + *newtype = new simgrid::smpi::Datatype(datatype, &retval); + //error when duplicating, free the new datatype + if(retval!=MPI_SUCCESS){ + simgrid::smpi::Datatype::unref(*newtype); + *newtype = MPI_DATATYPE_NULL; } return retval; } int PMPI_Type_contiguous(int count, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else { - return simgrid::smpi::Datatype::create_contiguous(count, old_type, 0, new_type); - } + CHECK_COUNT(1, count) + CHECK_MPI_NULL(2, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + CHECK_NULL(3, MPI_ERR_ARG, new_type) + return simgrid::smpi::Datatype::create_contiguous(count, old_type, 0, new_type); } int PMPI_Type_commit(MPI_Datatype* datatype) { - if (datatype == nullptr || *datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else { - (*datatype)->commit(); - return MPI_SUCCESS; - } + CHECK_NULL(1, MPI_ERR_ARG, datatype) + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, (*datatype)) + (*datatype)->commit(); + return MPI_SUCCESS; } int PMPI_Type_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else if(blocklen<0){ - return MPI_ERR_ARG; - } else { - return simgrid::smpi::Datatype::create_vector(count, blocklen, stride, old_type, new_type); - } + CHECK_COUNT(1, count) + CHECK_NEGATIVE(2, MPI_ERR_ARG, blocklen) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + return simgrid::smpi::Datatype::create_vector(count, blocklen, stride, old_type, new_type); } int PMPI_Type_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else if(blocklen<0){ - return MPI_ERR_ARG; - } else { - return simgrid::smpi::Datatype::create_hvector(count, blocklen, stride, old_type, new_type); - } + CHECK_COUNT(1, count) + CHECK_NEGATIVE(2, MPI_ERR_ARG, blocklen) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + return simgrid::smpi::Datatype::create_hvector(count, blocklen, stride, old_type, new_type); } int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) { @@ -160,52 +119,36 @@ int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datat } int PMPI_Type_indexed(int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else { - return simgrid::smpi::Datatype::create_indexed(count, blocklens, indices, old_type, new_type); - } + CHECK_COUNT(1, count) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + return simgrid::smpi::Datatype::create_indexed(count, blocklens, indices, old_type, new_type); } int PMPI_Type_create_indexed(int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else { - return simgrid::smpi::Datatype::create_indexed(count, blocklens, indices, old_type, new_type); - } + CHECK_COUNT(1, count) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + return simgrid::smpi::Datatype::create_indexed(count, blocklens, indices, old_type, new_type); } int PMPI_Type_create_indexed_block(int count, int blocklength, const int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else { - int* blocklens=static_cast(xbt_malloc(blocklength*count*sizeof(int))); - for (int i = 0; i < count; i++) - blocklens[i]=blocklength; - int retval = simgrid::smpi::Datatype::create_indexed(count, blocklens, indices, old_type, new_type); - xbt_free(blocklens); - return retval; - } + CHECK_COUNT(1, count) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + int* blocklens=static_cast(xbt_malloc(blocklength*count*sizeof(int))); + for (int i = 0; i < count; i++) + blocklens[i]=blocklength; + int retval = simgrid::smpi::Datatype::create_indexed(count, blocklens, indices, old_type, new_type); + xbt_free(blocklens); + return retval; } int PMPI_Type_hindexed(int count, const int* blocklens, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else { - return simgrid::smpi::Datatype::create_hindexed(count, blocklens, indices, old_type, new_type); - } + CHECK_COUNT(1, count) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + return simgrid::smpi::Datatype::create_hindexed(count, blocklens, indices, old_type, new_type); } int PMPI_Type_create_hindexed(int count, const int* blocklens, const MPI_Aint* indices, MPI_Datatype old_type, @@ -215,31 +158,23 @@ int PMPI_Type_create_hindexed(int count, const int* blocklens, const MPI_Aint* i int PMPI_Type_create_hindexed_block(int count, int blocklength, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { - if (old_type == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (count<0){ - return MPI_ERR_COUNT; - } else { - int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int)); - for (int i = 0; i < count; i++) - blocklens[i] = blocklength; - int retval = simgrid::smpi::Datatype::create_hindexed(count, blocklens, indices, old_type, new_type); - xbt_free(blocklens); - return retval; - } + CHECK_COUNT(1, count) + CHECK_MPI_NULL(4, MPI_DATATYPE_NULL, MPI_ERR_TYPE, old_type) + int* blocklens=(int*)xbt_malloc(blocklength*count*sizeof(int)); + for (int i = 0; i < count; i++) + blocklens[i] = blocklength; + int retval = simgrid::smpi::Datatype::create_hindexed(count, blocklens, indices, old_type, new_type); + xbt_free(blocklens); + return retval; } int PMPI_Type_struct(int count, const int* blocklens, const MPI_Aint* indices, const MPI_Datatype* old_types, MPI_Datatype* new_type) { - if (count<0){ - return MPI_ERR_COUNT; - } else { - for(int i=0; iset_name(name); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, name) + datatype->set_name(name); + return MPI_SUCCESS; } int PMPI_Type_get_name(MPI_Datatype datatype, char * name, int* len) { - if (datatype == MPI_DATATYPE_NULL) { - return MPI_ERR_TYPE; - } else if (name == nullptr) { - return MPI_ERR_ARG; - } else { - datatype->get_name(name, len); - return MPI_SUCCESS; - } + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, datatype) + CHECK_NULL(2, MPI_ERR_ARG, name) + datatype->get_name(name, len); + return MPI_SUCCESS; } MPI_Datatype PMPI_Type_f2c(MPI_Fint datatype){ @@ -314,26 +238,20 @@ MPI_Fint PMPI_Type_c2f(MPI_Datatype datatype){ int PMPI_Type_get_attr (MPI_Datatype type, int type_keyval, void *attribute_val, int* flag) { - if (type==MPI_DATATYPE_NULL) - return MPI_ERR_TYPE; - else - return type->attr_get(type_keyval, attribute_val, flag); + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, type) + return type->attr_get(type_keyval, attribute_val, flag); } int PMPI_Type_set_attr (MPI_Datatype type, int type_keyval, void *attribute_val) { - if (type==MPI_DATATYPE_NULL) - return MPI_ERR_TYPE; - else - return type->attr_put(type_keyval, attribute_val); + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, type) + return type->attr_put(type_keyval, attribute_val); } int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval) { - if (type==MPI_DATATYPE_NULL) - return MPI_ERR_TYPE; - else - return type->attr_delete(type_keyval); + CHECK_MPI_NULL(1, MPI_DATATYPE_NULL, MPI_ERR_TYPE, type) + return type->attr_delete(type_keyval); } int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, @@ -349,42 +267,29 @@ int PMPI_Type_free_keyval(int* keyval) { } int PMPI_Unpack(const void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) { - if(incount<0 || outcount < 0){ - return MPI_ERR_COUNT; - } else if (inbuf==nullptr || outbuf==nullptr){ - return MPI_ERR_ARG; - } else if (type == MPI_DATATYPE_NULL || not type->is_valid()){ - return MPI_ERR_TYPE; - } else if(comm==MPI_COMM_NULL){ - return MPI_ERR_COMM; - } else{ - return type->unpack(inbuf, incount, position, outbuf,outcount, comm); - } + CHECK_NEGATIVE(2, MPI_ERR_COUNT, incount) + CHECK_NEGATIVE(5, MPI_ERR_COUNT, outcount) + CHECK_BUFFER(1, inbuf, incount) + CHECK_BUFFER(4, outbuf, outcount) + CHECK_TYPE(6, type) + CHECK_COMM(7) + return type->unpack(inbuf, incount, position, outbuf,outcount, comm); } int PMPI_Pack(const void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) { - if(incount<0){ - return MPI_ERR_COUNT; - } else if(inbuf==nullptr || outbuf==nullptr || outcount < 0){ - return MPI_ERR_ARG; - } else if (type == MPI_DATATYPE_NULL || not type->is_valid()){ - return MPI_ERR_TYPE; - } else if(comm==MPI_COMM_NULL){ - return MPI_ERR_COMM; - } else { - return type->pack(inbuf == MPI_BOTTOM ? nullptr : inbuf, incount, outbuf, outcount, position, comm); - } + CHECK_NEGATIVE(2, MPI_ERR_COUNT, incount) + CHECK_NEGATIVE(5, MPI_ERR_COUNT, outcount) + CHECK_BUFFER(1, inbuf, incount) + CHECK_BUFFER(4, outbuf, outcount) + CHECK_TYPE(6, type) + CHECK_COMM(7) + return type->pack(inbuf == MPI_BOTTOM ? nullptr : inbuf, incount, outbuf, outcount, position, comm); } int PMPI_Pack_size(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) { - if(incount<0){ - return MPI_ERR_COUNT; - } else if (datatype == MPI_DATATYPE_NULL || not datatype->is_valid()){ - return MPI_ERR_TYPE; - } else if(comm==MPI_COMM_NULL){ - return MPI_ERR_COMM; - } else { - *size=incount*datatype->size(); - return MPI_SUCCESS; - } + CHECK_NEGATIVE(1, MPI_ERR_COUNT, incount) + CHECK_TYPE(2, datatype) + CHECK_COMM(3) + *size=incount*datatype->size(); + return MPI_SUCCESS; } diff --git a/src/smpi/bindings/smpi_pmpi_win.cpp b/src/smpi/bindings/smpi_pmpi_win.cpp index eda4b56d4e..aaff7ad135 100644 --- a/src/smpi/bindings/smpi_pmpi_win.cpp +++ b/src/smpi/bindings/smpi_pmpi_win.cpp @@ -13,14 +13,23 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi_pmpi); +#define CHECK_RMA\ + CHECK_BUFFER(1, origin_addr, origin_count)\ + CHECK_COUNT(2, origin_count)\ + CHECK_TYPE(3, origin_datatype)\ + CHECK_PROC(4, target_rank)\ + CHECK_NEGATIVE(4, MPI_ERR_RANK, target_rank)\ + CHECK_COUNT(6, target_count)\ + CHECK_TYPE(7, target_datatype) /* PMPI User level calls */ int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, MPI_Win *win){ int retval = 0; + CHECK_COMM(5) + CHECK_NEGATIVE(2, MPI_ERR_OTHER, size) + CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit) smpi_bench_end(); - if (comm == MPI_COMM_NULL) { - retval= MPI_ERR_COMM; - }else if ((base == nullptr && size != 0) || disp_unit <= 0 || size < 0 ){ + if (base == nullptr && size != 0){ retval= MPI_ERR_OTHER; }else{ *win = new simgrid::smpi::Win( base, size, disp_unit, info, comm); @@ -31,195 +40,136 @@ int PMPI_Win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info info, MP } int PMPI_Win_allocate( MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *base, MPI_Win *win){ - int retval = 0; + CHECK_COMM(5) + CHECK_NEGATIVE(2, MPI_ERR_OTHER, size) + CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit) + void* ptr = xbt_malloc(size); + if(ptr==nullptr) + return MPI_ERR_NO_MEM; smpi_bench_end(); - if (comm == MPI_COMM_NULL) { - retval= MPI_ERR_COMM; - }else if (disp_unit <= 0 || size < 0 ){ - retval= MPI_ERR_OTHER; - }else{ - void* ptr = xbt_malloc(size); - if(ptr==nullptr) - return MPI_ERR_NO_MEM; - *static_cast(base) = ptr; - *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,1); - retval = MPI_SUCCESS; - } + *static_cast(base) = ptr; + *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,1); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Win_allocate_shared( MPI_Aint size, int disp_unit, MPI_Info info, MPI_Comm comm, void *base, MPI_Win *win){ - int retval = 0; - smpi_bench_end(); - if (comm == MPI_COMM_NULL) { - retval= MPI_ERR_COMM; - }else if (disp_unit <= 0 || size < 0 ){ - retval= MPI_ERR_OTHER; - }else{ - void* ptr = nullptr; - int rank = comm->rank(); - if(rank==0){ - ptr = xbt_malloc(size*comm->size()); - if(ptr==nullptr) - return MPI_ERR_NO_MEM; - } - - simgrid::smpi::colls::bcast(&ptr, sizeof(void*), MPI_BYTE, 0, comm); - simgrid::smpi::colls::barrier(comm); - - *static_cast(base) = (char*)ptr+rank*size; - *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,rank==0); - retval = MPI_SUCCESS; + CHECK_COMM(5) + CHECK_NEGATIVE(2, MPI_ERR_OTHER, size) + CHECK_NEGATIVE(3, MPI_ERR_OTHER, disp_unit) + void* ptr = nullptr; + int rank = comm->rank(); + if(rank==0){ + ptr = xbt_malloc(size*comm->size()); + if(ptr==nullptr) + return MPI_ERR_NO_MEM; } + smpi_bench_end(); + simgrid::smpi::colls::bcast(&ptr, sizeof(void*), MPI_BYTE, 0, comm); + simgrid::smpi::colls::barrier(comm); + *static_cast(base) = (char*)ptr+rank*size; + *win = new simgrid::smpi::Win( ptr, size, disp_unit, info, comm,rank==0); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Win_create_dynamic( MPI_Info info, MPI_Comm comm, MPI_Win *win){ - int retval = 0; + CHECK_COMM(2) smpi_bench_end(); - if (comm == MPI_COMM_NULL) { - retval= MPI_ERR_COMM; - }else{ - *win = new simgrid::smpi::Win(info, comm); - retval = MPI_SUCCESS; - } + *win = new simgrid::smpi::Win(info, comm); smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Win_attach(MPI_Win win, void *base, MPI_Aint size){ - int retval = 0; + CHECK_WIN(1, win) + CHECK_NEGATIVE(3, MPI_ERR_OTHER, size) + if (base == nullptr && size != 0) + return MPI_ERR_OTHER; smpi_bench_end(); - if(win == MPI_WIN_NULL){ - retval = MPI_ERR_WIN; - } else if ((base == nullptr && size != 0) || size < 0 ){ - retval= MPI_ERR_OTHER; - }else{ - retval = win->attach(base, size); - } + int retval = win->attach(base, size); smpi_bench_begin(); return retval; } int PMPI_Win_detach(MPI_Win win, const void* base) { - int retval = 0; + CHECK_WIN(1, win) + CHECK_NULL(2, MPI_ERR_OTHER, base) smpi_bench_end(); - if(win == MPI_WIN_NULL){ - retval = MPI_ERR_WIN; - } else if (base == nullptr){ - retval= MPI_ERR_OTHER; - }else{ - retval = win->detach(base); - } + int retval = win->detach(base); smpi_bench_begin(); return retval; } - int PMPI_Win_free( MPI_Win* win){ - int retval = 0; + CHECK_NULL(1, MPI_ERR_WIN, win) + CHECK_WIN(1, (*win)) smpi_bench_end(); - if (win == nullptr || *win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - }else{ - delete *win; - retval=MPI_SUCCESS; - } + delete *win; smpi_bench_begin(); - return retval; + return MPI_SUCCESS; } int PMPI_Win_set_name(MPI_Win win, const char * name) { - if (win == MPI_WIN_NULL) { - return MPI_ERR_TYPE; - } else if (name == nullptr) { - return MPI_ERR_ARG; - } else { - win->set_name(name); - return MPI_SUCCESS; - } + CHECK_WIN(1, win) + CHECK_NULL(2, MPI_ERR_ARG, name) + win->set_name(name); + return MPI_SUCCESS; } int PMPI_Win_get_name(MPI_Win win, char * name, int* len) { - if (win == MPI_WIN_NULL) { - return MPI_ERR_WIN; - } else if (name == nullptr) { - return MPI_ERR_ARG; - } else { - win->get_name(name, len); - return MPI_SUCCESS; - } + CHECK_WIN(1, win) + CHECK_NULL(2, MPI_ERR_ARG, name) + win->get_name(name, len); + return MPI_SUCCESS; } int PMPI_Win_get_info(MPI_Win win, MPI_Info* info) { - if (win == MPI_WIN_NULL) { - return MPI_ERR_WIN; - } else { - *info = win->info(); - return MPI_SUCCESS; - } + CHECK_WIN(1, win) + CHECK_NULL(2, MPI_ERR_ARG, info) + *info = win->info(); + return MPI_SUCCESS; } int PMPI_Win_set_info(MPI_Win win, MPI_Info info) { - if (win == MPI_WIN_NULL) { - return MPI_ERR_TYPE; - } else { - win->set_info(info); - return MPI_SUCCESS; - } + CHECK_WIN(1, win) + win->set_info(info); + return MPI_SUCCESS; } int PMPI_Win_get_group(MPI_Win win, MPI_Group * group){ - if (win == MPI_WIN_NULL) { - return MPI_ERR_WIN; - }else { - win->get_group(group); - (*group)->ref(); - return MPI_SUCCESS; - } + CHECK_WIN(1, win) + win->get_group(group); + (*group)->ref(); + return MPI_SUCCESS; } int PMPI_Win_fence( int assert, MPI_Win win){ - int retval = 0; + CHECK_WIN(2, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_fence")); - retval = win->fence(assert); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_fence")); + int retval = win->fence(assert); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){ + CHECK_RMA + CHECK_WIN(8, win) + int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0) || - (origin_addr==nullptr && origin_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((origin_datatype == MPI_DATATYPE_NULL) || (target_datatype == MPI_DATATYPE_NULL)) || - ((not origin_datatype->is_valid()) || (not target_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -232,7 +182,6 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, retval = win->get( origin_addr, origin_count, origin_datatype, target_rank, target_disp, target_count, target_datatype); - TRACE_smpi_comm_out(my_proc_id); } smpi_bench_begin(); @@ -241,26 +190,17 @@ int PMPI_Get( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int PMPI_Rget( void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win, MPI_Request* request){ + if(target_rank==MPI_PROC_NULL) + *request = MPI_REQUEST_NULL; + CHECK_RMA + CHECK_WIN(8, win) + CHECK_NULL(9, MPI_ERR_ARG, request) + int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - *request = MPI_REQUEST_NULL; - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0) || - (origin_addr==nullptr && origin_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((origin_datatype == MPI_DATATYPE_NULL) || (target_datatype == MPI_DATATYPE_NULL)) || - ((not origin_datatype->is_valid()) || (not target_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; - } else if(request == nullptr){ - retval = MPI_ERR_REQUEST; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -282,23 +222,14 @@ int PMPI_Rget( void *origin_addr, int origin_count, MPI_Datatype origin_datatype int PMPI_Put(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win){ + CHECK_RMA + CHECK_WIN(8, win) + int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0) || - (origin_addr==nullptr && origin_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((origin_datatype == MPI_DATATYPE_NULL) || (target_datatype == MPI_DATATYPE_NULL)) || - ((not origin_datatype->is_valid()) || (not target_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -322,26 +253,16 @@ int PMPI_Put(const void *origin_addr, int origin_count, MPI_Datatype origin_data int PMPI_Rput(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Win win, MPI_Request* request){ + if(target_rank==MPI_PROC_NULL) + *request = MPI_REQUEST_NULL; + CHECK_RMA + CHECK_WIN(8, win) + CHECK_NULL(9, MPI_ERR_ARG, request) int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - *request = MPI_REQUEST_NULL; - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0) || - (origin_addr==nullptr && origin_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((origin_datatype == MPI_DATATYPE_NULL) || (target_datatype == MPI_DATATYPE_NULL)) || - ((not origin_datatype->is_valid()) || (not target_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; - } else if(request == nullptr){ - retval = MPI_ERR_REQUEST; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -365,25 +286,15 @@ int PMPI_Rput(const void *origin_addr, int origin_count, MPI_Datatype origin_dat int PMPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){ + CHECK_RMA + CHECK_OP(8) + CHECK_WIN(9, win) + int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0) || - (origin_addr==nullptr && origin_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((origin_datatype == MPI_DATATYPE_NULL) || (target_datatype == MPI_DATATYPE_NULL)) || - ((not origin_datatype->is_valid()) || (not target_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; - } else if (op == MPI_OP_NULL) { - retval = MPI_ERR_OP; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -404,28 +315,18 @@ int PMPI_Accumulate(const void *origin_addr, int origin_count, MPI_Datatype orig int PMPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){ + if(target_rank==MPI_PROC_NULL) + *request = MPI_REQUEST_NULL; + CHECK_RMA + CHECK_OP(8) + CHECK_WIN(9, win) + CHECK_NULL(10, MPI_ERR_ARG, request) + int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - *request = MPI_REQUEST_NULL; - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0) || - (origin_addr==nullptr && origin_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((origin_datatype == MPI_DATATYPE_NULL) || (target_datatype == MPI_DATATYPE_NULL)) || - ((not origin_datatype->is_valid()) || (not target_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; - } else if (op == MPI_OP_NULL) { - retval = MPI_ERR_OP; - } else if(request == nullptr){ - retval = MPI_ERR_REQUEST; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -448,26 +349,25 @@ int PMPI_Raccumulate(const void *origin_addr, int origin_count, MPI_Datatype ori int PMPI_Get_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr, int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){ + if (op != MPI_NO_OP) + CHECK_BUFFER(1, origin_addr, origin_count) + CHECK_COUNT(2, origin_count) + if(origin_count>0) + CHECK_TYPE(3, origin_datatype) + CHECK_BUFFER(4, result_addr, result_count) + CHECK_COUNT(5, result_count) + CHECK_TYPE(6, result_datatype) + CHECK_PROC(7, target_rank) + CHECK_NEGATIVE(7, MPI_ERR_RANK, target_rank) + CHECK_COUNT(9, target_count) + CHECK_TYPE(10, target_datatype) + CHECK_OP(11) + CHECK_WIN(12, win) int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0 || result_count <0) || - (origin_addr==nullptr && origin_count > 0 && op != MPI_NO_OP) || - (result_addr==nullptr && result_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((target_datatype == MPI_DATATYPE_NULL) || (result_datatype == MPI_DATATYPE_NULL)) || - (((origin_datatype != MPI_DATATYPE_NULL) && (not origin_datatype->is_valid())) || (not target_datatype->is_valid()) || (not result_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; - } else if (op == MPI_OP_NULL) { - retval = MPI_ERR_OP; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -492,29 +392,26 @@ MPI_Datatype target_datatype, MPI_Op op, MPI_Win win){ int PMPI_Rget_accumulate(const void *origin_addr, int origin_count, MPI_Datatype origin_datatype, void *result_addr, int result_count, MPI_Datatype result_datatype, int target_rank, MPI_Aint target_disp, int target_count, MPI_Datatype target_datatype, MPI_Op op, MPI_Win win, MPI_Request* request){ + if(target_rank==MPI_PROC_NULL) + *request = MPI_REQUEST_NULL; + CHECK_BUFFER(1, origin_addr, origin_count) + CHECK_COUNT(2, origin_count) + CHECK_TYPE(3, origin_datatype) + CHECK_BUFFER(4, result_addr, result_count) + CHECK_COUNT(5, result_count) + CHECK_TYPE(6, result_datatype) + CHECK_PROC(7, target_rank) + CHECK_NEGATIVE(7, MPI_ERR_RANK, target_rank) + CHECK_COUNT(9, target_count) + CHECK_TYPE(10, target_datatype) + CHECK_OP(11) + CHECK_WIN(12, win) + CHECK_NULL(10, MPI_ERR_ARG, request) int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - *request = MPI_REQUEST_NULL; - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if ((origin_count < 0 || target_count < 0 || result_count <0) || - (origin_addr==nullptr && origin_count > 0 && op != MPI_NO_OP) || - (result_addr==nullptr && result_count > 0)){ - retval = MPI_ERR_COUNT; - } else if (((target_datatype == MPI_DATATYPE_NULL) || (result_datatype == MPI_DATATYPE_NULL)) || - (((origin_datatype != MPI_DATATYPE_NULL) && (not origin_datatype->is_valid())) || (not target_datatype->is_valid()) || (not result_datatype->is_valid()))) { - retval = MPI_ERR_TYPE; - } else if (op == MPI_OP_NULL) { - retval = MPI_ERR_OP; - } else if(request == nullptr){ - retval = MPI_ERR_REQUEST; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -542,21 +439,18 @@ int PMPI_Fetch_and_op(const void *origin_addr, void *result_addr, MPI_Datatype d int PMPI_Compare_and_swap(const void* origin_addr, void* compare_addr, void* result_addr, MPI_Datatype datatype, int target_rank, MPI_Aint target_disp, MPI_Win win) { + CHECK_NULL(1, MPI_ERR_BUFFER, origin_addr) + CHECK_NULL(2, MPI_ERR_BUFFER, compare_addr) + CHECK_NULL(3, MPI_ERR_BUFFER, result_addr) + CHECK_TYPE(4, datatype) + CHECK_PROC(5, target_rank) + CHECK_NEGATIVE(5, MPI_ERR_RANK, target_rank) + CHECK_WIN(6, win) int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (target_rank == MPI_PROC_NULL) { - retval = MPI_SUCCESS; - } else if (target_rank <0){ - retval = MPI_ERR_RANK; - } else if (win->dynamic()==0 && target_disp <0){ + if (win->dynamic()==0 && target_disp <0){ //in case of dynamic window, target_disp can be mistakenly seen as negative, as it is an address retval = MPI_ERR_ARG; - } else if (origin_addr==nullptr || result_addr==nullptr || compare_addr==nullptr){ - retval = MPI_ERR_COUNT; - } else if ((datatype == MPI_DATATYPE_NULL) || (not datatype->is_valid())) { - retval = MPI_ERR_TYPE; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); MPI_Group group; @@ -575,83 +469,59 @@ int PMPI_Compare_and_swap(const void* origin_addr, void* compare_addr, void* res } int PMPI_Win_post(MPI_Group group, int assert, MPI_Win win){ - int retval = 0; + CHECK_GROUP(1, group) + CHECK_WIN(2, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (group==MPI_GROUP_NULL){ - retval = MPI_ERR_GROUP; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_post")); - retval = win->post(group,assert); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_post")); + int retval = win->post(group,assert); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_start(MPI_Group group, int assert, MPI_Win win){ - int retval = 0; + CHECK_GROUP(1, group) + CHECK_WIN(2, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (group==MPI_GROUP_NULL){ - retval = MPI_ERR_GROUP; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_start")); - retval = win->start(group,assert); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_start")); + int retval = win->start(group,assert); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_complete(MPI_Win win){ - int retval = 0; + CHECK_WIN(1, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_complete")); - - retval = win->complete(); - - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_complete")); + int retval = win->complete(); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_wait(MPI_Win win){ - int retval = 0; + CHECK_WIN(1, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_wait")); - - retval = win->wait(); - - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_wait")); + int retval = win->wait(); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win){ + CHECK_PROC(2, rank) + CHECK_WIN(4, win) int retval = 0; smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (lock_type != MPI_LOCK_EXCLUSIVE && - lock_type != MPI_LOCK_SHARED) { + if (lock_type != MPI_LOCK_EXCLUSIVE && + lock_type != MPI_LOCK_SHARED) { retval = MPI_ERR_LOCKTYPE; - } else if (rank == MPI_PROC_NULL){ - retval = MPI_SUCCESS; } else { int my_proc_id = simgrid::s4u::this_actor::get_pid(); TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_lock")); @@ -663,166 +533,125 @@ int PMPI_Win_lock(int lock_type, int rank, int assert, MPI_Win win){ } int PMPI_Win_unlock(int rank, MPI_Win win){ - int retval = 0; + CHECK_PROC(1, rank) + CHECK_WIN(2, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (rank == MPI_PROC_NULL){ - retval = MPI_SUCCESS; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_unlock")); - retval = win->unlock(rank); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_unlock")); + int retval = win->unlock(rank); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_lock_all(int assert, MPI_Win win){ - int retval = 0; + CHECK_WIN(2, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_lock_all")); - retval = win->lock_all(assert); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_lock_all")); + int retval = win->lock_all(assert); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_unlock_all(MPI_Win win){ - int retval = 0; + CHECK_WIN(1, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_unlock_all")); - retval = win->unlock_all(); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_unlock_all")); + int retval = win->unlock_all(); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_flush(int rank, MPI_Win win){ - int retval = 0; + CHECK_PROC(1, rank) + CHECK_WIN(2, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (rank == MPI_PROC_NULL){ - retval = MPI_SUCCESS; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush")); - retval = win->flush(rank); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush")); + int retval = win->flush(rank); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_flush_local(int rank, MPI_Win win){ - int retval = 0; - smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else if (rank == MPI_PROC_NULL){ - retval = MPI_SUCCESS; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_local")); - retval = win->flush_local(rank); - TRACE_smpi_comm_out(my_proc_id); - } + CHECK_PROC(1, rank) + CHECK_WIN(2, win) smpi_bench_end(); + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_local")); + int retval = win->flush_local(rank); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_flush_all(MPI_Win win){ - int retval = 0; + CHECK_WIN(1, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_all")); - retval = win->flush_all(); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_all")); + int retval = win->flush_all(); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_flush_local_all(MPI_Win win){ - int retval = 0; + CHECK_WIN(1, win) smpi_bench_end(); - if (win == MPI_WIN_NULL) { - retval = MPI_ERR_WIN; - } else { - int my_proc_id = simgrid::s4u::this_actor::get_pid(); - TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_local_all")); - retval = win->flush_local_all(); - TRACE_smpi_comm_out(my_proc_id); - } + int my_proc_id = simgrid::s4u::this_actor::get_pid(); + TRACE_smpi_comm_in(my_proc_id, __func__, new simgrid::instr::NoOpTIData("Win_flush_local_all")); + int retval = win->flush_local_all(); + TRACE_smpi_comm_out(my_proc_id); smpi_bench_begin(); return retval; } int PMPI_Win_shared_query (MPI_Win win, int rank, MPI_Aint* size, int* disp_unit, void* baseptr) { - if (win == MPI_WIN_NULL) - return MPI_ERR_TYPE; - else - return win->shared_query(rank, size, disp_unit, baseptr); + CHECK_WIN(1, win) + return win->shared_query(rank, size, disp_unit, baseptr); } int PMPI_Win_get_attr (MPI_Win win, int keyval, void *attribute_val, int* flag) { static MPI_Aint size; static MPI_Aint disp_unit; - if (win == MPI_WIN_NULL) - return MPI_ERR_TYPE; - else{ - switch (keyval) { - case MPI_WIN_BASE: - *static_cast(attribute_val) = win->base(); - *flag = 1; - return MPI_SUCCESS; - case MPI_WIN_SIZE: - size = win->size(); - *static_cast(attribute_val) = &size; - *flag = 1; - return MPI_SUCCESS; - case MPI_WIN_DISP_UNIT: - disp_unit = win->disp_unit(); - *static_cast(attribute_val) = &disp_unit; - *flag = 1; - return MPI_SUCCESS; - default: - return win->attr_get(keyval, attribute_val, flag); - } + CHECK_WIN(1, win) + switch (keyval) { + case MPI_WIN_BASE: + *static_cast(attribute_val) = win->base(); + *flag = 1; + return MPI_SUCCESS; + case MPI_WIN_SIZE: + size = win->size(); + *static_cast(attribute_val) = &size; + *flag = 1; + return MPI_SUCCESS; + case MPI_WIN_DISP_UNIT: + disp_unit = win->disp_unit(); + *static_cast(attribute_val) = &disp_unit; + *flag = 1; + return MPI_SUCCESS; + default: + return win->attr_get(keyval, attribute_val, flag); } } int PMPI_Win_set_attr (MPI_Win win, int type_keyval, void *attribute_val) { - if (win==MPI_WIN_NULL) - return MPI_ERR_TYPE; - else - return win->attr_put(type_keyval, attribute_val); + CHECK_WIN(1, win) + return win->attr_put(type_keyval, attribute_val); } int PMPI_Win_delete_attr (MPI_Win win, int type_keyval) { - if (win==MPI_WIN_NULL) - return MPI_ERR_TYPE; - else - return win->attr_delete(type_keyval); + CHECK_WIN(1, win) + return win->attr_delete(type_keyval); } int PMPI_Win_create_keyval(MPI_Win_copy_attr_function* copy_fn, MPI_Win_delete_attr_function* delete_fn, int* keyval, @@ -855,9 +684,8 @@ int PMPI_Win_create_errhandler(MPI_Win_errhandler_function* function, MPI_Errhan } int PMPI_Win_get_errhandler(MPI_Win win, MPI_Errhandler* errhandler){ - if (win == nullptr) { - return MPI_ERR_WIN; - } else if (errhandler==nullptr){ + CHECK_WIN(1, win) + if (errhandler==nullptr){ return MPI_ERR_ARG; } *errhandler=win->errhandler(); @@ -865,9 +693,8 @@ int PMPI_Win_get_errhandler(MPI_Win win, MPI_Errhandler* errhandler){ } int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler){ - if (win == nullptr) { - return MPI_ERR_WIN; - } else if (errhandler==nullptr){ + CHECK_WIN(1, win) + if (errhandler==nullptr){ return MPI_ERR_ARG; } win->set_errhandler(errhandler); @@ -875,9 +702,7 @@ int PMPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler){ } int PMPI_Win_call_errhandler(MPI_Win win,int errorcode){ - if (win == nullptr) { - return MPI_ERR_WIN; - } + CHECK_WIN(1, win) win->errhandler()->call(win, errorcode); return MPI_SUCCESS; } diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index f8cb15f449..0ccdc7f35e 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -501,42 +501,57 @@ XBT_PRIVATE void private_execute_flops(double flops); #define CHECK_ARGS(test, errcode, ...) \ if (test) { \ - XBT_WARN(__VA_ARGS__); \ + if(errcode != MPI_SUCCESS) \ + XBT_WARN(__VA_ARGS__); \ return (errcode); \ } +#define CHECK_MPI_NULL(num, val, err, ptr) \ + CHECK_ARGS(ptr == val, err, \ + "%s: param %d %s cannot be %s", __func__, num, #ptr, #val); +#define CHECK_NULL(num,err,buf) \ + CHECK_ARGS(buf == nullptr, err, \ + "%s: param %d %s cannot be NULL", __func__, num, #buf); +#define CHECK_NEGATIVE(num, err, val) \ + CHECK_ARGS(val < 0, err, \ + "%s: param %d %s cannot be negative", __func__, num, #val); +#define CHECK_COMM2(num, comm) \ + CHECK_MPI_NULL(num, MPI_COMM_NULL, MPI_ERR_COMM, comm) #define CHECK_COMM(num) \ - CHECK_ARGS(comm == MPI_COMM_NULL, MPI_ERR_COMM, \ - "%s: param %d communicator cannot be MPI_COMM_NULL", __func__, num); + CHECK_COMM2(num, comm) #define CHECK_REQUEST(num) \ CHECK_ARGS(request == nullptr, MPI_ERR_REQUEST, \ "%s: param %d request cannot be NULL",__func__, num); #define CHECK_BUFFER(num,buf,count) \ CHECK_ARGS(buf == nullptr && count > 0, MPI_ERR_BUFFER, \ "%s: param %d %s cannot be NULL if %s > 0",__func__, num, #buf, #count); -#define CHECK_COUNT(num,count) \ - CHECK_ARGS(count < 0, MPI_ERR_COUNT, \ - "%s: param %d %s cannot be negative", __func__, num, #count); +#define CHECK_COUNT(num, count) \ + CHECK_NEGATIVE(num, MPI_ERR_COUNT, count) #define CHECK_TYPE(num, datatype) \ CHECK_ARGS((datatype == MPI_DATATYPE_NULL|| not datatype->is_valid()), MPI_ERR_TYPE, \ "%s: param %d %s cannot be MPI_DATATYPE_NULL or invalid", __func__, num, #datatype); #define CHECK_OP(num) \ - CHECK_ARGS(op == MPI_OP_NULL, MPI_ERR_OP, \ - "%s: param %d op cannot be MPI_OP_NULL or invalid", __func__, num); + CHECK_MPI_NULL(num, MPI_OP_NULL, MPI_ERR_OP, op) #define CHECK_ROOT(num)\ CHECK_ARGS((root < 0 || root >= comm->size()), MPI_ERR_ROOT, \ "%s: param %d root (=%d) cannot be negative or larger than communicator size (=%d)", __func__, num, root, \ comm->size()); -#define CHECK_NULL(num,err,buf) \ - CHECK_ARGS(buf == nullptr, err, \ - "%s: param %d %s cannot be NULL", __func__, num, #buf); #define CHECK_PROC(num,proc) \ - CHECK_ARGS(proc == MPI_PROC_NULL, MPI_SUCCESS, \ - "%s: param %d %s cannot be MPI_PROC_NULL", __func__, num, #proc); + CHECK_MPI_NULL(num, MPI_PROC_NULL, MPI_SUCCESS, proc) +#define CHECK_INFO(num,info) \ + CHECK_MPI_NULL(num, MPI_INFO_NULL, MPI_ERR_INFO, info) #define CHECK_TAG(num,tag) \ - CHECK_ARGS((tag<0 && tag != MPI_ANY_TAG), MPI_ERR_TAG, \ - "%s: param %d %s cannot be negative", __func__, num, #tag); -#define CHECK_FILE(num, fh) \ - CHECK_ARGS(fh == MPI_FILE_NULL, MPI_ERR_FILE, \ - "%s: param %d %s cannot be MPI_PROC_NULL", __func__, num, #fh); + CHECK_ARGS((tag < 0 && tag != MPI_ANY_TAG), MPI_ERR_TAG, \ + "%s: param %d %s (=%d) cannot be negative", __func__, num, #tag, tag); +#define CHECK_FILE(num, fh) \ + CHECK_MPI_NULL(num, MPI_FILE_NULL, MPI_ERR_FILE, fh) +#define CHECK_OFFSET(num, offset) \ + CHECK_NEGATIVE(num, MPI_ERR_DISP, offset) +#define CHECK_GROUP(num, group) \ + CHECK_MPI_NULL(num, MPI_GROUP_NULL, MPI_ERR_GROUP, group) +#define CHECK_WIN(num, group) \ + CHECK_MPI_NULL(num, MPI_WIN_NULL, MPI_ERR_WIN, group) +#define CHECK_RANK(num, rank, comm) \ + CHECK_ARGS((rank >= comm->group()->size() || rank <0), MPI_ERR_RANK, \ + "%s: param %d %s (=%d) cannot be < 0 or > %d", __func__, num, #rank, rank, comm->group()->size() ); #endif diff --git a/teshsuite/smpi/coll-reduce/coll-reduce.c b/teshsuite/smpi/coll-reduce/coll-reduce.c index bd6ff17866..0ac4c664a0 100644 --- a/teshsuite/smpi/coll-reduce/coll-reduce.c +++ b/teshsuite/smpi/coll-reduce/coll-reduce.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) printf("MPI_Reduce did not return MPI_ERR_TYPE for MPI_DATATYPE_NULL type\n"); status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_OP_NULL, root, MPI_COMM_WORLD); if(status!=MPI_ERR_OP) - printf("MPI_Reduce did not return MPI_ERR_COMM for MPI_OP_NULL op\n"); + printf("MPI_Reduce did not return MPI_ERR_OP for MPI_OP_NULL op\n"); status = MPI_Reduce(sb, rb, size, MPI_UNSIGNED_LONG_LONG, MPI_SUM, -1, MPI_COMM_WORLD); if(status!=MPI_ERR_ROOT) printf("MPI_Reduce did not return MPI_ERR_ROOT for root -1\n");