00001 #include "TopoManager.h"
00002 #include <stdio.h>
00003 #include <mpi.h>
00004
00005 int main(int argc, char *argv[]) {
00006 int numranks, myrank;
00007 MPI_Init(&argc, &argv);
00008 MPI_Comm_size(MPI_COMM_WORLD, &numranks);
00009 MPI_Comm_rank(MPI_COMM_WORLD, &myrank);
00010 int i, ndims=0, *dims;
00011
00012 TopoManager_init(numranks);
00013 TopoManager_getDimCount(&ndims);
00014 if (ndims <= 0) {
00015 printf("ERROR: Rank %d got negative number of dimensions\n", myrank);
00016 MPI_Finalize();
00017 return 0;
00018 }
00019 dims = (int*)malloc(sizeof(int)*(ndims+1));
00020
00021 if (myrank == 0) {
00022 printf("Testing TopoManager...\n");
00023 printf("MPI Job Size: %d ranks\n\n", numranks);
00024 printf("Machine topology has %d dimensions\n", ndims);
00025
00026 TopoManager_getDims(dims);
00027 printf("Torus Size ");
00028 for (i=0; i < ndims; i++) printf("[%d] ", dims[i]);
00029 printf("\n\n");
00030
00031 FILE *out = fopen("allocationC.txt","w");
00032 TopoManager_printAllocation(out);
00033 fclose(out);
00034 printf("Dumped allocation to allocationC.txt\n");
00035 }
00036
00037 TopoManager_getPeCoordinates(myrank, dims);
00038 printf("---- Rank %d coordinates ---> (", myrank);
00039 for (i=0; i < ndims-1; i++) printf("%d,", dims[i]);
00040 printf("%d)\n", dims[ndims-1]);
00041 int obtained;
00042 TopoManager_getPeRank(&obtained, dims);
00043 if (obtained != myrank)
00044 printf("ERROR: Failure to obtain rank from my coordinates at rank %d!!!\n", myrank);
00045
00046 free(dims);
00047 TopoManager_free();
00048
00049 MPI_Finalize();
00050 return 0;
00051 }