Skip to content

Commit

Permalink
mpidummy: add MPI_Type_size()
Browse files Browse the repository at this point in the history
and use it internally, instead of repeated switch statements.
I'm intentionally using an if-else chain rather than switch in the
implementation, since I want this to work if MPI_Datatype isn't an
integer type in the future.
  • Loading branch information
germasch committed May 29, 2019
1 parent 649753b commit b595b2a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
97 changes: 46 additions & 51 deletions source/adios2/helper/mpidummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,57 +105,28 @@ int MPI_Gather(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
MPI_Comm comm)
{
int ier = MPI_SUCCESS;
size_t n = 0, nsent = 0, nrecv = 0;
int n;
size_t nsent = 0, nrecv = 0;
if (!sendbuf && !recvbuf)
{
return ier;
}
if (comm == MPI_COMM_NULL || root)
{
ier = MPI_ERR_COMM;
return MPI_ERR_COMM;
}

switch (sendtype)
ier = MPI_Type_size(sendtype, &n);
if (ier != MPI_SUCCESS)
{
case MPI_CHAR:
n = sizeof(char);
break;
case MPI_INT:
n = sizeof(int);
break;
case MPI_UNSIGNED:
n = sizeof(unsigned int);
break;
case MPI_UNSIGNED_LONG:
n = sizeof(unsigned long);
break;
case MPI_UNSIGNED_LONG_LONG:
n = sizeof(unsigned long long);
break;
default:
return MPI_ERR_TYPE;
return ier;
}
nsent = n * sendcnt;

switch (recvtype)
ier = MPI_Type_size(recvtype, &n);
if (ier != MPI_SUCCESS)
{
case MPI_CHAR:
n = sizeof(char);
break;
case MPI_INT:
n = sizeof(int);
break;
case MPI_UNSIGNED:
n = sizeof(unsigned int);
break;
case MPI_UNSIGNED_LONG:
n = sizeof(unsigned long);
break;
case MPI_UNSIGNED_LONG_LONG:
n = sizeof(unsigned long long);
break;
default:
return MPI_ERR_TYPE;
return ier;
}
nrecv = n * recvcnt;

Expand Down Expand Up @@ -206,7 +177,8 @@ int MPI_Scatter(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
MPI_Comm comm)
{
int ier = MPI_SUCCESS;
size_t n = 0, nsent = 0, nrecv = 0;
int n;
size_t nsent = 0, nrecv = 0;
if (!sendbuf || !recvbuf)
{
ier = MPI_ERR_BUFFER;
Expand All @@ -217,23 +189,17 @@ int MPI_Scatter(const void *sendbuf, int sendcnt, MPI_Datatype sendtype,
ier = MPI_ERR_COMM;
}

switch (sendtype)
ier = MPI_Type_size(sendtype, &n);
if (ier != MPI_SUCCESS)
{
case MPI_INT:
n = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
return ier;
}
nsent = n * sendcnt;

switch (recvtype)
ier = MPI_Type_size(recvtype, &n);
if (ier != MPI_SUCCESS)
{
case MPI_INT:
n = sizeof(int);
break;
default:
return MPI_ERR_TYPE;
return ier;
}
nrecv = n * recvcnt;

Expand Down Expand Up @@ -467,6 +433,35 @@ int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count,
return MPI_Reduce(sendbuf, recvbuf, count, datatype, op, 0, comm);
}

int MPI_Type_size(MPI_Datatype datatype, int *size)
{
if (datatype == MPI_CHAR)
{
*size = sizeof(char);
}
else if (datatype == MPI_INT)
{
*size = sizeof(int);
}
else if (datatype == MPI_UNSIGNED)
{
*size = sizeof(unsigned int);
}
else if (datatype == MPI_UNSIGNED_LONG)
{
*size = sizeof(unsigned long);
}
else if (datatype == MPI_UNSIGNED_LONG_LONG)
{
*size = sizeof(unsigned long long);
}
else
{
return MPI_ERR_TYPE;
}
return MPI_SUCCESS;
}

} // end namespace mpi
} // end namespace helper
} // end namespace adios2
2 changes: 2 additions & 0 deletions source/adios2/helper/mpidummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest,

int MPI_Wait(MPI_Request *request, MPI_Status *status);

int MPI_Type_size(MPI_Datatype datatype, int *size);

int MPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info,
MPI_File *fh);
int MPI_File_close(MPI_File *fh);
Expand Down

0 comments on commit b595b2a

Please sign in to comment.