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