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.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.c,v 1.3 2003/01/13 18:31:48 bronis 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 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   char processor_name[128];
36   int namelen = 128;
37   int buf0[buf_size];
38   int buf1[buf_size];
39   MPI_Request req, req0, req1;
40   MPI_Status status, status0, status1;
41
42   /* init */
43   MPI_Init (&argc, &argv);
44   MPI_Comm_size (MPI_COMM_WORLD, &nprocs);
45   MPI_Comm_rank (MPI_COMM_WORLD, &rank);
46   MPI_Get_processor_name (processor_name, &namelen);
47   printf ("(%d) is alive on %s\n", rank, processor_name);
48   fflush (stdout);
49
50   memset (buf0, 1, buf_size*sizeof(int));
51   memset (buf1, 2, buf_size*sizeof(int));
52
53   MPI_Barrier(MPI_COMM_WORLD);
54
55   /* 0 sends 1 two messages, but the request gets overwritten */
56   switch (rank)
57     {
58     case 0:
59       MPI_Isend (buf0, buf_size, MPI_INT, 1, tag1, MPI_COMM_WORLD, &req0);
60       MPI_Isend (buf1, buf_size, MPI_INT, 1, tag2, MPI_COMM_WORLD, &req1);
61
62       /* do some work here */
63
64       mydelay ();
65       MPI_Wait (&req0, &status0);
66       MPI_Wait (&req1, &status1);
67       break;
68
69     case 1:
70       MPI_Irecv (buf0, buf_size, MPI_INT, 0, tag1, MPI_COMM_WORLD, &req);
71       MPI_Irecv (buf1, buf_size, MPI_INT, 0, tag2, MPI_COMM_WORLD, &req);       /* overwrite req */
72
73       /* do some work here and get confused */
74
75       MPI_Wait (&req, &status);
76       break;
77
78     default:
79       /* do nothing */
80       break;
81     }
82
83   MPI_Finalize ();
84   printf ("(%d) Finished normally\n", rank);
85 }
86
87 /* EOF */