Skip to content

Instantly share code, notes, and snippets.

@rupertnash
Created April 23, 2014 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rupertnash/11222282 to your computer and use it in GitHub Desktop.
Save rupertnash/11222282 to your computer and use it in GitHub Desktop.
Bug report: non-blocking collectives with user-defined operation gives segfault
#include <mpi.h>
#include <stdio.h>
typedef struct DensityEtc {
double min;
double max;
double maxVel;
} DensityEtc;
void MpiOpUpdateFunc(void* invec, void* inoutvec, int *len, MPI_Datatype *datatype)
{
const DensityEtc* iv = (const DensityEtc*)(invec);
DensityEtc* iov = (DensityEtc*)(inoutvec);
for (int i = 0; i < *len; ++i, ++iv, ++iov) {
iov->min = iv->min < iov->min ? iv->min : iov->min;
iov->max = iv->max > iov->max ? iv->max : iov->max;
iov->maxVel = iv->maxVel > iov->maxVel ? iv->maxVel : iov->maxVel;
}
}
int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
MPI_Comm world = MPI_COMM_WORLD;
int rank, size;
MPI_Comm_rank(world, &rank);
MPI_Comm_size(world, &size);
MPI_Datatype density_t;
MPI_Type_contiguous(3, MPI_DOUBLE, &density_t);
MPI_Type_commit(&density_t);
MPI_Op upDensity;
MPI_Op_create(&MpiOpUpdateFunc, 1, &upDensity);
FILE* log;
if (rank == 0)
log = fopen("log", "w");
int a = rank, aMin, aMax;
DensityEtc densLocal;
densLocal.min = rank;
densLocal.max = rank * 2;
densLocal.maxVel = 0.5 * rank + 11;
DensityEtc densGlobal;
MPI_Request minReq, densReq;
MPI_Comm minComm, densComm;
MPI_Iallreduce(&densLocal, &densGlobal, 1, density_t, upDensity, world, &densReq);
MPI_Wait(&densReq, MPI_STATUS_IGNORE);
if (rank == 0) {
fprintf(log, "Rank %d: min = %d\n", rank, aMin);
fprintf(log, "Rank %d: min = %e, max = %e, maxVel = %e\n", rank, densGlobal.min, densGlobal.max, densGlobal.maxVel);
}
MPI_Finalize();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment