File: mt_sendrecv_impl.c

package info (click to toggle)
mpich 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 423,384 kB
  • sloc: ansic: 1,088,434; cpp: 71,364; javascript: 40,763; f90: 22,829; sh: 17,463; perl: 14,773; xml: 14,418; python: 10,265; makefile: 9,246; fortran: 8,008; java: 4,355; asm: 324; ruby: 176; lisp: 19; php: 8; sed: 4
file content (204 lines) | stat: -rw-r--r-- 6,557 bytes parent folder | download | duplicates (3)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * Copyright (C) by Argonne National Laboratory
 *     See COPYRIGHT in top-level directory
 */

#include "mt_pt2pt_common.h"

int test_sendrecv(int id, int iter, int *buff, MPI_Comm comm, int tag, int verify);
int test_sendrecv_huge(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify);
int test_isendirecv(int id, int iter, int *buff, MPI_Comm comm, int tag, int verify);
int test_isendirecv_huge(int id, int iter, int count, int *buff, MPI_Comm comm, int tag,
                         int verify);
MTEST_THREAD_RETURN_TYPE run_test(void *arg);

int test_sendrecv(int id, int iter, int *buff, MPI_Comm comm, int tag, int verify)
{
    int errs = 0, i, rank;
    MPI_Datatype type = MPI_INT;

    MPI_Comm_rank(comm, &rank);

    /* Make sure all threads have launched */
    MTest_thread_barrier(NTHREADS);

    if (rank == 0) {
        for (i = 0; i < iter; i++) {
            buff[i] = SETVAL(i, id);
            SEND_FUN(&buff[i], 1, type, 1, tag, comm);
        }
    } else if (rank == 1) {
        for (i = 0; i < iter; i++) {
            buff[i] = -1;
            MPI_Recv(&buff[i], 1, type, 0, tag, comm, MPI_STATUS_IGNORE);
            if (!verify)
                continue;
            if (buff[i] != SETVAL(i, id)) {
                errs++;
                if (errs <= DATA_WARN_THRESHOLD)
                    fprintf(stderr, "thread %d: Expected %d but got %d\n", id, SETVAL(i, id),
                            buff[i]);
            }
        }
        if (errs > 0)
            fprintf(stderr, "thread %d: %d errors found in received data\n", id, errs);
    }

  fn_exit:
    return errs;
}

int test_sendrecv_huge(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify)
{
    int errs = 0, i, rank;
    MPI_Datatype type = MPI_INT;

    MPI_Comm_rank(comm, &rank);

    /* Make sure all threads have launched */
    MTest_thread_barrier(NTHREADS);

    if (rank == 0) {
        for (i = 0; i < count; i++)
            buff[i] = SETVAL(i, id);
        for (i = 0; i < iter; i++)
            SEND_FUN(buff, count, type, 1, tag, comm);
    } else if (rank == 1) {
        for (i = 0; i < iter; i++) {
            int j;
            for (j = 0; j < count; j++)
                buff[j] = -1;
            MPI_Recv(buff, count, type, 0, tag, comm, MPI_STATUS_IGNORE);
            if (!verify)
                continue;
            for (j = 0; j < count; j++) {
                if (buff[j] != SETVAL(j, id)) {
                    errs++;
                    if (errs <= DATA_WARN_THRESHOLD)
                        fprintf(stderr, "thread %d: Expected %d but got %d\n", id,
                                SETVAL(j, id), buff[j]);
                }
            }
        }
        if (errs > 0)
            fprintf(stderr, "thread %d: %d errors found in received data\n", id, errs);
    }

  fn_exit:
    return errs;
}

int test_isendirecv(int id, int iter, int *buff, MPI_Comm comm, int tag, int verify)
{
    int errs = 0, i, rank;
    MPI_Request *reqs = malloc(sizeof(MPI_Request) * iter);
    MPI_Datatype type = MPI_INT;

    MPI_Comm_rank(comm, &rank);

    /* Make sure all threads have launched */
    MTest_thread_barrier(NTHREADS);

    if (rank == 0) {
        for (i = 0; i < iter; i++) {
            buff[i] = SETVAL(i, id);
            ISEND_FUN(&buff[i], 1, type, 1, tag, comm, &reqs[i]);
        }
        /* MPI_Waitall() could be called from one leader thread instead,
         * but by doing this we can stress MPI_Waitall from multiple threads. */
        MPI_Waitall(iter, reqs, MPI_STATUSES_IGNORE);
    } else if (rank == 1) {
        for (i = 0; i < iter; i++) {
            buff[i] = -1;
            MPI_Irecv(&buff[i], 1, type, 0, tag, comm, &reqs[i]);
        }
        MPI_Waitall(iter, reqs, MPI_STATUSES_IGNORE);
        if (verify) {
            for (i = 0; i < iter; i++) {
                if (buff[i] != SETVAL(i, id)) {
                    errs++;
                    if (errs <= DATA_WARN_THRESHOLD)
                        fprintf(stderr, "thread %d: Expected %d but got %d\n", id, SETVAL(i, id),
                                buff[i]);
                }
            }
        }
        if (errs > 0)
            fprintf(stderr, "thread %d: %d errors found in received data\n", id, errs);

    }

  fn_exit:
    free(reqs);
    return errs;
}

int test_isendirecv_huge(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify)
{
    int errs = 0, i, j, rank;
    MPI_Request req;
    MPI_Datatype type = MPI_INT;

    MPI_Comm_rank(comm, &rank);

    if (rank == 0) {
        for (i = 0; i < count; i++)
            buff[i] = SETVAL(i, id);
    }

    /* Make sure all threads have launched */
    MTest_thread_barrier(NTHREADS);

    if (rank == 0) {
        for (i = 0; i < iter; i++) {
            for (j = 0; j < count; j++)
                buff[i] = SETVAL(i, id);
            ISEND_FUN(buff, count, type, 1, tag, comm, &req);
            MPI_Wait(&req, MPI_STATUS_IGNORE);
        }
    } else if (rank == 1) {
        for (i = 0; i < iter; i++) {
            /* reset recv buffer before every recv. */
            for (j = 0; j < count; j++)
                buff[j] = -1;
            MPI_Irecv(buff, count, type, 0, tag, comm, &req);
            MPI_Wait(&req, MPI_STATUS_IGNORE);
            if (!verify)
                continue;
            for (j = 0; j < count; j++) {
                if (buff[j] != SETVAL(j, id)) {
                    errs++;
                    if (errs <= DATA_WARN_THRESHOLD)
                        fprintf(stderr, "thread %d: Expected %d but got %d\n", id,
                                SETVAL(j, id), buff[j]);
                }
            }
        }
        if (errs > 0)
            fprintf(stderr, "thread %d: %d errors found in received data\n", id, errs);
    }

  fn_exit:
    return errs;
}

MTEST_THREAD_RETURN_TYPE run_test(void *arg)
{
    struct thread_param *p = (struct thread_param *) arg;

    /* Send recv tests  */
#ifdef NONBLOCKING
#if defined(HUGE_COUNT)
    p->result = test_isendirecv_huge(p->id, p->iter, p->count, p->buff, p->comm, p->tag, p->verify);
#else
    p->result = test_isendirecv(p->id, p->iter, p->buff, p->comm, p->tag, p->verify);
#endif
#else /* #ifdef NONBLOCKING */
#if defined(HUGE_COUNT)
    p->result = test_sendrecv_huge(p->id, p->iter, p->count, p->buff, p->comm, p->tag, p->verify);
#else
    p->result = test_sendrecv(p->id, p->iter, p->buff, p->comm, p->tag, p->verify);
#endif
#endif /* #ifdef NONBLOCKING */
    return (MTEST_THREAD_RETURN_TYPE) NULL;
}