Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into CRTP
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / commname.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2001 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7
8 #include "mpi.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include "mpitest.h"
12 #include "mpitestconf.h"
13 #ifdef HAVE_STRING_H
14 #include <string.h>
15 #endif
16
17 int main(int argc, char *argv[])
18 {
19     int errs = 0;
20     MPI_Comm comm;
21     int cnt, rlen;
22     char name[MPI_MAX_OBJECT_NAME], nameout[MPI_MAX_OBJECT_NAME];
23     MTest_Init(&argc, &argv);
24
25     /* Check world and self firt */
26     nameout[0] = 0;
27     MPI_Comm_get_name(MPI_COMM_WORLD, nameout, &rlen);
28     if (strcmp(nameout, "MPI_COMM_WORLD")) {
29         errs++;
30         printf("Name of comm world is %s, should be MPI_COMM_WORLD\n", nameout);
31     }
32
33     nameout[0] = 0;
34     MPI_Comm_get_name(MPI_COMM_SELF, nameout, &rlen);
35     if (strcmp(nameout, "MPI_COMM_SELF")) {
36         errs++;
37         printf("Name of comm self is %s, should be MPI_COMM_SELF\n", nameout);
38     }
39
40     /* Now, handle other communicators, including world/self */
41     cnt = 0;
42     while (MTestGetComm(&comm, 1)) {
43         if (comm == MPI_COMM_NULL)
44             continue;
45
46         sprintf(name, "comm-%d", cnt);
47         cnt++;
48         MPI_Comm_set_name(comm, name);
49         nameout[0] = 0;
50         MPI_Comm_get_name(comm, nameout, &rlen);
51         if (strcmp(name, nameout)) {
52             errs++;
53             printf("Unexpected name, was %s but should be %s\n", nameout, name);
54         }
55
56         MTestFreeComm(&comm);
57     }
58
59     MTest_Finalize(errs);
60     MPI_Finalize();
61     return 0;
62 }