int main(int argc, char **argv) { int comm_size, comm_rank; MPI_Comm comm; MTest_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &comm_size); MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank); if (comm_size < 3) { fprintf(stderr, "At least 3 processes required\n"); MPI_Abort(MPI_COMM_WORLD, 1); } if (LARGE_BUF * comm_size > MAX_BUF) goto fn_exit; sbuf = (void *) calloc(MAX_BUF, 1); rbuf = (void *) calloc(MAX_BUF, 1); srand(time(NULL)); recvcounts = (void *) malloc(comm_size * sizeof(int)); displs = (void *) malloc(comm_size * sizeof(int)); if (!recvcounts || !displs || !sbuf || !rbuf) { fprintf(stderr, "Unable to allocate memory:\n"); if (!sbuf) fprintf(stderr, "\tsbuf of %d bytes\n", MAX_BUF); if (!rbuf) fprintf(stderr, "\trbuf of %d bytes\n", MAX_BUF); if (!recvcounts) fprintf(stderr, "\trecvcounts of %zd bytes\n", comm_size * sizeof(int)); if (!displs) fprintf(stderr, "\tdispls of %zd bytes\n", comm_size * sizeof(int)); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } if (!comm_rank) { dprintf("Message Range: (%d, %d); System size: %d\n", START_BUF, LARGE_BUF, comm_size); fflush(stdout); } /* COMM_WORLD tests */ if (!comm_rank) { dprintf("\n\n==========================================================\n"); dprintf(" MPI_COMM_WORLD\n"); dprintf("==========================================================\n"); } comm_tests(MPI_COMM_WORLD); /* non-COMM_WORLD tests */ if (!comm_rank) { dprintf("\n\n==========================================================\n"); dprintf(" non-COMM_WORLD\n"); dprintf("==========================================================\n"); } MPI_Comm_split(MPI_COMM_WORLD, (comm_rank == comm_size - 1) ? 0 : 1, 0, &comm); if (comm_rank < comm_size - 1) comm_tests(comm); MPI_Comm_free(&comm); /* Randomized communicator tests */ if (!comm_rank) { dprintf("\n\n==========================================================\n"); dprintf(" Randomized Communicator\n"); dprintf("==========================================================\n"); } MPI_Comm_split(MPI_COMM_WORLD, 0, rand(), &comm); comm_tests(comm); MPI_Comm_free(&comm); free(sbuf); free(rbuf); free(recvcounts); free(displs); fn_exit: MTest_Finalize(errs); return MTestReturnValue(errs); }
int main(int argc, char ** argv) { int comm_size, comm_rank; MPI_Comm comm; MTest_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &comm_size); MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank); if (LARGE_BUF * comm_size > MAX_BUF) goto fn_exit; SMPI_VARGET_GLOBAL(sbuf) = (void *) calloc(MAX_BUF, 1); SMPI_VARGET_GLOBAL(rbuf) = (void *) calloc(MAX_BUF, 1); srand(time(NULL)); SMPI_VARGET_GLOBAL(recvcounts) = (void *) malloc(comm_size * sizeof(int)); SMPI_VARGET_GLOBAL(displs) = (void *) malloc(comm_size * sizeof(int)); if (!SMPI_VARGET_GLOBAL(recvcounts) || !SMPI_VARGET_GLOBAL(displs) || !SMPI_VARGET_GLOBAL(sbuf) || !SMPI_VARGET_GLOBAL(rbuf)) { fprintf(stderr, "Unable to allocate memory:\n"); if (!SMPI_VARGET_GLOBAL(sbuf)) fprintf(stderr,"\tsbuf of %d bytes\n", MAX_BUF ); if (!SMPI_VARGET_GLOBAL(rbuf)) fprintf(stderr,"\trbuf of %d bytes\n", MAX_BUF ); if (!SMPI_VARGET_GLOBAL(recvcounts)) fprintf(stderr,"\trecvcounts of %zu bytes\n", comm_size * sizeof(int)); if (!SMPI_VARGET_GLOBAL(displs)) fprintf(stderr,"\tdispls of %zu bytes\n", comm_size * sizeof(int)); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); exit(-1); } if (!comm_rank) { dprintf("Message Range: (%d, %d); System size: %d\n", START_BUF, LARGE_BUF, comm_size); fflush(stdout); } /* COMM_WORLD tests */ if (!comm_rank) { dprintf("\n\n==========================================================\n"); dprintf(" MPI_COMM_WORLD\n"); dprintf("==========================================================\n"); } comm_tests(MPI_COMM_WORLD); /* non-COMM_WORLD tests */ if (!comm_rank) { dprintf("\n\n==========================================================\n"); dprintf(" non-COMM_WORLD\n"); dprintf("==========================================================\n"); } MPI_Comm_split(MPI_COMM_WORLD, (comm_rank == comm_size - 1) ? 0 : 1, 0, &comm); if (comm_rank < comm_size - 1) comm_tests(comm); MPI_Comm_free(&comm); /* Randomized communicator tests */ if (!comm_rank) { dprintf("\n\n==========================================================\n"); dprintf(" Randomized Communicator\n"); dprintf("==========================================================\n"); } MPI_Comm_split(MPI_COMM_WORLD, 0, rand(), &comm); comm_tests(comm); MPI_Comm_free(&comm); //free(SMPI_VARGET_GLOBAL(sbuf)); //free(SMPI_VARGET_GLOBAL(rbuf)); free(SMPI_VARGET_GLOBAL(recvcounts)); free(SMPI_VARGET_GLOBAL(displs)); fn_exit: MTest_Finalize(SMPI_VARGET_GLOBAL(errs)); MPI_Finalize(); return 0; }