Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
please sonar in various trivial ways
[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 ret;
17   int option_index = 0;
18   static struct option long_options[] = {
19   {"long",     no_argument, 0,  0 },
20   {0,         0,                 0,  0 }
21   };
22   while (1) {
23     ret = getopt_long(*argc, *argv, "s",
24                 long_options, &option_index);
25     if(ret==-1)
26       break;
27
28     switch (ret) {
29       case 0:
30         found++;
31       break;
32       case 's':
33         found ++;
34       break;
35       default:
36         printf("option %s", long_options[option_index].name);
37       break;
38     }
39   }
40   if (found!=2){
41     printf("(smpi_)getopt_long failed ! \n");
42   }
43 }
44
45 int main(int argc, char *argv[])
46 {
47   int rank;
48   int32_t data=11;
49
50   MPI_Init(NULL, NULL);
51
52   /* test getopt_long function */
53   test_opts(&argc, &argv);
54
55   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
56   MPI_Request r;
57   if (rank==1) {
58     data=22;
59     MPI_Send(&data,1,MPI_INT32_T,(rank+1)%2,666,MPI_COMM_WORLD);
60   } else {
61     MPI_Recv(&data,1,MPI_INT32_T,MPI_ANY_SOURCE,666,MPI_COMM_WORLD,NULL);
62     if (data !=22) {
63       printf("rank %d: Damn, data does not match (got %d)\n",rank, data);
64     }
65   }
66
67   if (rank==1) {
68     data=22;
69     MPI_Isend(&data,1,MPI_INT32_T,(rank+1)%2,666,MPI_COMM_WORLD, &r);
70     MPI_Wait(&r, MPI_STATUS_IGNORE);
71   } else {
72     MPI_Irecv(&data,1,MPI_INT32_T,MPI_ANY_SOURCE,666,MPI_COMM_WORLD,&r);
73     MPI_Wait(&r, MPI_STATUS_IGNORE);
74     if (data !=22) {
75       printf("rank %d: Damn, data does not match (got %d)\n",rank, data);
76     }
77   }
78
79   XBT_INFO("rank %d: data exchanged", rank);
80   MPI_Finalize();
81   return 0;
82 }