1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
3 * (C) 2010 by Argonne National Laboratory.
4 * See COPYRIGHT in top-level directory.
11 /* Tests send/receive with large tag values. It mimics the usage of tags in
12 * some MPI-based libraries (e.g., PETSc). */
15 #define BUF_COUNT (16)
17 int recvbuf[BUF_COUNT], sendbuf[BUF_COUNT];
19 int main(int argc, char *argv[])
21 int x, size, rank, errs = 0;
22 void *tag_ub_val = NULL;
23 int tag = 0, flag = 0;
25 MTest_Init(&argc, &argv);
27 MPI_Comm_size(MPI_COMM_WORLD, &size);
28 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30 /* perform test only with two or more processes */
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);
44 /* send/receive with large tags from the upper bound */
45 for (x = 0; x < ITER; x++) {
49 /* reset send buffer */
50 for (i = 0; i < BUF_COUNT; i++)
51 sendbuf[i] = x * BUF_COUNT + i;
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);
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) {
62 fprintf(stdout, "%d -- Received %d at index %d with tag %d, expected %d\n",
63 rank, recvbuf[i], i, tag, expected_val);
74 return MTestReturnValue(errs);