Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce the size of partial shared malloc tests.
[simgrid.git] / teshsuite / smpi / mpich3-test / comm / dup.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *
4  *  (C) 2003 by Argonne National Laboratory.
5  *      See COPYRIGHT in top-level directory.
6  */
7 #include "mpi.h"
8 #include <stdio.h>
9 #include "mpitest.h"
10
11 int main(int argc, char **argv)
12 {
13     int errs = 0;
14     int rank, size, wrank, wsize, dest, a, b;
15     MPI_Comm newcomm;
16     MPI_Status status;
17
18     MTest_Init(&argc, &argv);
19
20     /* Can we run comm dup at all? */
21     MPI_Comm_dup(MPI_COMM_WORLD, &newcomm);
22
23     /* Check basic properties */
24     MPI_Comm_size(MPI_COMM_WORLD, &wsize);
25     MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
26     MPI_Comm_size(newcomm, &size);
27     MPI_Comm_rank(newcomm, &rank);
28
29     if (size != wsize || rank != wrank) {
30         errs++;
31         fprintf(stderr, "Size (%d) or rank (%d) wrong\n", size, rank);
32         fflush(stderr);
33     }
34
35     /* Can we communicate with this new communicator? */
36     dest = MPI_PROC_NULL;
37     if (rank == 0) {
38         dest = size - 1;
39         a = rank;
40         b = -1;
41         MPI_Sendrecv(&a, 1, MPI_INT, dest, 0, &b, 1, MPI_INT, dest, 0, newcomm, &status);
42         if (b != dest) {
43             errs++;
44             fprintf(stderr, "Received %d expected %d on %d\n", b, dest, rank);
45             fflush(stderr);
46         }
47         if (status.MPI_SOURCE != dest) {
48             errs++;
49             fprintf(stderr, "Source not set correctly in status on %d\n", rank);
50             fflush(stderr);
51         }
52     }
53     else if (rank == size - 1) {
54         dest = 0;
55         a = rank;
56         b = -1;
57         MPI_Sendrecv(&a, 1, MPI_INT, dest, 0, &b, 1, MPI_INT, dest, 0, newcomm, &status);
58         if (b != dest) {
59             errs++;
60             fprintf(stderr, "Received %d expected %d on %d\n", b, dest, rank);
61             fflush(stderr);
62         }
63         if (status.MPI_SOURCE != dest) {
64             errs++;
65             fprintf(stderr, "Source not set correctly in status on %d\n", rank);
66             fflush(stderr);
67         }
68     }
69
70     MPI_Comm_free(&newcomm);
71
72     MTest_Finalize(errs);
73
74     MPI_Finalize();
75
76     return 0;
77 }