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

« back to all changes in this revision

Viewing changes to teshsuite/smpi/mpich-test/pt2pt/testtest1.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 MPI_Test to receive a message of known length (used as a
 
3
   server)
 
4
 */
 
5
#include "mpi.h"
 
6
#include <stdio.h>
 
7
#include <string.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;
 
14
    MPI_Request request;
 
15
 
 
16
    MPI_Init( &argc, &argv );
 
17
    MPI_Comm_rank( MPI_COMM_WORLD, &myid );
 
18
    MPI_Comm_size( MPI_COMM_WORLD, &np );
 
19
 
 
20
/* dest writes out the received stats; for the output to be
 
21
   consistant (with the final check), it should be procees 0 */
 
22
    if (argc > 1 && argv[1] && strcmp( "-alt", argv[1] ) == 0) {
 
23
        dest = np - 1;
 
24
        src  = 0;
 
25
    }
 
26
    else {
 
27
        src  = np - 1;
 
28
        dest = 0;
 
29
    }
 
30
 
 
31
    if (myid == src) {
 
32
        to   = dest;
 
33
        tag = 2000;
 
34
        data = 100;
 
35
#ifdef VERBOSE
 
36
        printf( "About to send\n" );
 
37
#endif
 
38
        MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
 
39
        tag = 2001;
 
40
        data = 0;
 
41
#ifdef VERBOSE
 
42
        printf( "About to send 'done'\n" );
 
43
#endif
 
44
        MPI_Send( &data, 1, MPI_INT, to, tag, MPI_COMM_WORLD );
 
45
    }
 
46
    else {
 
47
        /* Server loop */
 
48
        while (1) {
 
49
            tag    = MPI_ANY_TAG;
 
50
            from   = MPI_ANY_SOURCE;
 
51
            MPI_Irecv( &data, 1, MPI_INT, from, tag, MPI_COMM_WORLD,
 
52
                       &request );
 
53
            /* Should really use MPI_Wait, but functionally this will work
 
54
               (it is less efficient, however) */
 
55
            do {                
 
56
                MPI_Test( &request, &flag, &status );
 
57
            } while (!flag);
 
58
            if (status.MPI_TAG == 2001) {
 
59
#ifdef VERBOSE
 
60
                printf( "Received terminate message\n" );
 
61
#endif
 
62
                break;
 
63
            }
 
64
            if (status.MPI_TAG == 2000) {
 
65
                MPI_Get_count( &status, MPI_INT, &maxlen );
 
66
                if (maxlen != 1) {
 
67
                    fprintf( stderr, "Should have received one integer; got %d\n",
 
68
                             maxlen );
 
69
                }
 
70
                /* Check data: */
 
71
                if (data != 100) {
 
72
                    fprintf( stderr, 
 
73
                             "Did not receive correct data: %d instead of %d\n", 
 
74
                             data, 100 );
 
75
                }
 
76
            }
 
77
        }
 
78
    }
 
79
    MPI_Barrier( MPI_COMM_WORLD );
 
80
    Test_Waitforall( );
 
81
    MPI_Finalize();
 
82
    return 0;
 
83
}