Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill all trailling whitespaces
[simgrid.git] / teshsuite / smpi / isp / umpire / no-error-interleaved-isend.c
1 /* -*- Mode: C; -*- */
2 /* Creator: Bronis R. de Supinski (bronis@llnl.gov)  */
3 /* no-error-interleaved-isend.c - use isends with vector type */
4
5 #ifndef lint
6 static char *rcsid =
7   "$Header: /usr/gapps/asde/cvs-vault/umpire/tests/no-error-interleaved-isend.c,v 1.2 2002/06/07 20:41:22 bronis Exp $";
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <assert.h>
13 #include "mpi.h"
14
15 #define buf_size 128
16
17 int
18 main (int argc, char **argv)
19 {
20   int nprocs = -1;
21   int rank = -1;
22   MPI_Comm comm = MPI_COMM_WORLD;
23   char processor_name[128];
24   int namelen = 128;
25   int buf[buf_size];
26   int i;
27   MPI_Request req;
28   MPI_Status status;
29   MPI_Datatype strided_type;
30
31   /* init */
32   MPI_Init (&argc, &argv);
33   MPI_Comm_size (comm, &nprocs);
34   MPI_Comm_rank (comm, &rank);
35   MPI_Get_processor_name (processor_name, &namelen);
36   printf ("(%d) is alive on %s\n", rank, processor_name);
37   fflush (stdout);
38
39   MPI_Type_vector (buf_size/2, 1, 2, MPI_INT, &strided_type);
40   MPI_Type_commit (&strided_type);
41
42   MPI_Barrier(MPI_COMM_WORLD);
43
44   if (rank < 2)
45     {
46       for (i = rank; i < buf_size; i = i + 2)
47         buf[i] = i;
48
49       MPI_Isend (&buf[rank], 1,
50                  strided_type, (rank + 1) % 2, 0, comm, &req);
51
52       MPI_Recv (&buf[(rank + 1) % 2], 1,
53                 strided_type, (rank + 1) % 2, 0, comm, &status);
54
55       MPI_Wait (&req, &status);
56
57       for (i = 0; i < buf_size; i++)
58         assert (buf[i] == i);
59     }
60
61   MPI_Barrier(MPI_COMM_WORLD);
62
63   MPI_Type_free (&strided_type);
64
65   MPI_Finalize ();
66   printf ("(%d) Finished normally\n", rank);
67 }
68
69 /* EOF */