/* -*- Mode: c -*- $Id: Small_Msg,v 1.1 1999/10/19 18:38:39 wgeorge Exp $ This script sends 1 small message from each process to every other process. (Also see "Small Msgs" script) */ { int i; int my_rank; int status[3]; int num_errors; int nprocs; int test_status; MPI_Comm_size(MPI_COMM_WORLD, nprocs); MPI_Comm_rank(MPI_COMM_WORLD, my_rank); if (nprocs <= 1) { report_info ("More than one process required for execution."); report_indeterminate ( "Unable to determine test success or failure."); return; } num_errors = 0; int num_outer; int num_inner1; int num_inner2; int ji1; int ji2; int jo; num_outer = 1; num_inner1 = 1; int i_rbuf; int i_sbuf; i_sbuf = my_rank * 3; /* Each rank sends to and receives every other rank. */ for (jo = 0; jo < num_outer; jo=jo+1) { printf ("Iteration %.0f of %.0f . . .\n", (jo+1), num_outer); for (i = 0; i < nprocs; i=i+1) { if (my_rank < i) { /* If i indicates a rank higher than mine, recv then send. */ for (ji1 = 0; ji1 < num_inner1; ji1=ji1+1) { MPI_Recv (i_rbuf, 1, MPI_INT, i, 2*i, MPI_COMM_WORLD, status); if (i_rbuf != (jo + (num_outer*ji1))*nprocs + i) { report_error ( "Expected %.0f, recved %.0f from process %.0f.", i*3, i_rbuf, i); num_errors = num_errors + 1; } i_sbuf = (jo + (num_outer*ji1))*nprocs + my_rank; MPI_Send (i_sbuf, 1, MPI_INT, i, 2*my_rank, MPI_COMM_WORLD); } } else if (my_rank > i) { /* If i indicates a rank lower than mine, send then recv. */ for (ji1 = 0; ji1 < num_inner1; ji1=ji1+1) { i_sbuf = (jo + (num_outer*ji1))*nprocs + my_rank; MPI_Send (i_sbuf, 1, MPI_INT, i, 2*my_rank, MPI_COMM_WORLD); MPI_Recv (i_rbuf, 1, MPI_INT, i, 2*i, MPI_COMM_WORLD, status); if (i_rbuf != (jo + (num_outer*ji1))*nprocs + i) { report_error ( "Expected %.0f, recved %.0f from process %.0f.", i*3, i_rbuf, i); num_errors = num_errors + 1; } } } } } if (num_errors == 0) { report_pass ("Small Msgs: Test succeeded in rank %.0f; no errors detected.", my_rank); } else { report_fail ( "Small Msgs: Test failed in rank %.0f with %.0f errors.", my_rank, num_errors); } return; }