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

« back to all changes in this revision

Viewing changes to teshsuite/smpi/mpich-test/pt2pt/probe1.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
/* 
 
2
   This is a test of probe to receive a message of unknown type (used as a
 
3
   server)
 
4
 */
 
5
#include <stdio.h>
 
6
#include <string.h>
 
7
#include "mpi.h"
 
8
#include "test.h"
 
9
 
 
10
int main( int argc, char **argv ) 
 
11
{
 
12
int data, to, from, tag, maxlen, np, myid, flag, dest, src;
 
13
MPI_Status status, status1;
 
14
 
 
15
MPI_Init( &argc, &argv );
 
16
MPI_Comm_rank( MPI_COMM_WORLD, &myid );
 
17
MPI_Comm_size( MPI_COMM_WORLD, &np );
 
18
 
 
19
/* dest writes out the received stats; for the output to be
 
20
   consistant (with the final check), it should be procees 0 */
 
21
if (argc > 1 && argv[1] && strcmp( "-alt", argv[1] ) == 0) {
 
22
    dest = np - 1;
 
23
    src  = 0;
 
24
    }
 
25
else {
 
26
    src  = np - 1;
 
27
    dest = 0;
 
28
    }
 
29
 
 
30
if (myid == src) {
 
31
    to   = dest;
 
32
    tag = 2000;
 
33
#ifdef VERBOSE
 
34
    printf( "About to send\n" );
 
35
#endif
 
36
    MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
 
37
    tag = 2001;
 
38
#ifdef VERBOSE
 
39
    printf( "About to send 'done'\n" );
 
40
#endif
 
41
    MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
 
42
    }
 
43
else {
 
44
    /* Server loop */
 
45
    while (1) {
 
46
        tag    = MPI_ANY_TAG;
 
47
        from   = MPI_ANY_SOURCE;
 
48
        /* Should really use MPI_Probe, but functionally this will work
 
49
           (it is less efficient, however) */
 
50
        do {            
 
51
            MPI_Iprobe( from, tag, MPI_COMM_WORLD, &flag, &status );
 
52
            } while (!flag);
 
53
        if (status.MPI_TAG == 2001) {
 
54
#ifdef VERBOSE
 
55
            printf( "Received terminate message\n" );
 
56
#endif
 
57
            /* Actually need to receive it ... */
 
58
            MPI_Recv( &data, 1, MPI_INT, status.MPI_SOURCE, 
 
59
                      status.MPI_TAG, MPI_COMM_WORLD, &status1 );
 
60
            break;
 
61
            }
 
62
        if (status.MPI_TAG == 2000) {
 
63
            MPI_Get_count( &status, MPI_INT, &maxlen );
 
64
            if (maxlen > 1)
 
65
                printf( "Error; size = %d\n", maxlen );
 
66
#ifdef VERBOSE
 
67
            printf( "About to receive\n" );
 
68
#endif
 
69
            MPI_Recv( &data, 1, MPI_INT, status.MPI_SOURCE, 
 
70
                      status.MPI_TAG, MPI_COMM_WORLD, &status1 );
 
71
            }
 
72
        }
 
73
    }
 
74
MPI_Barrier( MPI_COMM_WORLD );
 
75
Test_Waitforall( );
 
76
MPI_Finalize();
 
77
return 0;
 
78
}