Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add new entry in Release_Notes.
[simgrid.git] / teshsuite / smpi / mpich3-test / pt2pt / large_tag.c
1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3  *  (C) 2010 by Argonne National Laboratory.
4  *      See COPYRIGHT in top-level directory.
5  */
6 #include <mpi.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "mpitest.h"
10
11 /* Tests send/receive with large tag values. It mimics the usage of tags in
12  * some MPI-based libraries (e.g., PETSc). */
13
14 #define ITER 5
15 #define BUF_COUNT (16)
16
17 int recvbuf[BUF_COUNT], sendbuf[BUF_COUNT];
18
19 int main(int argc, char *argv[])
20 {
21     int x, size, rank, errs = 0;
22     void *tag_ub_val = NULL;
23     int tag = 0, flag = 0;
24
25     MTest_Init(&argc, &argv);
26
27     MPI_Comm_size(MPI_COMM_WORLD, &size);
28     MPI_Comm_rank(MPI_COMM_WORLD, &rank);
29
30     /* perform test only with two or more processes */
31     if (size < 2)
32         goto exit;
33
34     /* query the upper bound of tag value */
35     MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &tag_ub_val, &flag);
36     tag = *(int *) tag_ub_val;
37     if (!flag || tag < 32767) {
38         fprintf(stdout, "%d -- Incorrect MPI_TAG_UB, found flag=%d, tag=%d\n", rank, flag, tag);
39         fflush(stdout);
40         errs++;
41         goto exit;
42     }
43
44     /* send/receive with large tags from the upper bound */
45     for (x = 0; x < ITER; x++) {
46         int i;
47
48         if (rank == 0) {
49             /* reset send buffer */
50             for (i = 0; i < BUF_COUNT; i++)
51                 sendbuf[i] = x * BUF_COUNT + i;
52
53             MPI_Send(sendbuf, BUF_COUNT, MPI_INT, 1, tag, MPI_COMM_WORLD);
54         } else if (rank == 1) {
55             MPI_Recv(recvbuf, BUF_COUNT, MPI_INT, 0, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
56
57             /* check correctness of received data */
58             for (i = 0; i < BUF_COUNT; i++) {
59                 int expected_val = x * BUF_COUNT + i;
60                 if (recvbuf[i] != expected_val) {
61                     errs++;
62                     fprintf(stdout, "%d -- Received %d at index %d with tag %d, expected %d\n",
63                             rank, recvbuf[i], i, tag, expected_val);
64                     fflush(stdout);
65                 }
66             }
67         }
68         tag--;
69     }
70
71   exit:
72     MTest_Finalize(errs);
73
74     return MTestReturnValue(errs);
75 }