X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/69e6c3b1ce23f7f750cc5f2cd416ff60296a1dcb..a286e57018d2ef03257affb9fe1e73e0b8d08a3d:/teshsuite/smpi/mpich-test/topol/graphtest.c diff --git a/teshsuite/smpi/mpich-test/topol/graphtest.c b/teshsuite/smpi/mpich-test/topol/graphtest.c new file mode 100644 index 0000000000..ee60559116 --- /dev/null +++ b/teshsuite/smpi/mpich-test/topol/graphtest.c @@ -0,0 +1,234 @@ +/* + + Test for the MPI Graph routines : + + MPI_Graphdims_get + MPI_Graph_create + MPI_Graph_get + MPI_Graph_map + MPI_Graph_neighbors + MPI_Graph_neighbors_count +*/ + + +#include "mpi.h" +#include +/* stdlib.h Needed for malloc declaration */ +#include +#include "test.h" + +void NumberEdges ( int **, int **, int, int, int ); +void PrintGraph ( int, int *, int * ); + +int main( int argc, char **argv ) +{ + MPI_Comm comm, new_comm; + int reorder; + int nbrarray[3], baseindex; + int size, i, j, nnodes, nedges, q_nnodes, q_nedges, q_nnbrs, newrank; + int *index, *edges, *q_index, *q_edges, *rankbuf; + int worldrank, err = 0, toterr; + + MPI_Init( &argc, &argv ); + + MPI_Comm_rank( MPI_COMM_WORLD, &worldrank ); + +/* Generate the graph for a binary tree. + + Note that EVERY process must have the SAME data + */ + comm = MPI_COMM_WORLD; + MPI_Comm_size( comm, &size ); + + index = (int *)malloc( (size + 1) * sizeof(int) ); + edges = (int *)malloc( (size + 1) * 3 * sizeof(int) ); + reorder = 0; + for (i=0; i < size; i++) { + index[i] = 0; + } + NumberEdges( &index, &edges, -1, 0, size - 1 ); + nedges= index[0]; + for (i=1; i 0) ? index[i-1] : 0; + for (j=0; j= size) { + err++; + printf( "Rank %d missing in graph_map\n", i ); + } + } + + MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); + if (worldrank == 0) { + if (toterr == 0) + printf( "No errors in MPI Graph routines\n" ); + else + printf( "Found %d errors in MPI Graph routines\n", toterr ); + } + + MPI_Comm_free( &new_comm ); + free( index ); + free( edges ); + free( q_index ); + free( q_edges ); + free( rankbuf ); + MPI_Finalize( ); + return 0; +} + +/* + * Routine to print out a graph for debugging + */ +void PrintGraph( nnodes, index, edges ) +int nnodes, *index, *edges; +{ + int i, lastidx, j; + lastidx=0; + printf( "rank\tindex\tedges\n" ); + for (i=0; i= 0) { +#ifdef DEBUG + printf( "Adding parent %d to %d\n", parent, first ); +#endif + *index = *index + 1; + *edges++ = parent; + } + if (first >= last) { + /* leaf */ + index++; + if (parent >= 0) { + *Index = index; + *Edges = edges; + } + return; + } + +/* Internal node. Always at least a left child */ +#ifdef DEBUG + printf( "Adding left child %d to %d\n", first + 1, first ); +#endif + *index = *index + 1; + *edges++ = first + 1; + +/* Try to add a right child */ + right = (last - first)/2; + right = first + right + 1; + if (right == first + 1) + right++; + if (right <= last) { + /* right child */ +#ifdef DEBUG + printf( "Adding rightchild %d to %d\n", right, first ); +#endif + *index = *index + 1; + *edges++ = right; + } + index++; + if (first + 1 <= last && right - 1 > first) { + NumberEdges( &index, &edges, first, first + 1, + (right <= last) ? right - 1: last ); + } + if (right <= last) { + NumberEdges( &index, &edges, first, right, last ); + } + if (parent >= 0) { + *Index = index; + *Edges = edges; + } +}