~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to teshsuite/smpi/mpich-test/pt2pt/issend2.c

  • Committer: Package Import Robot
  • Author(s): Martin Quinson
  • Date: 2013-01-31 00:24:51 UTC
  • mfrom: (10.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20130131002451-krejhf7w7h24lpsc
Tags: 3.9~rc1-1
* New upstream release: the "Grasgory" release. Major changes:
  - Gras was completely removed from this version.
  - Documentation reorganization to ease browsing it.
  - New default value for the TCP_gamma parameter: 4MiB

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; c-basic-offset:4 ; -*- */
 
2
/* This program comes from Bert Still, bert@h4p.llnl.gov 
 
3
   It caused problems for the T3D implementation.
 
4
 */
 
5
#include <stdio.h>
 
6
#include "mpi.h"
 
7
#include "test.h"
 
8
 
 
9
#define MESSAGE_TAG 8
 
10
#define MESSAGE_VALUE 6
 
11
#define MESSAGE_TYPE MPI_BYTE
 
12
#define MESSAGE_CTYPE char
 
13
static MESSAGE_CTYPE recv_msg[8];
 
14
static MESSAGE_CTYPE send_msg[8];
 
15
 
 
16
static MPI_Status recv_status;
 
17
static MPI_Status send_status[2];
 
18
static MPI_Request request[2];
 
19
static int complete[2];
 
20
 
 
21
/*------------------------------------------------------------------------*/
 
22
 
 
23
void fatal ( int,const char * );
 
24
 
 
25
void fatal(rank, msg)
 
26
int rank;
 
27
const char *msg;
 
28
{
 
29
  printf("***FATAL** rank %d: %s\n", rank, msg);
 
30
  MPI_Abort(MPI_COMM_WORLD, 1);
 
31
  exit(1);
 
32
}
 
33
 
 
34
int verbose = 0;
 
35
int main( int argc, char *argv[] )
 
36
{
 
37
  int size, rank;
 
38
  int err=0, toterr;
 
39
 
 
40
  if (MPI_Init(&argc, &argv)!=MPI_SUCCESS) fatal(-1, "MPI_Init failed");
 
41
 
 
42
  if (MPI_Comm_size(MPI_COMM_WORLD, &size)!=MPI_SUCCESS)
 
43
    fatal(-1, "MPI_Comm_size failed");
 
44
  if (MPI_Comm_rank(MPI_COMM_WORLD, &rank)!=MPI_SUCCESS)
 
45
    fatal(-1, "MPI_Comm_rank failed");
 
46
  if (size!=2) fatal(rank, "issend2 test requires -np 2\n");
 
47
 
 
48
  if (rank) {
 
49
    if (MPI_Probe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD,
 
50
                  &recv_status)!=MPI_SUCCESS)
 
51
      fatal(rank, "MPI_Probe failed");
 
52
    if (recv_status.MPI_SOURCE!=0 || recv_status.MPI_TAG!=MESSAGE_TAG)
 
53
      fatal(rank, "message source or tag wrong");
 
54
    if (MPI_Recv(recv_msg, 8, MESSAGE_TYPE,
 
55
                 recv_status.MPI_SOURCE, recv_status.MPI_TAG, MPI_COMM_WORLD,
 
56
                 &recv_status)!=MPI_SUCCESS)
 
57
      fatal(rank, "MPI_Recv failed");
 
58
    if (recv_msg[0] == MESSAGE_VALUE) {
 
59
        if (verbose) printf( "test completed successfully\n" );
 
60
    }
 
61
    else {
 
62
        printf("test failed: rank %d: got %d but expected %d\n", 
 
63
               rank, recv_msg[0], MESSAGE_VALUE );
 
64
        err++;
 
65
    }
 
66
 
 
67
    fflush(stdout);
 
68
 
 
69
    if (recv_msg[0]!=MESSAGE_VALUE)
 
70
      fatal(rank, "received message doesn't match sent message");
 
71
 
 
72
  } else {
 
73
    int n_complete;
 
74
 
 
75
    send_msg[0]= MESSAGE_VALUE;
 
76
 
 
77
    if (MPI_Issend(send_msg, 1, MESSAGE_TYPE, /*rank*/1, MESSAGE_TAG,
 
78
                   MPI_COMM_WORLD, request) != MPI_SUCCESS)
 
79
          fatal(rank, "MPI_Issend failed");
 
80
    if (MPI_Waitsome(1, request, &n_complete, complete,send_status) != 
 
81
        MPI_SUCCESS) 
 
82
        fatal(rank, "MPI_Waitsome failed");
 
83
    if (request[0]!=MPI_REQUEST_NULL || n_complete!=1 || complete[0]!=0) 
 
84
        fatal(rank, "Waitsome result is wrong");
 
85
  }
 
86
 
 
87
  MPI_Allreduce( &err, &toterr, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
 
88
  if (rank == 0) {
 
89
      if (toterr == 0) {
 
90
          printf( " No Errors\n" );
 
91
      }
 
92
      else {
 
93
          printf (" Found %d errors\n", toterr );
 
94
      }
 
95
  }
 
96
  /* printf("rank %d: about to finalize\n", rank); */
 
97
  fflush(stdout);
 
98
  MPI_Finalize();
 
99
  /*  printf("rank %d: finalize completed\n", rank); */
 
100
  fflush(stdout);
 
101
  return 0;
 
102
}