|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2009 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
#include <stdlib.h>
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* style: allow:calloc:1 sig:0 */
|
|
Packit Service |
c5cf8c |
/* style: allow:fprintf:2 sig:0 */
|
|
Packit Service |
c5cf8c |
/* style: allow:printf:2 sig:0 */
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* This program provides a convienient way to test some of the debugger
|
|
Packit Service |
c5cf8c |
* interface functionality, including message queues and named communicators
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define MAX_TARGETS 100
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int provided, wrank, wsize, nmsg, i, tag;
|
|
Packit Service |
c5cf8c |
int *(buf[MAX_TARGETS]), bufsize[MAX_TARGETS];
|
|
Packit Service |
c5cf8c |
MPI_Request r[MAX_TARGETS];
|
|
Packit Service |
c5cf8c |
MPI_Comm commDup, commEven;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &wsize);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
if (wsize < 4) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "This test requires at least 4 processes\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Create several communicators */
|
|
Packit Service |
c5cf8c |
MPI_Comm_dup(MPI_COMM_WORLD, &commDup);
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_name(commDup, "User dup of comm world");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_split(MPI_COMM_WORLD, wrank & 0x1, wrank, &commEven);
|
|
Packit Service |
c5cf8c |
if (wrank & 0x1)
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&commEven);
|
|
Packit Service |
c5cf8c |
else
|
|
Packit Service |
c5cf8c |
MPI_Comm_set_name(commEven, "User split to even ranks");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Create a collection of pending sends and receives
|
|
Packit Service |
c5cf8c |
* We use tags on the sends and receives (when ANY_TAG isn't used)
|
|
Packit Service |
c5cf8c |
* to provide an easy way to check that the proper requests are present.
|
|
Packit Service |
c5cf8c |
* TAG values use fields, in decimal (for easy reading):
|
|
Packit Service |
c5cf8c |
* 0-99: send/recv type:
|
|
Packit Service |
c5cf8c |
* 0 - other
|
|
Packit Service |
c5cf8c |
* 1 - irecv
|
|
Packit Service |
c5cf8c |
* 2 - isend
|
|
Packit Service |
c5cf8c |
* 3 - issend
|
|
Packit Service |
c5cf8c |
* 4 - ibsend
|
|
Packit Service |
c5cf8c |
* 5 - irsend
|
|
Packit Service |
c5cf8c |
* 6 - persistent recv
|
|
Packit Service |
c5cf8c |
* 7 - persistent send
|
|
Packit Service |
c5cf8c |
* 8 - persistent ssend
|
|
Packit Service |
c5cf8c |
* 9 - persistent rsend
|
|
Packit Service |
c5cf8c |
* 10 - persistent bsend
|
|
Packit Service |
c5cf8c |
* 100-999: destination (for send) or source, if receive. 999 = any-source
|
|
Packit Service |
c5cf8c |
* (rank is value/100)
|
|
Packit Service |
c5cf8c |
* 1000-2G: other values
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
/* Create the send/receive buffers */
|
|
Packit Service |
c5cf8c |
nmsg = 10;
|
|
Packit Service |
c5cf8c |
for (i = 0; i < nmsg; i++) {
|
|
Packit Service |
c5cf8c |
bufsize[i] = i;
|
|
Packit Service |
c5cf8c |
if (i) {
|
|
Packit Service |
c5cf8c |
buf[i] = (int *) calloc(bufsize[i], sizeof(int));
|
|
Packit Service |
c5cf8c |
if (!buf[i]) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "Unable to allocate %d words\n", bufsize[i]);
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 2);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
} else
|
|
Packit Service |
c5cf8c |
buf[i] = 0;
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Partial implementation */
|
|
Packit Service |
c5cf8c |
if (wrank == 0) {
|
|
Packit Service |
c5cf8c |
nmsg = 0;
|
|
Packit Service |
c5cf8c |
tag = 2 + 1 * 100;
|
|
Packit Service |
c5cf8c |
MPI_Isend(buf[0], bufsize[0], MPI_INT, 1, tag, MPI_COMM_WORLD, &r[nmsg++]);
|
|
Packit Service |
c5cf8c |
tag = 3 + 2 * 100;
|
|
Packit Service |
c5cf8c |
MPI_Issend(buf[1], bufsize[1], MPI_INT, 2, tag, MPI_COMM_WORLD, &r[nmsg++]);
|
|
Packit Service |
c5cf8c |
tag = 1 + 3 * 100;
|
|
Packit Service |
c5cf8c |
MPI_Irecv(buf[2], bufsize[2], MPI_INT, 3, tag, MPI_COMM_WORLD, &r[nmsg++]);
|
|
Packit Service |
c5cf8c |
} else if (wrank == 1) {
|
|
Packit Service |
c5cf8c |
} else if (wrank == 2) {
|
|
Packit Service |
c5cf8c |
} else if (wrank == 3) {
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* provide a convenient place to wait */
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
printf("Barrier 1 finished\n");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* Match up (or cancel) the requests */
|
|
Packit Service |
c5cf8c |
if (wrank == 0) {
|
|
Packit Service |
c5cf8c |
MPI_Waitall(nmsg, r, MPI_STATUSES_IGNORE);
|
|
Packit Service |
c5cf8c |
} else if (wrank == 1) {
|
|
Packit Service |
c5cf8c |
tag = 2 + 1 * 100;
|
|
Packit Service |
c5cf8c |
MPI_Recv(buf[0], bufsize[0], MPI_INT, 0, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
Packit Service |
c5cf8c |
} else if (wrank == 2) {
|
|
Packit Service |
c5cf8c |
tag = 3 + 2 * 100;
|
|
Packit Service |
c5cf8c |
MPI_Recv(buf[1], bufsize[1], MPI_INT, 0, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
|
|
Packit Service |
c5cf8c |
} else if (wrank == 3) {
|
|
Packit Service |
c5cf8c |
tag = 1 + 3 * 100;
|
|
Packit Service |
c5cf8c |
MPI_Send(buf[2], bufsize[2], MPI_INT, 0, tag, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Barrier(MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
printf("Barrier 2 finished\n");
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&commDup);
|
|
Packit Service |
c5cf8c |
if (commEven != MPI_COMM_NULL)
|
|
Packit Service |
c5cf8c |
MPI_Comm_free(&commEven);
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|