File: large_tag.c

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (75 lines) | stat: -rw-r--r-- 2,094 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"

/* Tests send/receive with large tag values. It mimics the usage of tags in
 * some MPI-based libraries (e.g., PETSc). */

#define ITER 5
#define BUF_COUNT (16)

int recvbuf[BUF_COUNT], sendbuf[BUF_COUNT];

int main(int argc, char *argv[])
{
    int x, size, rank, errs = 0;
    void *tag_ub_val = NULL;
    int tag = 0, flag = 0;

    MTest_Init(&argc, &argv);

    MPI_Comm_size(MPI_COMM_WORLD, &size);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    /* perform test only with two or more processes */
    if (size < 2)
        goto exit;

    /* query the upper bound of tag value */
    MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_TAG_UB, &tag_ub_val, &flag);
    tag = *(int *) tag_ub_val;
    if (!flag || tag < 32767) {
        fprintf(stdout, "%d -- Incorrect MPI_TAG_UB, found flag=%d, tag=%d\n", rank, flag, tag);
        fflush(stdout);
        errs++;
        goto exit;
    }

    /* send/receive with large tags from the upper bound */
    for (x = 0; x < ITER; x++) {
        int i;

        if (rank == 0) {
            /* reset send buffer */
            for (i = 0; i < BUF_COUNT; i++)
                sendbuf[i] = x * BUF_COUNT + i;

            MPI_Send(sendbuf, BUF_COUNT, MPI_INT, 1, tag, MPI_COMM_WORLD);
        } else if (rank == 1) {
            MPI_Recv(recvbuf, BUF_COUNT, MPI_INT, 0, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);

            /* check correctness of received data */
            for (i = 0; i < BUF_COUNT; i++) {
                int expected_val = x * BUF_COUNT + i;
                if (recvbuf[i] != expected_val) {
                    errs++;
                    fprintf(stdout, "%d -- Received %d at index %d with tag %d, expected %d\n",
                            rank, recvbuf[i], i, tag, expected_val);
                    fflush(stdout);
                }
            }
        }
        tag--;
    }

  exit:
    MTest_Finalize(errs);

    return MTestReturnValue(errs);
}