Logo AND Algorithmique Numérique Distribuée

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