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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
|
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mt_pt2pt_common.h"
enum operation_types { TYPE_ASYNC, TYPE_SYNC };
enum probe_routines { Probe, Iprobe, Mprobe, Improbe };
/* Setup send and recv types */
#ifdef BLOCKINGSEND
#define SEND_TYPE TYPE_SYNC
#else
#define SEND_TYPE TYPE_ASYNC
#endif
#ifdef BLOCKINGRECV
#define RECV_TYPE TYPE_SYNC
#else
#define RECV_TYPE TYPE_ASYNC
#endif
/* Select a probe routine */
#ifdef PROBE
#define PROBE_ROUTINE Probe
#elif defined(IPROBE)
#define PROBE_ROUTINE Iprobe
#elif defined(MPROBE)
#define PROBE_ROUTINE Mprobe
#elif defined(IMPROBE)
#define PROBE_ROUTINE Improbe
#else
#error "No valid probe type specified"
#endif
#define PROBE_ERROR_DUMMY MPI_ERR_DIMS /* Dummy values used for the tests */
#define RECV_ERROR_DUMMY MPI_ERR_TOPOLOGY
int probetest_check_valid_data(const MPI_Message * message, MPI_Status * status, int sender_rank,
int tag);
int probetest_invoke_send(int *buff, int data_count, MPI_Datatype type, int recv_rank,
MPI_Comm comm, int tag, MPI_Request * request);
int probetest_invoke_probe(int sender_rank, int tag, MPI_Comm comm, int *recv_count,
MPI_Datatype type, MPI_Message * message, MPI_Status * status);
int probetest_check_probe_result(int id, int *buff, int send_count, int recv_count,
MPI_Message * message, MPI_Status * status, int sender_rank,
int tag);
int probetest_invoke_recv(int *buff, int recv_count, MPI_Datatype type, int sender_rank, int tag,
MPI_Comm comm, MPI_Message * message, MPI_Status * status);
int probetest_probe_n_recv(int id, int send_count, MPI_Datatype type, int sender_rank,
int *buff, MPI_Comm comm, int tag);
int test_probe_normal(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify);
int test_probe_huge(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify);
int test_probe_nullproc(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify);
MTEST_THREAD_RETURN_TYPE run_test(void *arg);
int probetest_check_valid_data(const MPI_Message * message, MPI_Status * status, int sender_rank,
int tag)
{
int errs = 0;
/* check message matching */
if (PROBE_ROUTINE == Mprobe || PROBE_ROUTINE == Improbe) {
if (sender_rank == MPI_PROC_NULL) {
RECORD_ERROR(*message != MPI_MESSAGE_NULL);
RECORD_ERROR(status->MPI_SOURCE != MPI_PROC_NULL);
RECORD_ERROR(status->MPI_TAG != MPI_ANY_TAG);
RECORD_ERROR(status->MPI_ERROR != RECV_ERROR_DUMMY);
} else {
RECORD_ERROR(*message != MPI_MESSAGE_NULL); /* expect null after recv */
RECORD_ERROR(status->MPI_SOURCE != sender_rank);
RECORD_ERROR(status->MPI_TAG != tag);
RECORD_ERROR(status->MPI_ERROR != RECV_ERROR_DUMMY);
}
}
return errs;
}
int probetest_invoke_send(int *buff, int data_count, MPI_Datatype type, int recv_rank,
MPI_Comm comm, int tag, MPI_Request * request)
{
if (SEND_TYPE == TYPE_SYNC)
SEND_FUN(buff, data_count, type, recv_rank, tag, comm);
else
ISEND_FUN(buff, data_count, type, recv_rank, tag, comm, request);
return 0;
}
int probetest_invoke_probe(int sender_rank, int tag, MPI_Comm comm, int *recv_count,
MPI_Datatype type, MPI_Message * message, MPI_Status * status)
{
int errs = 0;
int flag = 0;
switch (PROBE_ROUTINE) {
case Probe:
MPI_Probe(sender_rank, tag, comm, status);
break;
case Iprobe:
while (!flag) {
MPI_Iprobe(sender_rank, tag, comm, &flag, status);
}
break;
case Mprobe:
MPI_Mprobe(sender_rank, tag, comm, message, status);
break;
case Improbe:
while (!flag) {
RECORD_ERROR(*message != MPI_MESSAGE_NULL);
MPI_Improbe(sender_rank, tag, comm, &flag, message, status);
}
break;
default:
fprintf(stderr, "Probe type not defined \n");
MPI_Abort(MPI_COMM_WORLD, 1);
}
/* Find data count */
MPI_Get_count(status, type, recv_count);
return errs;
}
int probetest_check_probe_result(int id, int *buff, int send_count, int recv_count,
MPI_Message * message, MPI_Status * status, int sender_rank,
int tag)
{
int errs = 0;
if (sender_rank == MPI_PROC_NULL) {
RECORD_ERROR(recv_count != 0); /* expect count 0 for NULL_PROC */
RECORD_ERROR(status->MPI_SOURCE != MPI_PROC_NULL);
RECORD_ERROR(status->MPI_TAG != MPI_ANY_TAG);
RECORD_ERROR(*message != MPI_MESSAGE_NULL);
} else {
RECORD_ERROR(recv_count != send_count);
RECORD_ERROR(status->MPI_SOURCE != sender_rank);
RECORD_ERROR(status->MPI_TAG != tag);
}
if (PROBE_ROUTINE == Mprobe || PROBE_ROUTINE == Improbe)
RECORD_ERROR(*message == MPI_MESSAGE_NULL);
RECORD_ERROR(status->MPI_ERROR != PROBE_ERROR_DUMMY);
return errs;
}
int probetest_invoke_recv(int *buff, int recv_count, MPI_Datatype type, int sender_rank, int tag,
MPI_Comm comm, MPI_Message * message, MPI_Status * status)
{
if (PROBE_ROUTINE == Probe || PROBE_ROUTINE == Iprobe) {
if (RECV_TYPE == TYPE_SYNC) {
MPI_Recv(buff, recv_count, type, sender_rank, tag, comm, MPI_STATUS_IGNORE);
} else {
MPI_Request request;
MPI_Irecv(buff, recv_count, type, sender_rank, tag, comm, &request);
MPI_Wait(&request, status);
}
} else { /* for Mprobe or Improbe */
if (RECV_TYPE == TYPE_SYNC) {
MPI_Mrecv(buff, recv_count, type, message, status);
} else {
MPI_Request request;
MPI_Imrecv(buff, recv_count, type, message, &request);
MPI_Wait(&request, status);
}
}
return 0;
}
int probetest_probe_n_recv(int id, int send_count, MPI_Datatype type, int sender_rank,
int *buff, MPI_Comm comm, int tag)
{
int errs = 0;
/* initialize data before recv */
int recv_count = -1;
MPI_Message message = MPI_MESSAGE_NULL;
MPI_Status status, status2;
status.MPI_ERROR = PROBE_ERROR_DUMMY;
status2.MPI_ERROR = RECV_ERROR_DUMMY;
/* call a probe routine */
errs += probetest_invoke_probe(sender_rank, tag, comm, &recv_count, type, &message, &status);
/* call a recv routine */
errs +=
probetest_invoke_recv(buff, recv_count, type, sender_rank, tag, comm, &message, &status2);
/* check received results */
errs += probetest_check_valid_data(&message, &status2, sender_rank, tag);
return errs;
}
int test_probe_normal(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) { /* sender */
MPI_Request *requests = malloc(sizeof(MPI_Request) * iter);
for (i = 0; i < iter; i++) {
buff[i] = SETVAL(i, id);
errs = probetest_invoke_send(&buff[i], 1, type, 1, comm, tag, &requests[i]);
}
if (SEND_TYPE == TYPE_ASYNC)
MPI_Waitall(iter, requests, MPI_STATUSES_IGNORE);
free(requests);
} else { /* receiver */
/* Run tests multiple times */
for (i = 0; i < iter; i++) {
/* Use sender rank 0 and buffer buff[i] */
buff[i] = -1;
errs += probetest_probe_n_recv(id, 1, type, 0 /* sender */ , &buff[i], comm, tag);
if (verify && 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);
}
return errs;
}
int test_probe_huge(int id, int iter, int count, int *buff, MPI_Comm comm, int tag, int verify)
{
int errs = 0, rank;
MPI_Datatype type = MPI_INT;
MPI_Comm_rank(comm, &rank);
/* Make sure all threads have launched */
MTest_thread_barrier(NTHREADS);
if (rank == 0) { /* sender */
MPI_Request request;
for (int i = 0; i < count; i++)
buff[i] = SETVAL(i, id);
for (int i = 0; i < iter; i++) {
errs = probetest_invoke_send(buff, count, type, 1, comm, tag, &request);
/* complete a request before starting another since buff is common across them */
if (SEND_TYPE == TYPE_ASYNC)
MPI_Wait(&request, MPI_STATUS_IGNORE);
}
} else { /* receiver */
/* Run tests multiple times */
for (int i = 0; i < iter; i++) {
for (int j = 0; j < count; j++)
buff[j] = -1;
errs += probetest_probe_n_recv(id, count, type, 0 /* sender_rank */ , buff, comm,
tag);
if (verify) {
for (int 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]);
}
}
}
}
}
fn_exit:
return errs;
}
int test_probe_nullproc(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);
int sender_rank = MPI_PROC_NULL;
/* All ranks recv only */
for (i = 0; i < iter; i++) {
errs = probetest_probe_n_recv(id, count, type, sender_rank, buff, comm, tag);
}
fn_exit:
return errs;
}
MTEST_THREAD_RETURN_TYPE run_test(void *arg)
{
struct thread_param *p = (struct thread_param *) arg;
/* Probe tests */
#if defined(HUGE_COUNT)
p->result = test_probe_huge(p->id, p->iter, p->count, p->buff, p->comm, p->tag, p->verify);
#else
MTestPrintfMsg(2, "Testing probe_normal\n");
p->result = test_probe_normal(p->id, p->iter, p->count, p->buff, p->comm, p->tag, p->verify);
/* Barrier across threads. */
MTest_thread_barrier(NTHREADS);
if (p->id == 0) {
MPI_Barrier(p->comm);
}
MTest_thread_barrier(NTHREADS);
MTestPrintfMsg(2, "Testing probe_nullproc\n");
p->result += test_probe_nullproc(p->id, p->iter, p->count, p->buff, p->comm, p->tag, p->verify);
#endif
return (MTEST_THREAD_RETURN_TYPE) NULL;
}
|