Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / pt2pt-dsend / pt2pt-dsend.c
1 /* Copyright (c) 2011-2019. 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 #include <stdint.h>
9 #include <stdio.h>
10 #include <mpi.h>
11
12 XBT_LOG_NEW_DEFAULT_CATEGORY(dsend,"the dsend test");
13
14 static void test_opts(int* argc, char **argv[]){
15   int found = 0;
16   int option_index = 0;
17   static struct option long_options[] = {
18   {(char*)"long",     no_argument, 0,  0 },
19   {0,         0,                 0,  0 }
20   };
21   while (1) {
22     int ret = getopt_long(*argc, *argv, "s", long_options, &option_index);
23     if(ret==-1)
24       break;
25
26     switch (ret) {
27       case 0:
28         found++;
29       break;
30       case 's':
31         found ++;
32       break;
33       default:
34         printf("option %s", long_options[option_index].name);
35       break;
36     }
37   }
38   if (found!=2){
39     printf("(smpi_)getopt_long failed ! \n");
40   }
41 }
42
43 int main(int argc, char *argv[])
44 {
45   int rank;
46   int32_t data=11;
47
48   MPI_Init(NULL, NULL);
49
50   /* test getopt_long function */
51   test_opts(&argc, &argv);
52
53   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
54   MPI_Request r;
55   if (rank==1) {
56     data=22;
57     MPI_Send(&data,1,MPI_INT32_T,(rank+1)%2,666,MPI_COMM_WORLD);
58   } else {
59     MPI_Recv(&data,1,MPI_INT32_T,MPI_ANY_SOURCE,666,MPI_COMM_WORLD,NULL);
60     if (data !=22) {
61       printf("rank %d: Damn, data does not match (got %d)\n",rank, data);
62     }
63   }
64
65   if (rank==1) {
66     data=22;
67     MPI_Isend(&data,1,MPI_INT32_T,(rank+1)%2,666,MPI_COMM_WORLD, &r);
68     MPI_Wait(&r, MPI_STATUS_IGNORE);
69   } else {
70     MPI_Irecv(&data,1,MPI_INT32_T,MPI_ANY_SOURCE,666,MPI_COMM_WORLD,&r);
71     MPI_Wait(&r, MPI_STATUS_IGNORE);
72     if (data !=22) {
73       printf("rank %d: Damn, data does not match (got %d)\n",rank, data);
74     }
75   }
76
77   XBT_INFO("rank %d: data exchanged", rank);
78   MPI_Finalize();
79   return 0;
80 }