diff --git a/lib/recorder-mpi.c b/lib/recorder-mpi.c index 5944962..98897b7 100644 --- a/lib/recorder-mpi.c +++ b/lib/recorder-mpi.c @@ -68,24 +68,55 @@ #define CONST #endif +typedef struct MPICommHash_t { + void *key; + char* id; + UT_hash_handle hh; +} MPICommHash; +static MPICommHash *mpi_comm_table = NULL; + -int depth; static int split_times; // how many time we see MPI_Comm_split static int dup_times; - - -static inline char *comm2name(MPI_Comm comm) { - int len = 0; - char *tmp = calloc(128, sizeof(char)); - if(comm == MPI_COMM_NULL) - strcpy(tmp, "MPI_COMM_NULL"); - else { - PMPI_Comm_get_name(comm, tmp, &len); - if(len == 0) - strcpy(tmp, "MPI_COMM_UNKNOWN"); +void add_mpi_comm(MPI_Comm *newcomm) { + if(newcomm == NULL || *newcomm == MPI_COMM_NULL) + return; + int new_rank, world_rank; + PMPI_Comm_rank(*newcomm, &new_rank); + PMPI_Comm_rank(MPI_COMM_WORLD, &world_rank); + + MPICommHash *entry = malloc(sizeof(MPICommHash)); + entry->key = malloc(sizeof(MPI_Comm)); + memcpy(entry->key, newcomm, sizeof(MPI_Comm)); + + // Rank 0 of the new communicator decides an unique id + // and broadcast it to all others, then everyone stores it + // in the hash table. + char *id = calloc(32, sizeof(char)); + if(new_rank == 0) + sprintf(id, "%d%d", *newcomm, new_rank); + PMPI_Bcast(id, 32, MPI_BYTE, 0, *newcomm); + entry->id = id; + + HASH_ADD_KEYPTR(hh, mpi_comm_table, entry->key, sizeof(MPI_Comm), entry); +} + +char* comm2name(MPI_Comm *comm) { + if(comm == NULL || *comm == MPI_COMM_NULL) + return strdup("MPI_COMM_NULL"); + else if(*comm == MPI_COMM_WORLD) { + return strdup("MPI_COMM_WORLD"); + } else if(*comm == MPI_COMM_SELF) { + return strdup("MPI_COMM_SELF"); + } else { + MPICommHash *entry = NULL; + HASH_FIND(hh, mpi_comm_table, comm, sizeof(MPI_Comm), entry); + if(entry) + return strdup(entry->id); + else + return strdup("MPI_COMM_NULL"); } - return tmp; } static inline char *type2name(MPI_Datatype type) { @@ -121,13 +152,13 @@ static inline char* whence2name(int whence) { */ int RECORDER_MPI_DECL(MPI_Comm_size)(MPI_Comm comm, int *size) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_size, (comm, size)); - char **args = assemble_args_list(2, comm2name(comm), itoa(*size)); + char **args = assemble_args_list(2, comm2name(&comm), itoa(*size)); RECORDER_INTERCEPTOR(2, args); } int RECORDER_MPI_DECL(MPI_Comm_rank)(MPI_Comm comm, int *rank) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_rank, (comm, rank)); - char **args = assemble_args_list(2, comm2name(comm), itoa(*rank)); + char **args = assemble_args_list(2, comm2name(&comm), itoa(*rank)); RECORDER_INTERCEPTOR(2, args); } @@ -139,26 +170,26 @@ int RECORDER_MPI_DECL(MPI_Get_processor_name)(char *name, int *resultlen) { int RECORDER_MPI_DECL(MPI_Comm_set_errhandler)(MPI_Comm comm, MPI_Errhandler errhandler) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_set_errhandler, (comm, errhandler)); - char **args = assemble_args_list(2, comm2name(comm), ptoa(&errhandler)); + char **args = assemble_args_list(2, comm2name(&comm), ptoa(&errhandler)); RECORDER_INTERCEPTOR(2, args); } int RECORDER_MPI_DECL(MPI_Barrier)(MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Barrier, (comm)); - char **args = assemble_args_list(1, comm2name(comm)); + char **args = assemble_args_list(1, comm2name(&comm)); RECORDER_INTERCEPTOR(1, args); } int RECORDER_MPI_DECL(MPI_Bcast)(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Bcast, (buffer, count, datatype, root, comm)); - char **args = assemble_args_list(5, ptoa(buffer), itoa(count), type2name(datatype), itoa(root), comm2name(comm)); + char **args = assemble_args_list(5, ptoa(buffer), itoa(count), type2name(datatype), itoa(root), comm2name(&comm)); RECORDER_INTERCEPTOR(5, args); } int RECORDER_MPI_DECL(MPI_Ibcast)(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm, MPI_Request *request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Ibcast, (buffer, count, datatype, root, comm, request)); size_t r = *request; - char **args = assemble_args_list(6, ptoa(buffer), itoa(count), type2name(datatype), itoa(root), comm2name(comm), itoa(r)); + char **args = assemble_args_list(6, ptoa(buffer), itoa(count), type2name(datatype), itoa(root), comm2name(&comm), itoa(r)); RECORDER_INTERCEPTOR(6, args); } @@ -166,7 +197,7 @@ int RECORDER_MPI_DECL(MPI_Gather)(CONST void *sbuf, int scount, MPI_Datatype sty int rcount, MPI_Datatype rtype, int root, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Gather, (sbuf, scount, stype, rbuf, rcount, rtype, root, comm)); char **args = assemble_args_list(8, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(comm)); + ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(&comm)); RECORDER_INTERCEPTOR(8, args); } @@ -174,7 +205,7 @@ int RECORDER_MPI_DECL(MPI_Scatter)(CONST void *sbuf, int scount, MPI_Datatype st int rcount, MPI_Datatype rtype, int root, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Scatter, (sbuf, scount, stype, rbuf, rcount, rtype, root, comm)); char **args = assemble_args_list(8, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(comm)); + ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(&comm)); RECORDER_INTERCEPTOR(8, args); } @@ -183,7 +214,7 @@ int RECORDER_MPI_DECL(MPI_Gatherv)(CONST void *sbuf, int scount, MPI_Datatype st // TODO: *displs RECORDER_INTERCEPTOR_NOIO(int, PMPI_Gatherv, (sbuf, scount, stype, rbuf, rcount, displs, rtype, root, comm)); char **args = assemble_args_list(9, ptoa(sbuf), itoa(scount), type2name(stype), ptoa(rbuf), - ptoa(rcount), ptoa(displs), type2name(rtype), itoa(root), comm2name(comm)); + ptoa(rcount), ptoa(displs), type2name(rtype), itoa(root), comm2name(&comm)); RECORDER_INTERCEPTOR(9, args); } @@ -192,7 +223,7 @@ int RECORDER_MPI_DECL(MPI_Scatterv)(CONST void *sbuf, CONST int *scount, CONST i MPI_Datatype stype, void *rbuf, int rcount, MPI_Datatype rtype, int root, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Scatterv, (sbuf, scount, displa, stype, rbuf, rcount, rtype, root, comm)); char **args = assemble_args_list(9, ptoa(sbuf), ptoa(scount), ptoa(displa), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(comm)); + ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(&comm)); RECORDER_INTERCEPTOR(9, args); } @@ -208,7 +239,7 @@ int RECORDER_MPI_DECL(MPI_Allgatherv)(CONST void *sbuf, int scount, MPI_Datatype // TODO: displs RECORDER_INTERCEPTOR_NOIO(int, PMPI_Allgatherv, (sbuf, scount, stype, rbuf, rcount, displs, rtype, comm)); char **args = assemble_args_list(8, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), ptoa(rcount), ptoa(displs), type2name(rtype), comm2name(comm)); + ptoa(rbuf), ptoa(rcount), ptoa(displs), type2name(rtype), comm2name(&comm)); RECORDER_INTERCEPTOR(8, args); } @@ -217,7 +248,7 @@ int RECORDER_MPI_DECL(MPI_Alltoall)(CONST void *sbuf, int scount, MPI_Datatype s int rcount, MPI_Datatype rtype, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Alltoall, (sbuf, scount, stype, rbuf, rcount, rtype, comm)); char **args = assemble_args_list(7, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), comm2name(comm)); + ptoa(rbuf), itoa(rcount), type2name(rtype), comm2name(&comm)); RECORDER_INTERCEPTOR(7, args); } @@ -225,13 +256,13 @@ int RECORDER_MPI_DECL(MPI_Alltoall)(CONST void *sbuf, int scount, MPI_Datatype s int RECORDER_MPI_DECL(MPI_Reduce)(CONST void *sbuf, void *rbuf, int count, MPI_Datatype stype, MPI_Op op, int root, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Reduce, (sbuf, rbuf, count, stype, op, root, comm)); char **args = assemble_args_list(7, ptoa(sbuf), ptoa(rbuf), itoa(count), type2name(stype), - itoa(op), itoa(root), comm2name(comm)); + itoa(op), itoa(root), comm2name(&comm)); RECORDER_INTERCEPTOR(7, args); } int RECORDER_MPI_DECL(MPI_Allreduce)(CONST void *sbuf, void *rbuf, int count, MPI_Datatype stype, MPI_Op op, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Allreduce, (sbuf, rbuf, count, stype, op, comm)); - char **args = assemble_args_list(6, ptoa(sbuf), ptoa(rbuf), itoa(count), type2name(stype), itoa(op), comm2name(comm)); + char **args = assemble_args_list(6, ptoa(sbuf), ptoa(rbuf), itoa(count), type2name(stype), itoa(op), comm2name(&comm)); RECORDER_INTERCEPTOR(6, args) } @@ -239,13 +270,13 @@ int RECORDER_MPI_DECL(MPI_Reduce_scatter)(CONST void *sbuf, void *rbuf, CONST in MPI_Datatype stype, MPI_Op op, MPI_Comm comm) { // TODO: *rcounts RECORDER_INTERCEPTOR_NOIO(int, PMPI_Reduce_scatter, (sbuf, rbuf, rcounts, stype, op, comm)); - char **args = assemble_args_list(6, ptoa(sbuf), ptoa(rbuf), ptoa(rcounts), type2name(stype), itoa(op), comm2name(comm)); + char **args = assemble_args_list(6, ptoa(sbuf), ptoa(rbuf), ptoa(rcounts), type2name(stype), itoa(op), comm2name(&comm)); RECORDER_INTERCEPTOR(6, args); } int RECORDER_MPI_DECL(MPI_Scan)(CONST void *sbuf, void *rbuf, int count, MPI_Datatype stype, MPI_Op op, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Scan, (sbuf, rbuf, count, stype, op, comm)); - char **args = assemble_args_list(6, ptoa(sbuf), ptoa(rbuf), itoa(count), type2name(stype), itoa(op), comm2name(comm)); + char **args = assemble_args_list(6, ptoa(sbuf), ptoa(rbuf), itoa(count), type2name(stype), itoa(op), comm2name(&comm)); RECORDER_INTERCEPTOR(6, args); } @@ -266,7 +297,7 @@ int RECORDER_MPI_DECL(MPI_Type_commit)(MPI_Datatype *datatype) { int RECORDER_MPI_DECL(MPI_File_open)(MPI_Comm comm, CONST char *filename, int amode, MPI_Info info, MPI_File *fh) { // TODO: filename RECORDER_INTERCEPTOR_NOIO(int, PMPI_File_open, (comm, filename, amode, info, fh)); - char **args = assemble_args_list(5, comm2name(comm), realrealpath(filename), itoa(amode), ptoa(&info), ptoa(fh)); + char **args = assemble_args_list(5, comm2name(&comm), realrealpath(filename), itoa(amode), ptoa(&info), ptoa(fh)); RECORDER_INTERCEPTOR(5, args); } @@ -462,22 +493,23 @@ int RECORDER_MPI_DECL(MPI_Finalized)(int *flag) { // Added 10 new MPI funcitons on 2019/01/07 int RECORDER_MPI_DECL(MPI_Cart_rank) (MPI_Comm comm, CONST int coords[], int *rank) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Cart_rank, (comm, coords, rank)); - char **args = assemble_args_list(3, comm2name(comm), ptoa(coords), ptoa(rank)); + char **args = assemble_args_list(3, comm2name(&comm), ptoa(coords), ptoa(rank)); RECORDER_INTERCEPTOR(3, args); } int RECORDER_MPI_DECL(MPI_Cart_create) (MPI_Comm comm_old, int ndims, CONST int dims[], CONST int periods[], int reorder, MPI_Comm *comm_cart) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Cart_create, (comm_old, ndims, dims, periods, reorder, comm_cart)); - char **args = assemble_args_list(6, comm2name(comm_old), itoa(ndims), ptoa(dims), ptoa(periods), itoa(reorder), ptoa(comm_cart)); + add_mpi_comm(comm_cart); + char **args = assemble_args_list(6, comm2name(&comm_old), itoa(ndims), ptoa(dims), ptoa(periods), itoa(reorder), comm2name(comm_cart)); RECORDER_INTERCEPTOR(6, args) } int RECORDER_MPI_DECL(MPI_Cart_get) (MPI_Comm comm, int maxdims, int dims[], int periods[], int coords[]) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Cart_get, (comm, maxdims, dims, periods, coords)); - char **args = assemble_args_list(5, comm2name(comm), itoa(maxdims), ptoa(dims), ptoa(periods), ptoa(coords)); + char **args = assemble_args_list(5, comm2name(&comm), itoa(maxdims), ptoa(dims), ptoa(periods), ptoa(coords)); RECORDER_INTERCEPTOR(5, args); } int RECORDER_MPI_DECL(MPI_Cart_shift) (MPI_Comm comm, int direction, int disp, int *rank_source, int *rank_dest) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Cart_shift, (comm, direction, disp, rank_source, rank_dest)); - char **args = assemble_args_list(5, comm2name(comm), itoa(direction), itoa(disp), ptoa(rank_source), ptoa(rank_dest)); + char **args = assemble_args_list(5, comm2name(&comm), itoa(direction), itoa(disp), ptoa(rank_source), ptoa(rank_dest)); RECORDER_INTERCEPTOR(5, args); } int RECORDER_MPI_DECL(MPI_Wait) (MPI_Request *request, MPI_Status *status) { @@ -488,31 +520,31 @@ int RECORDER_MPI_DECL(MPI_Wait) (MPI_Request *request, MPI_Status *status) { int RECORDER_MPI_DECL(MPI_Send) (CONST void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Send, (buf, count, datatype, dest, tag, comm)); - char **args = assemble_args_list(6, ptoa(buf), itoa(count), type2name(datatype), itoa(dest), itoa(tag), comm2name(comm)); + char **args = assemble_args_list(6, ptoa(buf), itoa(count), type2name(datatype), itoa(dest), itoa(tag), comm2name(&comm)); RECORDER_INTERCEPTOR(6, args); } int RECORDER_MPI_DECL(MPI_Recv) (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Recv, (buf, count, datatype, source, tag, comm, status)); - char **args = assemble_args_list(7, ptoa(buf), itoa(count), type2name(datatype), itoa(source), itoa(tag), comm2name(comm), status2str(status)); + char **args = assemble_args_list(7, ptoa(buf), itoa(count), type2name(datatype), itoa(source), itoa(tag), comm2name(&comm), status2str(status)); RECORDER_INTERCEPTOR(7, args); } int RECORDER_MPI_DECL(MPI_Sendrecv) (CONST void *sendbuf, int sendcount, MPI_Datatype sendtype, int dest, int sendtag, void *recvbuf, int recvcount, MPI_Datatype recvtype, int source, int recvtag, MPI_Comm comm, MPI_Status *status) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Sendrecv, (sendbuf, sendcount, sendtype, dest, sendtag, recvbuf, recvcount, recvtype, source, recvtag, comm, status)); char **args = assemble_args_list(12, ptoa(sendbuf), itoa(sendcount), type2name(sendtype), itoa(dest), itoa(sendtag), ptoa(recvbuf), itoa(recvcount), type2name(recvtype), - itoa(source), itoa(recvtag), comm2name(comm), status2str(status)); + itoa(source), itoa(recvtag), comm2name(&comm), status2str(status)); RECORDER_INTERCEPTOR(12, args); } int RECORDER_MPI_DECL(MPI_Isend) (CONST void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Isend, (buf, count, datatype, dest, tag, comm, request)); size_t r = *request; - char **args = assemble_args_list(7, ptoa(buf), itoa(count), type2name(datatype), itoa(dest), itoa(tag), comm2name(comm), itoa(r)); + char **args = assemble_args_list(7, ptoa(buf), itoa(count), type2name(datatype), itoa(dest), itoa(tag), comm2name(&comm), itoa(r)); RECORDER_INTERCEPTOR(7, args); } int RECORDER_MPI_DECL(MPI_Irecv) (void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Irecv, (buf, count, datatype, source, tag, comm, request)); size_t r = *request; - char **args = assemble_args_list(7, ptoa(buf), itoa(count), type2name(datatype), itoa(source), itoa(tag), comm2name(comm), itoa(r)); + char **args = assemble_args_list(7, ptoa(buf), itoa(count), type2name(datatype), itoa(source), itoa(tag), comm2name(&comm), itoa(r)); RECORDER_INTERCEPTOR(7, args); } @@ -557,67 +589,29 @@ int RECORDER_MPI_DECL(MPI_Waitany) (int count, MPI_Request requests[], int *indx } int RECORDER_MPI_DECL(MPI_Ssend) (CONST void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Ssend, (buf, count, datatype, dest, tag, comm)); - char **args = assemble_args_list(6, ptoa(buf), itoa(count), type2name(datatype), itoa(dest), itoa(tag), comm2name(comm)); + char **args = assemble_args_list(6, ptoa(buf), itoa(count), type2name(datatype), itoa(dest), itoa(tag), comm2name(&comm)); RECORDER_INTERCEPTOR(6, args); } int RECORDER_MPI_DECL(MPI_Comm_split) (MPI_Comm comm, int color, int key, MPI_Comm *newcomm) { - //printf("comm: %d, color: %d, key: %d\n", comm, color, key); RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_split, (comm, color, key, newcomm)); - - if((newcomm != NULL) && (*newcomm != MPI_COMM_NULL)) { - int rank; - PMPI_Comm_rank(*newcomm, &rank); - - char new_comm_name[128] = {0}; - if(rank == 0) { - char* parent_name = comm2name(comm); - - int global_rank; - PMPI_Comm_rank(MPI_COMM_WORLD, &global_rank); - - sprintf(new_comm_name, "%s_(%d,%d)", parent_name, split_times++, global_rank); - free(parent_name); - } - PMPI_Bcast(&split_times, 1, MPI_INT, 0, *newcomm); - PMPI_Bcast(new_comm_name, 128, MPI_CHAR, 0, *newcomm); - PMPI_Comm_set_name(*newcomm, new_comm_name); - } - - char **args = assemble_args_list(4, comm2name(comm), itoa(color), itoa(key), comm2name(*newcomm)); + add_mpi_comm(newcomm); + char **args = assemble_args_list(4, comm2name(&comm), itoa(color), itoa(key), comm2name(newcomm)); RECORDER_INTERCEPTOR(4, args); } int RECORDER_MPI_DECL(MPI_Comm_create) (MPI_Comm comm, MPI_Group group, MPI_Comm *newcomm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_create, (comm, group, newcomm)); - char **args = assemble_args_list(3, comm2name(comm), itoa(group), comm2name(*newcomm)); + add_mpi_comm(newcomm); + char **args = assemble_args_list(3, comm2name(&comm), itoa(group), comm2name(newcomm)); RECORDER_INTERCEPTOR(3, args); } -int RECORDER_MPI_DECL(MPI_Comm_dup) (MPI_Comm comm, MPI_Comm * newcomm) { +int RECORDER_MPI_DECL(MPI_Comm_dup) (MPI_Comm comm, MPI_Comm *newcomm) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_dup, (comm, newcomm)); - - if((newcomm != NULL) && (*newcomm != MPI_COMM_NULL)) { - int rank; - PMPI_Comm_rank(*newcomm, &rank); - - char new_comm_name[128] = {0}; - if(rank == 0) { - char* parent_name = comm2name(comm); - - int global_rank; - PMPI_Comm_rank(MPI_COMM_WORLD, &global_rank); - - sprintf(new_comm_name, "%s_dup(%d,%d)", parent_name, dup_times++, global_rank); - free(parent_name); - } - PMPI_Bcast(&dup_times, 1, MPI_INT, 0, *newcomm); - PMPI_Bcast(new_comm_name, 128, MPI_CHAR, 0, *newcomm); - PMPI_Comm_set_name(*newcomm, new_comm_name); - } - - char **args = assemble_args_list(2, comm2name(comm), comm2name(*newcomm)); + add_mpi_comm(newcomm); + char **args = assemble_args_list(2, comm2name(&comm), comm2name(newcomm)); RECORDER_INTERCEPTOR(2, args); } @@ -689,31 +683,39 @@ int RECORDER_MPI_DECL(MPI_Testany) (int count, MPI_Request requests[], int *indx int RECORDER_MPI_DECL(MPI_Ireduce) (const void *sbuf, void *rbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm, MPI_Request *request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Ireduce, (sbuf, rbuf, count, datatype, op, root, comm, request)); char **args = assemble_args_list(8, ptoa(sbuf), ptoa(rbuf), itoa(count), type2name(datatype), - itoa(op), itoa(root), comm2name(comm), itoa(*request)); + itoa(op), itoa(root), comm2name(&comm), itoa(*request)); RECORDER_INTERCEPTOR(8, args); } int RECORDER_MPI_DECL(MPI_Igather) (const void *sbuf, int scount, MPI_Datatype stype, void *rbuf, int rcount, MPI_Datatype rtype, int root, MPI_Comm comm, MPI_Request *request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Igather, (sbuf, scount, stype, rbuf, rcount, rtype, root, comm, request)); char **args = assemble_args_list(9, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(comm), itoa(*request)); + ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(&comm), itoa(*request)); RECORDER_INTERCEPTOR(9, args); } int RECORDER_MPI_DECL(MPI_Iscatter) (const void *sbuf, int scount, MPI_Datatype stype, void *rbuf, int rcount, MPI_Datatype rtype, int root, MPI_Comm comm, MPI_Request *request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Iscatter, (sbuf, scount, stype, rbuf, rcount, rtype, root, comm, request)); char **args = assemble_args_list(9, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(comm), itoa(*request)); + ptoa(rbuf), itoa(rcount), type2name(rtype), itoa(root), comm2name(&comm), itoa(*request)); RECORDER_INTERCEPTOR(9, args); } int RECORDER_MPI_DECL(MPI_Ialltoall) (const void *sbuf, int scount, MPI_Datatype stype, void *rbuf, int rcount, MPI_Datatype rtype, MPI_Comm comm, MPI_Request * request) { RECORDER_INTERCEPTOR_NOIO(int, PMPI_Ialltoall, (sbuf, scount, stype, rbuf, rcount, rtype, comm, request)); char **args = assemble_args_list(8, ptoa(sbuf), itoa(scount), type2name(stype), - ptoa(rbuf), itoa(rcount), type2name(rtype), comm2name(comm), itoa(*request)); + ptoa(rbuf), itoa(rcount), type2name(rtype), comm2name(&comm), itoa(*request)); RECORDER_INTERCEPTOR(8, args); } // Add MPI_Comm_Free on 2021/01/25 int RECORDER_MPI_DECL(MPI_Comm_free) (MPI_Comm *comm) { - char* comm_name = comm2name(*comm); + char* comm_name = comm2name(comm); + MPICommHash *entry = NULL; + HASH_FIND(hh, mpi_comm_table, comm, sizeof(MPI_Comm), entry); + if(entry) { + HASH_DEL(mpi_comm_table, entry); + free(entry->id); + free(entry); + } + RECORDER_INTERCEPTOR_NOIO(int, PMPI_Comm_free, (comm)); char **args = assemble_args_list(1, comm_name); RECORDER_INTERCEPTOR(1, args); diff --git a/test/test_mpi.c b/test/test_mpi.c index b357bd6..7cec969 100644 --- a/test/test_mpi.c +++ b/test/test_mpi.c @@ -16,7 +16,6 @@ int main(int argc, char *argv[]) { MPI_Comm comm; MPI_Comm_dup(MPI_COMM_WORLD, &comm); - MPI_Comm_free(&comm); MPI_Datatype type = MPI_LONG_INT; MPI_Type_commit(&type); @@ -25,7 +24,8 @@ int main(int argc, char *argv[]) { int name_len; MPI_Get_processor_name(processor_name, &name_len); - MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN); + MPI_Comm_set_errhandler(comm, MPI_ERRORS_RETURN); + MPI_Comm_free(&comm); void *sbuf = processor_name; int scount = name_len;