From 34d4ea3aa3fbfab92b7fde639f236f03c9d3fb20 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Fri, 26 Apr 2019 13:46:14 +0200 Subject: [PATCH] constify MPI_Datatype* --- include/smpi/smpi.h | 18 +++---- src/smpi/bindings/smpi_mpi.cpp | 18 +++---- src/smpi/bindings/smpi_pmpi_type.cpp | 24 +++++----- src/smpi/include/smpi_datatype.hpp | 20 ++++---- src/smpi/include/smpi_datatype_derived.hpp | 28 +++++------ src/smpi/include/smpi_op.hpp | 2 +- src/smpi/mpi/smpi_datatype.cpp | 26 +++++----- src/smpi/mpi/smpi_datatype_derived.cpp | 56 +++++++++++----------- src/smpi/mpi/smpi_op.cpp | 6 +-- 9 files changed, 100 insertions(+), 98 deletions(-) diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index 546be44caa..ab27979e21 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -440,23 +440,23 @@ MPI_CALL(XBT_PUBLIC int, MPI_Type_commit, (MPI_Datatype * datatype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_hindexed, (int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_hindexed, - (int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); + (int count, const int* blocklens, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_hindexed_block, - (int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); + (int count, int blocklength, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_hvector, (int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_hvector, (int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_indexed, - (int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); + (int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_indexed, - (int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); + (int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_indexed_block, - (int count, int blocklength, int* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); + (int count, int blocklength, const int* indices, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_struct, (int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_struct, - (int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* newtype)); + (int count, const int* blocklens, const MPI_Aint* indices, const MPI_Datatype* old_types, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_vector, (int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_contiguous, (int count, MPI_Datatype old_type, MPI_Datatype* newtype)); @@ -477,10 +477,10 @@ MPI_CALL(XBT_PUBLIC int, MPI_Type_set_name, (MPI_Datatype datatype, char* name)) MPI_CALL(XBT_PUBLIC int, MPI_Type_get_name, (MPI_Datatype datatype, char* name, int* len)); MPI_CALL(XBT_PUBLIC int, MPI_Pack, - (void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm)); + (const void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm)); MPI_CALL(XBT_PUBLIC int, MPI_Pack_size, (int incount, MPI_Datatype datatype, MPI_Comm comm, int* size)); MPI_CALL(XBT_PUBLIC int, MPI_Unpack, - (void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm)); + (const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm)); MPI_CALL(XBT_PUBLIC int, MPI_Op_create, (MPI_User_function * function, int commute, MPI_Op* op)); MPI_CALL(XBT_PUBLIC int, MPI_Op_free, (MPI_Op * op)); @@ -841,7 +841,7 @@ MPI_CALL(XBT_PUBLIC int, MPI_Pack_external, (char* datarep, void* inbuf, int inc MPI_CALL(XBT_PUBLIC int, MPI_Unpack_external, (char* datarep, void* inbuf, MPI_Aint insize, MPI_Aint* position, void* outbuf, int outcount, MPI_Datatype datatype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_create_subarray, - (int ndims, int* array_of_sizes, int* array_of_subsizes, int* array_of_starts, int order, MPI_Datatype oldtype, + (int ndims, const int* array_of_sizes, const int* array_of_subsizes, const int* array_of_starts, int order, MPI_Datatype oldtype, MPI_Datatype* newtype)); MPI_CALL(XBT_PUBLIC int, MPI_Type_match_size, (int typeclass, int size, MPI_Datatype* datatype)); MPI_CALL(XBT_PUBLIC int, MPI_Comm_set_info, (MPI_Comm comm, MPI_Info info)); diff --git a/src/smpi/bindings/smpi_mpi.cpp b/src/smpi/bindings/smpi_mpi.cpp index cd04fa2458..d9d7b5dc30 100644 --- a/src/smpi/bindings/smpi_mpi.cpp +++ b/src/smpi/bindings/smpi_mpi.cpp @@ -186,7 +186,7 @@ WRAPPED_PMPI_CALL(int,MPI_Op_create,(MPI_User_function * function, int commute, WRAPPED_PMPI_CALL(int,MPI_Op_free,(MPI_Op * op),(op)) WRAPPED_PMPI_CALL(int,MPI_Op_commutative,(MPI_Op op, int *commute), (op, commute)) WRAPPED_PMPI_CALL(int,MPI_Pack_size,(int incount, MPI_Datatype datatype, MPI_Comm comm, int* size) ,(incount, datatype, comm, size)) -WRAPPED_PMPI_CALL(int,MPI_Pack,(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) ,(inbuf, incount, type, outbuf, outcount, position, comm)) +WRAPPED_PMPI_CALL(int,MPI_Pack,(const void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm comm) ,(inbuf, incount, type, outbuf, outcount, position, comm)) WRAPPED_PMPI_CALL(int,MPI_Probe,(int source, int tag, MPI_Comm comm, MPI_Status* status) ,(source, tag, comm, status)) WRAPPED_PMPI_CALL(int,MPI_Put,( 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),(origin_addr,origin_count, origin_datatype,target_rank,target_disp, target_count,target_datatype, win)) WRAPPED_PMPI_CALL(int,MPI_Query_thread,(int *provided),(provided)) @@ -221,15 +221,15 @@ WRAPPED_PMPI_CALL(int,MPI_Grequest_complete,( MPI_Request request),( request)) WRAPPED_PMPI_CALL(int,MPI_Grequest_start,(MPI_Grequest_query_function *query_fn, MPI_Grequest_free_function *free_fn,MPI_Grequest_cancel_function *cancel_fn, void *extra_state, MPI_Request *request),( query_fn, free_fn, cancel_fn, extra_state, request)) WRAPPED_PMPI_CALL(int,MPI_Type_commit,(MPI_Datatype* datatype) ,(datatype)) WRAPPED_PMPI_CALL(int,MPI_Type_contiguous,(int count, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, old_type, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Type_create_hindexed_block,(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklength, indices, old_type, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Type_create_hindexed,(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type,MPI_Datatype* new_type) ,(count, blocklens,indices,old_type,new_type)) +WRAPPED_PMPI_CALL(int,MPI_Type_create_hindexed_block,(int count, int blocklength, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklength, indices, old_type, newtype)) +WRAPPED_PMPI_CALL(int,MPI_Type_create_hindexed,(int count, const int* blocklens, const MPI_Aint* indices, MPI_Datatype old_type,MPI_Datatype* new_type) ,(count, blocklens,indices,old_type,new_type)) WRAPPED_PMPI_CALL(int,MPI_Type_create_hvector,(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type) ,(count, blocklen, stride, old_type, new_type)) -WRAPPED_PMPI_CALL(int,MPI_Type_create_indexed_block,(int count, int blocklength, int* indices,MPI_Datatype old_type,MPI_Datatype *newtype),(count, blocklength, indices, old_type, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Type_create_indexed,(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklens, indices, old_type, newtype)) +WRAPPED_PMPI_CALL(int,MPI_Type_create_indexed_block,(int count, int blocklength, const int* indices,MPI_Datatype old_type,MPI_Datatype *newtype),(count, blocklength, indices, old_type, newtype)) +WRAPPED_PMPI_CALL(int,MPI_Type_create_indexed,(int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklens, indices, old_type, newtype)) WRAPPED_PMPI_CALL(int,MPI_Type_create_keyval,(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,void* extra_state),(copy_fn,delete_fn,keyval,extra_state)) WRAPPED_PMPI_CALL(int,MPI_Type_create_resized,(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype),(oldtype,lb, extent, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Type_create_struct,(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types,MPI_Datatype* newtype) ,(count, blocklens, indices, old_types, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Type_create_subarray,(int ndims,int *array_of_sizes, int *array_of_subsizes, int *array_of_starts, int order,MPI_Datatype oldtype, MPI_Datatype *newtype),(ndims,array_of_sizes, array_of_subsizes, array_of_starts, order, oldtype, newtype)) +WRAPPED_PMPI_CALL(int,MPI_Type_create_struct,(int count, const int* blocklens, const MPI_Aint* indices, const MPI_Datatype* old_types,MPI_Datatype* newtype) ,(count, blocklens, indices, old_types, newtype)) +WRAPPED_PMPI_CALL(int,MPI_Type_create_subarray,(int ndims,const int *array_of_sizes, const int *array_of_subsizes, const int *array_of_starts, int order,MPI_Datatype oldtype, MPI_Datatype *newtype),(ndims,array_of_sizes, array_of_subsizes, array_of_starts, order, oldtype, newtype)) WRAPPED_PMPI_CALL(int,MPI_Type_delete_attr ,(MPI_Datatype type, int type_keyval),(type,type_keyval)) WRAPPED_PMPI_CALL(int,MPI_Type_dup,(MPI_Datatype datatype, MPI_Datatype * newdatatype),(datatype, newdatatype)) WRAPPED_PMPI_CALL(int,MPI_Type_extent,(MPI_Datatype datatype, MPI_Aint * extent),(datatype, extent)) @@ -241,7 +241,7 @@ WRAPPED_PMPI_CALL(int,MPI_Type_get_name,(MPI_Datatype datatype, char * name, int WRAPPED_PMPI_CALL(int,MPI_Type_get_true_extent,(MPI_Datatype datatype, MPI_Aint * lb, MPI_Aint * extent),(datatype, lb, extent)) WRAPPED_PMPI_CALL(int,MPI_Type_hindexed,(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklens, indices, old_type, newtype)) WRAPPED_PMPI_CALL(int,MPI_Type_hvector,(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklen, stride, old_type, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Type_indexed,(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklens, indices, old_type, newtype)) +WRAPPED_PMPI_CALL(int,MPI_Type_indexed,(int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklens, indices, old_type, newtype)) WRAPPED_PMPI_CALL(int,MPI_Type_lb,(MPI_Datatype datatype, MPI_Aint * disp),(datatype, disp)) WRAPPED_PMPI_CALL(int,MPI_Type_set_attr ,(MPI_Datatype type, int type_keyval, void *attribute_val),( type, type_keyval, attribute_val)) WRAPPED_PMPI_CALL(int,MPI_Type_set_name,(MPI_Datatype datatype, char * name),(datatype, name)) @@ -250,7 +250,7 @@ WRAPPED_PMPI_CALL(int,MPI_Type_size_x,(MPI_Datatype datatype, MPI_Count *size),( WRAPPED_PMPI_CALL(int,MPI_Type_struct,(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* newtype) ,(count, blocklens, indices, old_types, newtype)) WRAPPED_PMPI_CALL(int,MPI_Type_ub,(MPI_Datatype datatype, MPI_Aint * disp),(datatype, disp)) WRAPPED_PMPI_CALL(int,MPI_Type_vector,(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* newtype) ,(count, blocklen, stride, old_type, newtype)) -WRAPPED_PMPI_CALL(int,MPI_Unpack,(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) ,(inbuf, insize, position, outbuf, outcount, type, comm)) +WRAPPED_PMPI_CALL(int,MPI_Unpack,(const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) ,(inbuf, insize, position, outbuf, outcount, type, comm)) WRAPPED_PMPI_CALL(int,MPI_Waitall,(int count, MPI_Request requests[], MPI_Status status[]),(count, requests, status)) WRAPPED_PMPI_CALL(int,MPI_Waitany,(int count, MPI_Request requests[], int *index, MPI_Status * status),(count, requests, index, status)) WRAPPED_PMPI_CALL(int,MPI_Wait,(MPI_Request * request, MPI_Status * status),(request, status)) diff --git a/src/smpi/bindings/smpi_pmpi_type.cpp b/src/smpi/bindings/smpi_pmpi_type.cpp index 20a79ae9c5..108050c578 100644 --- a/src/smpi/bindings/smpi_pmpi_type.cpp +++ b/src/smpi/bindings/smpi_pmpi_type.cpp @@ -159,7 +159,7 @@ int PMPI_Type_create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datat return MPI_Type_hvector(count, blocklen, stride, old_type, new_type); } -int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { +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){ @@ -169,7 +169,7 @@ int PMPI_Type_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_ } } -int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* 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){ @@ -179,7 +179,7 @@ int PMPI_Type_create_indexed(int count, int* blocklens, int* indices, MPI_Dataty } } -int PMPI_Type_create_indexed_block(int count, int blocklength, int* indices, MPI_Datatype old_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) { @@ -207,12 +207,12 @@ int PMPI_Type_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatyp } } -int PMPI_Type_create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, +int PMPI_Type_create_hindexed(int count, const int* blocklens, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type) { - return PMPI_Type_hindexed(count, blocklens,indices,old_type,new_type); + return PMPI_Type_hindexed(count, const_cast(blocklens),const_cast(indices),old_type,new_type); } -int PMPI_Type_create_hindexed_block(int count, int blocklength, MPI_Aint* indices, MPI_Datatype old_type, +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; @@ -239,14 +239,14 @@ int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* } } -int PMPI_Type_create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, +int PMPI_Type_create_struct(int count, const int* blocklens, const MPI_Aint* indices, const MPI_Datatype* old_types, MPI_Datatype* new_type) { - return PMPI_Type_struct(count, blocklens, indices, old_types, new_type); + return PMPI_Type_struct(count, const_cast(blocklens), const_cast(indices), const_cast(old_types), new_type); } -int PMPI_Type_create_subarray(int ndims, int* array_of_sizes, - int* array_of_subsizes, int* array_of_starts, +int PMPI_Type_create_subarray(int ndims, const int* array_of_sizes, + const int* array_of_subsizes, const int* array_of_starts, int order, MPI_Datatype oldtype, MPI_Datatype *newtype) { if (ndims<0){ return MPI_ERR_COUNT; @@ -341,7 +341,7 @@ int PMPI_Type_free_keyval(int* keyval) { return simgrid::smpi::Keyval::keyval_free(keyval); } -int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outcount, MPI_Datatype type, MPI_Comm comm) { +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){ @@ -355,7 +355,7 @@ int PMPI_Unpack(void* inbuf, int incount, int* position, void* outbuf, int outco } } -int PMPI_Pack(void* inbuf, int incount, MPI_Datatype type, void* outbuf, int outcount, int* position, MPI_Comm 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){ diff --git a/src/smpi/include/smpi_datatype.hpp b/src/smpi/include/smpi_datatype.hpp index 3b00c7e02b..202956111b 100644 --- a/src/smpi/include/smpi_datatype.hpp +++ b/src/smpi/include/smpi_datatype.hpp @@ -122,26 +122,26 @@ public: MPI_Aint get_extent() { return ub_ - lb_; }; void get_name(char* name, int* length); void set_name(char* name); - static int copy(void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, + static int copy(const void* sendbuf, int sendcount, MPI_Datatype sendtype, void* recvbuf, int recvcount, MPI_Datatype recvtype); - virtual void serialize(void* noncontiguous, void* contiguous, int count); - virtual void unserialize(void* contiguous, void* noncontiguous, int count, MPI_Op op); + virtual void serialize(const void* noncontiguous, void* contiguous, int count); + virtual void unserialize(const void* contiguous, void* noncontiguous, int count, MPI_Op op); static int keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval, void* extra_state); static int keyval_free(int* keyval); - int pack(void* inbuf, int incount, void* outbuf, int outcount, int* position, MPI_Comm comm); - int unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Comm comm); + int pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, MPI_Comm comm); + int unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Comm comm); static int create_contiguous(int count, MPI_Datatype old_type, MPI_Aint lb, MPI_Datatype* new_type); static int create_vector(int count, int blocklen, int stride, MPI_Datatype old_type, MPI_Datatype* new_type); static int create_hvector(int count, int blocklen, MPI_Aint stride, MPI_Datatype old_type, MPI_Datatype* new_type); - static int create_indexed(int count, int* blocklens, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type); - static int create_hindexed(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype old_type, + static int create_indexed(int count, const int* blocklens, const int* indices, MPI_Datatype old_type, MPI_Datatype* new_type); + static int create_hindexed(int count, const int* blocklens, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type); - static int create_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype* old_types, + static int create_struct(int count, const int* blocklens, const MPI_Aint* indices, const MPI_Datatype* old_types, MPI_Datatype* new_type); - static int create_subarray(int ndims, int* array_of_sizes, - int* array_of_subsizes, int* array_of_starts, + static int create_subarray(int ndims, const int* array_of_sizes, + const int* array_of_subsizes, const int* array_of_starts, int order, MPI_Datatype oldtype, MPI_Datatype *newtype); static int create_resized(MPI_Datatype oldtype,MPI_Aint lb, MPI_Aint extent, MPI_Datatype *newtype); diff --git a/src/smpi/include/smpi_datatype_derived.hpp b/src/smpi/include/smpi_datatype_derived.hpp index e98619709a..890b4eb4ae 100644 --- a/src/smpi/include/smpi_datatype_derived.hpp +++ b/src/smpi/include/smpi_datatype_derived.hpp @@ -21,8 +21,8 @@ public: Type_Contiguous(const Type_Contiguous&) = delete; Type_Contiguous& operator=(const Type_Contiguous&) = delete; ~Type_Contiguous(); - void serialize(void* noncontiguous, void* contiguous, int count); - void unserialize(void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); + void serialize(const void* noncontiguous, void* contiguous, int count); + void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); }; class Type_Hvector: public Datatype{ @@ -37,8 +37,8 @@ public: Type_Hvector(const Type_Hvector&) = delete; Type_Hvector& operator=(const Type_Hvector&) = delete; ~Type_Hvector(); - void serialize(void* noncontiguous, void* contiguous, int count); - void unserialize(void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); + void serialize(const void* noncontiguous, void* contiguous, int count); + void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); }; class Type_Vector : public Type_Hvector { @@ -54,20 +54,20 @@ class Type_Hindexed: public Datatype{ MPI_Datatype old_type_; public: - Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, int* block_lengths, - MPI_Aint* block_indices, MPI_Datatype old_type); - Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, int* block_lengths, int* block_indices, + Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, const int* block_lengths, + const MPI_Aint* block_indices, MPI_Datatype old_type); + Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, const int* block_lengths, const int* block_indices, MPI_Datatype old_type, MPI_Aint factor); Type_Hindexed(const Type_Hindexed&) = delete; Type_Hindexed& operator=(const Type_Hindexed&) = delete; ~Type_Hindexed(); - void serialize(void* noncontiguous, void* contiguous, int count); - void unserialize(void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); + void serialize(const void* noncontiguous, void* contiguous, int count); + void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); }; class Type_Indexed : public Type_Hindexed { public: - Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, int* block_lengths, int* block_indices, + Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, const int* block_lengths, const int* block_indices, MPI_Datatype old_type); }; @@ -78,13 +78,13 @@ class Type_Struct: public Datatype{ MPI_Datatype* old_types_; public: - Type_Struct(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, int* block_lengths, - MPI_Aint* block_indices, MPI_Datatype* old_types); + Type_Struct(int size, MPI_Aint lb, MPI_Aint ub, int flags, int block_count, const int* block_lengths, + const MPI_Aint* block_indices, const MPI_Datatype* old_types); Type_Struct(const Type_Struct&) = delete; Type_Struct& operator=(const Type_Struct&) = delete; ~Type_Struct(); - void serialize(void* noncontiguous, void* contiguous, int count); - void unserialize(void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); + void serialize(const void* noncontiguous, void* contiguous, int count); + void unserialize(const void* contiguous_vector, void* noncontiguous_vector, int count, MPI_Op op); }; } // namespace smpi diff --git a/src/smpi/include/smpi_op.hpp b/src/smpi/include/smpi_op.hpp index dcc39c3994..f483eac897 100644 --- a/src/smpi/include/smpi_op.hpp +++ b/src/smpi/include/smpi_op.hpp @@ -25,7 +25,7 @@ public: bool is_fortran_op() { return is_fortran_op_; } // tell that we were created from fortran, so we need to translate the type to fortran when called void set_fortran_op() { is_fortran_op_ = true; } - void apply(void* invec, void* inoutvec, int* len, MPI_Datatype datatype); + void apply(const void* invec, void* inoutvec, int* len, MPI_Datatype datatype); static Op* f2c(int id); void ref(); static void unref(MPI_Op* op); diff --git a/src/smpi/mpi/smpi_datatype.cpp b/src/smpi/mpi/smpi_datatype.cpp index 70002725bb..766629ea13 100644 --- a/src/smpi/mpi/smpi_datatype.cpp +++ b/src/smpi/mpi/smpi_datatype.cpp @@ -250,7 +250,7 @@ void Datatype::set_name(char* name){ name_ = xbt_strdup(name); } -int Datatype::pack(void* inbuf, int incount, void* outbuf, int outcount, int* position, MPI_Comm) +int Datatype::pack(const void* inbuf, int incount, void* outbuf, int outcount, int* position, MPI_Comm) { if (outcount - *position < incount*static_cast(size_)) return MPI_ERR_OTHER; @@ -259,16 +259,16 @@ int Datatype::pack(void* inbuf, int incount, void* outbuf, int outcount, int* po return MPI_SUCCESS; } -int Datatype::unpack(void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Comm) +int Datatype::unpack(const void* inbuf, int insize, int* position, void* outbuf, int outcount, MPI_Comm) { if (outcount*static_cast(size_)> insize) return MPI_ERR_OTHER; - Datatype::copy(static_cast(inbuf) + *position, insize, MPI_CHAR, outbuf, outcount, this); + Datatype::copy(static_cast(inbuf) + *position, insize, MPI_CHAR, outbuf, outcount, this); *position += outcount * size_; return MPI_SUCCESS; } -int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, +int Datatype::copy(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype){ // FIXME Handle the case of a partial shared malloc. @@ -304,15 +304,15 @@ int Datatype::copy(void *sendbuf, int sendcount, MPI_Datatype sendtype, } //Default serialization method : memcpy. -void Datatype::serialize(void* noncontiguous_buf, void* contiguous_buf, int count) +void Datatype::serialize(const void* noncontiguous_buf, void* contiguous_buf, int count) { char* contiguous_buf_char = static_cast(contiguous_buf); - char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb_; + const char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb_; memcpy(contiguous_buf_char, noncontiguous_buf_char, count*size_); } -void Datatype::unserialize( void* contiguous_buf, void *noncontiguous_buf, int count, MPI_Op op){ - char* contiguous_buf_char = static_cast(contiguous_buf); +void Datatype::unserialize(const void* contiguous_buf, void *noncontiguous_buf, int count, MPI_Op op){ + const char* contiguous_buf_char = static_cast(contiguous_buf); char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb_; int n=count; if(op!=MPI_OP_NULL) @@ -380,7 +380,7 @@ int Datatype::create_hvector(int count, int block_length, MPI_Aint stride, MPI_D return retval; } -int Datatype::create_indexed(int count, int* block_lengths, int* indices, MPI_Datatype old_type, MPI_Datatype* new_type){ +int Datatype::create_indexed(int count, const int* block_lengths, const int* indices, MPI_Datatype old_type, MPI_Datatype* new_type){ int size = 0; bool contiguous=true; MPI_Aint lb = 0; @@ -415,7 +415,7 @@ int Datatype::create_indexed(int count, int* block_lengths, int* indices, MPI_Da return MPI_SUCCESS; } -int Datatype::create_hindexed(int count, int* block_lengths, MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type){ +int Datatype::create_hindexed(int count, const int* block_lengths, const MPI_Aint* indices, MPI_Datatype old_type, MPI_Datatype* new_type){ int size = 0; bool contiguous=true; MPI_Aint lb = 0; @@ -449,7 +449,7 @@ int Datatype::create_hindexed(int count, int* block_lengths, MPI_Aint* indices, return MPI_SUCCESS; } -int Datatype::create_struct(int count, int* block_lengths, MPI_Aint* indices, MPI_Datatype* old_types, MPI_Datatype* new_type){ +int Datatype::create_struct(int count, const int* block_lengths, const MPI_Aint* indices, const MPI_Datatype* old_types, MPI_Datatype* new_type){ size_t size = 0; bool contiguous=true; size = 0; @@ -494,8 +494,8 @@ int Datatype::create_struct(int count, int* block_lengths, MPI_Aint* indices, MP return MPI_SUCCESS; } -int Datatype::create_subarray(int ndims, int* array_of_sizes, - int* array_of_subsizes, int* array_of_starts, +int Datatype::create_subarray(int ndims, const int* array_of_sizes, + const int* array_of_subsizes, const int* array_of_starts, int order, MPI_Datatype oldtype, MPI_Datatype *newtype){ MPI_Datatype tmp; diff --git a/src/smpi/mpi/smpi_datatype_derived.cpp b/src/smpi/mpi/smpi_datatype_derived.cpp index ba6c632cd1..9b1140dc2a 100644 --- a/src/smpi/mpi/smpi_datatype_derived.cpp +++ b/src/smpi/mpi/smpi_datatype_derived.cpp @@ -24,16 +24,16 @@ Type_Contiguous::~Type_Contiguous() Datatype::unref(old_type_); } -void Type_Contiguous::serialize(void* noncontiguous_buf, void* contiguous_buf, int count) +void Type_Contiguous::serialize(const void* noncontiguous_buf, void* contiguous_buf, int count) { char* contiguous_buf_char = static_cast(contiguous_buf); - char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb(); + const char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb(); memcpy(contiguous_buf_char, noncontiguous_buf_char, count * block_count_ * old_type_->size()); } -void Type_Contiguous::unserialize(void* contiguous_buf, void* noncontiguous_buf, int count, MPI_Op op) +void Type_Contiguous::unserialize(const void* contiguous_buf, void* noncontiguous_buf, int count, MPI_Op op) { - char* contiguous_buf_char = static_cast(contiguous_buf); + const char* contiguous_buf_char = static_cast(contiguous_buf); char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+lb(); int n= count*block_count_; if(op!=MPI_OP_NULL) @@ -47,10 +47,10 @@ Type_Hvector::~Type_Hvector(){ Datatype::unref(old_type_); } -void Type_Hvector::serialize( void* noncontiguous_buf, void *contiguous_buf, +void Type_Hvector::serialize(const void* noncontiguous_buf, void *contiguous_buf, int count){ char* contiguous_buf_char = static_cast(contiguous_buf); - char* noncontiguous_buf_char = static_cast(noncontiguous_buf); + const char* noncontiguous_buf_char = static_cast(noncontiguous_buf); for (int i = 0; i < block_count_ * count; i++) { if (not(old_type_->flags() & DT_FLAG_DERIVED)) @@ -66,9 +66,9 @@ void Type_Hvector::serialize( void* noncontiguous_buf, void *contiguous_buf, } } -void Type_Hvector::unserialize( void* contiguous_buf, void *noncontiguous_buf, +void Type_Hvector::unserialize(const void* contiguous_buf, void *noncontiguous_buf, int count, MPI_Op op){ - char* contiguous_buf_char = static_cast(contiguous_buf); + const char* contiguous_buf_char = static_cast(contiguous_buf); char* noncontiguous_buf_char = static_cast(noncontiguous_buf); for (int i = 0; i < block_count_ * count; i++) { @@ -91,8 +91,8 @@ Type_Vector::Type_Vector(int size, MPI_Aint lb, MPI_Aint ub, int flags, int coun { } -Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, int* block_lengths, - MPI_Aint* block_indices, MPI_Datatype old_type) +Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, + const MPI_Aint* block_indices, MPI_Datatype old_type) : Datatype(size, lb, ub, flags), block_count_(count), old_type_(old_type) { old_type_->ref(); @@ -104,8 +104,8 @@ Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int } } -Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, int* block_lengths, - int* block_indices, MPI_Datatype old_type, MPI_Aint factor) +Type_Hindexed::Type_Hindexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, + const int* block_indices, MPI_Datatype old_type, MPI_Aint factor) : Datatype(size, lb, ub, flags), block_count_(count), old_type_(old_type) { old_type_->ref(); @@ -126,10 +126,11 @@ Type_Hindexed::~Type_Hindexed() } } -void Type_Hindexed::serialize( void* noncontiguous_buf, void *contiguous_buf, +void Type_Hindexed::serialize(const void* noncontiguous_buf, void *contiguous_buf, int count){ char* contiguous_buf_char = static_cast(contiguous_buf); - char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+ block_indices_[0]; + const char* noncontiguous_buf_iter = static_cast(noncontiguous_buf); + const char* noncontiguous_buf_char = noncontiguous_buf_iter + block_indices_[0]; for (int j = 0; j < count; j++) { for (int i = 0; i < block_count_; i++) { if (not(old_type_->flags() & DT_FLAG_DERIVED)) @@ -139,17 +140,17 @@ void Type_Hindexed::serialize( void* noncontiguous_buf, void *contiguous_buf, contiguous_buf_char += block_lengths_[i]*old_type_->size(); if (i(noncontiguous_buf) + block_indices_[i+1]; + noncontiguous_buf_char = noncontiguous_buf_iter + block_indices_[i+1]; else noncontiguous_buf_char += block_lengths_[i]*old_type_->get_extent(); } - noncontiguous_buf=static_cast(noncontiguous_buf_char); + noncontiguous_buf_iter=noncontiguous_buf_char; } } -void Type_Hindexed::unserialize( void* contiguous_buf, void *noncontiguous_buf, +void Type_Hindexed::unserialize(const void* contiguous_buf, void *noncontiguous_buf, int count, MPI_Op op){ - char* contiguous_buf_char = static_cast(contiguous_buf); + const char* contiguous_buf_char = static_cast(contiguous_buf); char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+ block_indices_[0]; for (int j = 0; j < count; j++) { for (int i = 0; i < block_count_; i++) { @@ -170,13 +171,13 @@ void Type_Hindexed::unserialize( void* contiguous_buf, void *noncontiguous_buf, } } -Type_Indexed::Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, int* block_lengths, - int* block_indices, MPI_Datatype old_type) +Type_Indexed::Type_Indexed(int size, MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, + const int* block_indices, MPI_Datatype old_type) : Type_Hindexed(size, lb, ub, flags, count, block_lengths, block_indices, old_type, old_type->get_extent()) { } -Type_Struct::Type_Struct(int size,MPI_Aint lb, MPI_Aint ub, int flags, int count, int* block_lengths, MPI_Aint* block_indices, MPI_Datatype* old_types): Datatype(size, lb, ub, flags), block_count_(count), block_lengths_(block_lengths), block_indices_(block_indices), old_types_(old_types){ +Type_Struct::Type_Struct(int size,MPI_Aint lb, MPI_Aint ub, int flags, int count, const int* block_lengths, const MPI_Aint* block_indices, const MPI_Datatype* old_types): Datatype(size, lb, ub, flags), block_count_(count){ block_lengths_= new int[count]; block_indices_= new MPI_Aint[count]; old_types_= new MPI_Datatype[count]; @@ -200,10 +201,11 @@ Type_Struct::~Type_Struct(){ } -void Type_Struct::serialize( void* noncontiguous_buf, void *contiguous_buf, +void Type_Struct::serialize(const void* noncontiguous_buf, void *contiguous_buf, int count){ char* contiguous_buf_char = static_cast(contiguous_buf); - char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+ block_indices_[0]; + const char* noncontiguous_buf_iter = static_cast(noncontiguous_buf); + const char* noncontiguous_buf_char = noncontiguous_buf_iter + block_indices_[0]; for (int j = 0; j < count; j++) { for (int i = 0; i < block_count_; i++) { if (not(old_types_[i]->flags() & DT_FLAG_DERIVED)) @@ -214,17 +216,17 @@ void Type_Struct::serialize( void* noncontiguous_buf, void *contiguous_buf, contiguous_buf_char += block_lengths_[i]*old_types_[i]->size(); if (i(noncontiguous_buf) + block_indices_[i+1]; + noncontiguous_buf_char = noncontiguous_buf_iter + block_indices_[i+1]; else //let's hope this is MPI_UB ? noncontiguous_buf_char += block_lengths_[i]*old_types_[i]->get_extent(); } - noncontiguous_buf=static_cast(noncontiguous_buf_char); + noncontiguous_buf_iter=noncontiguous_buf_char; } } -void Type_Struct::unserialize( void* contiguous_buf, void *noncontiguous_buf, +void Type_Struct::unserialize(const void* contiguous_buf, void *noncontiguous_buf, int count, MPI_Op op){ - char* contiguous_buf_char = static_cast(contiguous_buf); + const char* contiguous_buf_char = static_cast(contiguous_buf); char* noncontiguous_buf_char = static_cast(noncontiguous_buf)+ block_indices_[0]; for (int j = 0; j < count; j++) { for (int i = 0; i < block_count_; i++) { diff --git a/src/smpi/mpi/smpi_op.cpp b/src/smpi/mpi/smpi_op.cpp index 2f9da357fa..962978cd24 100644 --- a/src/smpi/mpi/smpi_op.cpp +++ b/src/smpi/mpi/smpi_op.cpp @@ -219,7 +219,7 @@ CREATE_MPI_OP(MPI_NO_OP, no_func); namespace simgrid{ namespace smpi{ -void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype) +void Op::apply(const void *invec, void *inoutvec, int *len, MPI_Datatype datatype) { if (smpi_privatize_global_variables == SmpiPrivStrategies::MMAP) { // we need to switch as the called function may silently touch global variables @@ -229,13 +229,13 @@ void Op::apply(void *invec, void *inoutvec, int *len, MPI_Datatype datatype) if (not smpi_process()->replaying() && *len > 0) { if (not is_fortran_op_) - this->func_(invec, inoutvec, len, &datatype); + this->func_(const_cast(invec), inoutvec, len, &datatype); else{ XBT_DEBUG("Applying operation of length %d from %p and from/to %p", *len, invec, inoutvec); int tmp = datatype->c2f(); /* Unfortunately, the C and Fortran version of the MPI standard do not agree on the type here, thus the reinterpret_cast. */ - this->func_(invec, inoutvec, len, reinterpret_cast(&tmp) ); + this->func_(const_cast(invec), inoutvec, len, reinterpret_cast(&tmp) ); } } } -- 2.20.1