Logo AND Algorithmique Numérique Distribuée

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