Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7244ec4a2c2c00918bd6860ae09033c11229eb3d
[simgrid.git] / teshsuite / smpi / pt2pt-dsend / pt2pt-dsend.c
1 /* Copyright (c) 2011-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* This program simply does a very small exchange to test whether using SIMIX dsend to model the eager mode works */
8
9 #include <stdio.h>
10 #include <mpi.h>
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(dsend,"the dsend test");
13
14 int main(int argc, char *argv[]) {
15   int rank;
16   int data=11;
17
18   MPI_Init(&argc, &argv);
19   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20   MPI_Request r;
21   if (rank==1) {
22     data=22;
23     MPI_Send(&data,1,MPI_BYTE,(rank+1)%2,666,MPI_COMM_WORLD);
24   } else {
25     MPI_Recv(&data,1,MPI_BYTE,MPI_ANY_SOURCE,666,MPI_COMM_WORLD,NULL);
26     if (data !=22) {
27       printf("rank %d: Damn, data does not match (got %d)\n",rank, data);
28     }
29   }
30
31   if (rank==1) {
32     data=22;
33     MPI_Isend(&data,1,MPI_BYTE,(rank+1)%2,666,MPI_COMM_WORLD, &r);
34     MPI_Wait(&r, MPI_STATUS_IGNORE);
35   } else {
36     MPI_Irecv(&data,1,MPI_BYTE,MPI_ANY_SOURCE,666,MPI_COMM_WORLD,&r);
37     MPI_Wait(&r, MPI_STATUS_IGNORE);
38     if (data !=22) {
39       printf("rank %d: Damn, data does not match (got %d)\n",rank, data);
40     }
41   }
42
43
44   XBT_INFO("rank %d: data exchanged", rank);
45   MPI_Finalize();
46   return 0;
47 }