Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / context / commnames.c
1 /*
2  * Check that we can put names on communicators and get them back.
3  */
4
5 #include <stdio.h>
6
7 #include "mpi.h"
8
9 #if defined(NEEDS_STDLIB_PROTOTYPES)
10 #include "protofix.h"
11 #endif
12
13 int main( int argc, char **argv )
14 {
15   char commName [MPI_MAX_NAME_STRING+1];
16   int namelen;
17
18   MPI_Init( &argc, &argv );
19   
20   if (MPI_Comm_get_name(MPI_COMM_WORLD, commName, &namelen) != MPI_SUCCESS)
21     {
22       printf("Failed to get a name from COMM_WORLD\n");
23       MPI_Abort(MPI_COMM_WORLD, -1);
24     }
25
26   if (strcmp("MPI_COMM_WORLD", commName))
27     {
28       printf("Name on MPI_COMM_WORLD is \"%s\" should be \"MPI_COMM_WORLD\"\n", commName);
29       MPI_Abort(MPI_COMM_WORLD, -1);
30     }
31   
32   if (namelen != strlen (commName))
33     {
34       printf("Length of name on MPI_COMM_WORLD is %d should be %d\n", 
35              namelen, (int) strlen(commName)); 
36       MPI_Abort(MPI_COMM_WORLD, -1);
37     }
38
39   /* Check that we can replace it */
40   if (MPI_Comm_set_name(MPI_COMM_WORLD,"foobar") != MPI_SUCCESS)
41     {
42       printf("Failed to put a name onto COMM_WORLD\n");
43       MPI_Abort(MPI_COMM_WORLD, -1);
44     }
45
46   if (MPI_Comm_get_name(MPI_COMM_WORLD, commName, &namelen) != MPI_SUCCESS)
47     {
48       printf("Failed to get a name from COMM_WORLD after changing it\n");
49       MPI_Abort(MPI_COMM_WORLD, -1);
50     }
51
52   if (strcmp("foobar", commName))
53     {
54       printf("Name on MPI_COMM_WORLD is \"%s\" should be \"foobar\"\n", 
55              commName );
56       MPI_Abort(MPI_COMM_WORLD, -1);
57     }
58
59   printf("Name tests OK\n");
60   MPI_Finalize();
61   return 0;
62 }