|
Packit Service |
c5cf8c |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit Service |
c5cf8c |
/*
|
|
Packit Service |
c5cf8c |
* (C) 2005 by Argonne National Laboratory.
|
|
Packit Service |
c5cf8c |
* See COPYRIGHT in top-level directory.
|
|
Packit Service |
c5cf8c |
*/
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
/* A very simple program that performs only a send and a receive. This
|
|
Packit Service |
c5cf8c |
program can be use with logging enabled (configure with
|
|
Packit Service |
c5cf8c |
--enable-g=dbg,log) and run with -mpich-dbg-class=routine to get
|
|
Packit Service |
c5cf8c |
a trace of the execution of the functions in MPICH */
|
|
Packit Service |
c5cf8c |
#include <stdio.h>
|
|
Packit Service |
c5cf8c |
#include "mpi.h"
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
#define SENDER_RANK 0
|
|
Packit Service |
c5cf8c |
#define RECEIVER_RANK 1
|
|
Packit Service |
c5cf8c |
int main(int argc, char *argv[])
|
|
Packit Service |
c5cf8c |
{
|
|
Packit Service |
c5cf8c |
int rank, size, val;
|
|
Packit Service |
c5cf8c |
MPI_Status status;
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Init(&argc, &argv);
|
|
Packit Service |
c5cf8c |
MPI_Comm_size(MPI_COMM_WORLD, &size);
|
|
Packit Service |
c5cf8c |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit Service |
c5cf8c |
if (size < 2) {
|
|
Packit Service |
c5cf8c |
fprintf(stderr, "This program requires at least 2 processes\n");
|
|
Packit Service |
c5cf8c |
MPI_Abort(MPI_COMM_WORLD, 1);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
if (rank == SENDER_RANK) {
|
|
Packit Service |
c5cf8c |
MPI_Send(&rank, 1, MPI_INT, RECEIVER_RANK, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
} else if (rank == RECEIVER_RANK) {
|
|
Packit Service |
c5cf8c |
/* This may or may not post the receive before the send arrives */
|
|
Packit Service |
c5cf8c |
MPI_Recv(&val, 1, MPI_INT, SENDER_RANK, 0, MPI_COMM_WORLD, &status);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
/* Perform a second send/receive to allow the first pair to handle
|
|
Packit Service |
c5cf8c |
* any connection logic */
|
|
Packit Service |
c5cf8c |
#if 1
|
|
Packit Service |
c5cf8c |
if (rank == SENDER_RANK) {
|
|
Packit Service |
c5cf8c |
MPI_Send(&rank, 1, MPI_INT, RECEIVER_RANK, 0, MPI_COMM_WORLD);
|
|
Packit Service |
c5cf8c |
} else if (rank == RECEIVER_RANK) {
|
|
Packit Service |
c5cf8c |
/* This may or may not post the receive before the send arrives */
|
|
Packit Service |
c5cf8c |
MPI_Recv(&val, 1, MPI_INT, SENDER_RANK, 0, MPI_COMM_WORLD, &status);
|
|
Packit Service |
c5cf8c |
}
|
|
Packit Service |
c5cf8c |
#endif
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
MPI_Finalize();
|
|
Packit Service |
c5cf8c |
|
|
Packit Service |
c5cf8c |
return 0;
|
|
Packit Service |
c5cf8c |
}
|