MPI user-defined datatype size
Hi, I'm running MPICH 4.1.2. Should a MPI user-defined datatype created by MPI_Type_create_struct have the same size as the C++ object on which it is based? Comparing sizeof(cpp_obj) and the output
From MPI_Type_size(mpi_data_type_, &size1), the C++ object is four bytes larger than the MPI datatype. I don't know if this is because I have to do something special to take padding into account when I create the MPI user datatype.
Here is my C++ message class: struct MsgTupleSeq { static const int N_INDICES_MAX_ = 4; // culprit? int n_vars_; int n_ndxs_; short start_[N_INDICES_MAX_]; short end_[N_INDICES_MAX_]; short current_[N_INDICES_MAX_]; long long n_tuples_; int unique_id_; int subordinate_id_; int opcode_; char error_msg_[512]; } That is 564 bytes for the non-static members, but such an object is 568 bytes long with the 4 bytes of padding that the compiler inserts. I define the MPI user datatype with the code below, using the MsgTupleSeq object to compute the offsets. MPI_Type_size returns 564 bytes for the user datatype, so it seems like it isn't seeing the padding. MsgTupleSeq obj; MPI_Datatype mpi_data_type; int struct_len = 10, i = 0; int block_len[struct_len]; MPI_Datatype types[struct_len]; MPI_Aint displacements[struct_len]; // the integer "n_vars_" member block_len[i] = 1; types[i] = MPI_INT; displacements[i] = (size_t) &obj.n_vars_ - (size_t) &obj; // the integer "n_ndxs_" member ++i; block_len[i] = 1; types[i] = MPI_INT; displacements[i] = (size_t) &obj.n_ndxs_ - (size_t) &obj; // the short integer "start_" array member ++i; block_len[i] = N_INDICES_MAX_; types[i] = MPI_SHORT; displacements[i] = (size_t) &obj.start_ - (size_t) &obj; // the short integer "end_" array member ++i; block_len[i] = N_INDICES_MAX_; types[i] = MPI_SHORT; displacements[i] = (size_t) &obj.end_ - (size_t) &obj; // the short integer "current_" array member ++i; block_len[i] = N_INDICES_MAX_; types[i] = MPI_SHORT; displacements[i] = (size_t) &obj.current_ - (size_t) &obj; // the long long integer "n_tuples_" member ++i; block_len[i] = 1; types[i] = MPI_LONG_LONG; displacements[i] = (size_t) &obj.n_tuples_ - (size_t) &obj; // the integer "unique_id_" member ++i; block_len[i] = 1; types[i] = MPI_INT; displacements[i] = (size_t) &obj.unique_id_ - (size_t) &obj; // the integer "subordinate_id_" member ++i; block_len[i] = 1; types[i] = MPI_INT; displacements[i] = (size_t) &obj.subordinate_id_ - (size_t) &obj; // the integer "opcode_" member ++i; block_len[i] = 1; types[i] = MPI_INT; displacements[i] = (size_t) &obj.opcode_ - (size_t) &obj; // the char array "error_msg_" member ++i; block_len[i] = 512; types[i] = MPI_CHAR; displacements[i] = (size_t) &obj.error_msg_[0] - (size_t) &obj; MPI_Type_create_struct(struct_len, block_len, displacements, types, &mpi_data_type); MPI_Type_commit(&mpi_data_type);
participants (1)
-
Mccall, Kurt E. (MSFC-EV41)