root/test/memchecker/non_blocking_recv_test.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. main

   1 /*
   2  * Copyright (c) 2004-2007 High Performance Computing Center Stuttgart,
   3  *                         University of Stuttgart.  All rights reserved.
   4  * $COPYRIGHT$
   5  *
   6  * Additional copyrights may follow
   7  *
   8  * $HEADER$
   9  */
  10 
  11 #include <stdio.h>
  12 #include "mpi.h"
  13 
  14 int main( int argc, char *argv[] )
  15 {
  16     int rank, size;
  17     int send_value,recv_value;
  18 
  19     MPI_Status status;
  20     MPI_Request send_request;
  21     MPI_Request recv_request;
  22 
  23     MPI_Init( &argc, &argv );
  24 
  25     MPI_Comm_rank( MPI_COMM_WORLD, &rank );
  26     MPI_Comm_size( MPI_COMM_WORLD, &size );
  27 
  28     send_value = 10;
  29     recv_value = 0;
  30 
  31     if (size != 2) {
  32         fprintf (stderr, "Error: Need 2 processes\n");
  33         MPI_Finalize ();
  34     }
  35 
  36     MPI_Isend (&send_value, 1, MPI_INT,
  37                (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request);
  38     MPI_Irecv (&recv_value, 1, MPI_INT,
  39                (rank + size - 1) % size, 4711, MPI_COMM_WORLD, &recv_request);
  40 
  41     /*
  42      * Reading or writing of the receive buffer before
  43      * non blocking send finished will cause an error.
  44      */
  45     printf("\nsent: %d\n",recv_value);
  46     recv_value = 12;
  47 
  48     MPI_Wait (&send_request, &status);
  49     MPI_Wait (&recv_request, &status);
  50     /*
  51      * Using of receive buffer after non blocking send
  52      * is finished will be ok.
  53      */
  54     printf("\nsent: %d\n",recv_value);
  55     recv_value = 16;
  56 
  57     MPI_Finalize ();
  58     return 0;
  59 }

/* [<][>][^][v][top][bottom][index][help] */