Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / isp / umpire / lost-request-waitall.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Jeffrey Vetter (j-vetter@llnl.gov) Mon Nov  1 1999 */
3 /* lost-request.c -- overwrite a request and essentially lose a synch point */
4
5 #ifndef lint
6 static char *rcsid =
7   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/lost-request-waitall.c,v 1.1.1.1 2000/08/23 17:28:26 vetter Exp $";
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <unistd.h>
13 #include "mpi.h"
14
15 #define buf_size 128
16
17 int mydelay ()                  /* about 6 seconds */
18 {
19   int i;
20   int val;
21   for (i = 0; i < 3000000; i++)
22     {
23       val = getpid ();          /* about 2.06 usecs on snow */
24     }
25   return val;
26 }
27
28 int
29 main (int argc, char **argv)
30 {
31   int nprocs = -1;
32   int rank = -1;
33   int tag1 = 31;
34   int tag2 = 32;
35   MPI_Comm comm = MPI_COMM_WORLD;
36   char processor_name[128];
37   int namelen = 128;
38   int buf0[buf_size];
39   int buf1[buf_size];
40   MPI_Request req, req0, req1;
41   MPI_Status status, status0, status1;
42   MPI_Request areq[10];
43   MPI_Status astatus[10];
44
45   /* init */
46   MPI_Init (&argc, &argv);
47   MPI_Comm_size (comm, &nprocs);
48   MPI_Comm_rank (comm, &rank);
49   MPI_Get_processor_name (processor_name, &namelen);
50   printf ("(%d) is alive on %s\n", rank, processor_name);
51   fflush (stdout);
52
53   memset (buf0, 0, buf_size);
54   memset (buf1, 1, buf_size);
55
56   /* 0 sends 1 two messages, but the request gets overwritten */
57   switch (rank)
58     {
59     case 0:
60       MPI_Isend (buf0, buf_size, MPI_INT, 1, tag1, comm, &(areq[0]));
61       MPI_Isend (buf1, buf_size, MPI_INT, 1, tag2, comm, &(areq[1]));
62       /* do some work here */
63       //mydelay ();
64       MPI_Waitall (2, areq, astatus);
65       break;
66
67     case 1:
68       MPI_Irecv (buf0, buf_size, MPI_INT, 0, tag1, comm, &req);
69       MPI_Irecv (buf1, buf_size, MPI_INT, 0, tag2, comm, &req); /* overwrite req */
70       /* do some work here and get confused */
71       MPI_Wait (&req, &status);
72       break;
73
74     default:
75       /* do nothing */
76       break;
77     }
78
79   MPI_Finalize ();
80   printf ("(%d) Finished normally\n", rank);
81 }
82
83 /* EOF */