Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[example,smpi,MM] remove the timer interface which is useless here
[simgrid.git] / examples / smpi / MM / MM_mpi.c
1 /*
2  * Block Matrix Multiplication example
3  *
4  */
5
6
7 #include "topo.h"
8 #include "param.h"
9 #include "Matrix_init.h"
10 #include "2.5D_MM.h"
11 #include "xbt/log.h"
12
13 /*int sched_setaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
14   int sched_getaffinity(pid_t pid, size_t cpusetsize, cpu_set_t *mask);
15  */
16 #include <mpi.h>
17 #include <math.h>
18 #include <getopt.h>
19 #include <stdio.h>
20 #include <string.h>
21
22  XBT_LOG_NEW_DEFAULT_CATEGORY(MM_mpi,
23                              "Messages specific for this msg example");
24
25
26
27 int main(int argc, char ** argv)
28 {
29
30   size_t    m   = 1024 , n   = 1024 , k = 1024;
31   size_t    NB_Block = 16;
32   size_t    Block_size = k/NB_Block ;
33   size_t    NB_groups = 1, group = 0, key = 0;
34   /* x index on M
35      y index on N
36      Z index on K */
37
38
39
40   int myrank;
41   int NB_proc;
42   size_t row, col, size_row, size_col; //description: vitual processor topology
43   row = 0;
44   col = 0;
45
46   MPI_Init(&argc, &argv);
47
48   /* Find out my identity in the default communicator */
49
50   MPI_Comm_rank ( MPI_COMM_WORLD, &myrank );
51   MPI_Comm_size ( MPI_COMM_WORLD, &NB_proc );
52
53   if(NB_proc != 1)
54     for (size_col=NB_proc/2; NB_proc%size_col; size_col--);
55   else
56     size_col = 1;
57
58   size_row = NB_proc/size_col;
59   if (size_row > size_col){
60     size_col = size_row;
61     size_row = NB_proc/size_col;
62   }
63
64
65   // for the degub
66 #if DEBUG_MPI
67   size_t loop=1;
68   while(loop==1);
69 #endif
70
71   int opt, display = 0;
72   char *conf_file = NULL;
73   optind = 1;
74
75   //get the parameter from command line
76   while ((opt = getopt(argc, argv, "hdf:r:c:M:N:K:B:G:g:k:P:")) != -1) {
77     switch(opt) {
78       case 'h':
79         XBT_INFO(
80                     "Usage: mxm_cblas_test [options]\n"
81                     "   -M I    M size (default: %zu)\n"
82                     "   -N I    N size (default: %zu)\n"
83                     "   -K I    K size (default: %zu)\n"
84                     "   -B I    Block size on the k dimension(default: %zu)\n"
85                     "   -G I    Number of processor groups(default: %zu)\n"
86                     "   -g I    group index(default: %zu)\n"
87                     "   -k I    group rank(default: %zu)\n"
88                     "   -r I    processor row size (default: %zu)\n"
89                     "   -c I    processor col size (default: %zu)\n"
90                     " -f {Filename} provide the file with the configuration\n"
91                     "   -d  display the configuration file on the stderr\n"
92                     "   -h      help\n",
93                     m, n, k, Block_size, NB_groups, group, key, row, col);
94         return 0;
95       case 'M':
96         m = atoi(optarg);
97         break;
98       case 'N':
99         n   = atoi(optarg);
100         break;
101       case 'K':
102         k  = atoi(optarg);
103         break;
104       case 'B':
105         Block_size = atoi(optarg);
106         break;
107       case 'G':
108         NB_groups = atoi(optarg);
109         break;
110       case 'g':
111         group = atoi(optarg);
112         break;
113       case 'k':
114         key = atoi(optarg);
115         break;
116       case 'r':
117         size_row = atoi(optarg);
118         break;
119       case 'c':
120         size_col = atoi(optarg);
121         break;
122         /*case 'P':
123           str_mask = strdup(optarg);
124           break;*/
125       case 'f':
126         conf_file = strdup(optarg);
127         break;
128       case 'd':
129         display = 1;
130         break;
131     }
132   }
133   if( display == 1 ){
134     print_conf(MPI_COMM_WORLD, myrank,NULL,NULL);
135     MPI_Barrier(MPI_COMM_WORLD);
136     MPI_Finalize();
137     exit(0);
138   }
139
140   char **conf;
141   //char ***conf_all;
142   if(conf_file == NULL){
143     conf = get_conf(MPI_COMM_WORLD, "default_conf", -1);
144   }else{
145     conf = get_conf(MPI_COMM_WORLD, conf_file, -1);
146     //conf_all = get_conf_all(conf_file);
147   }
148   if(conf == NULL){
149         XBT_INFO(
150                 "No configuration for me inside the file\n");
151   }else{
152
153
154     if(NB_groups !=1){
155       /* Get my group number from the config file */
156       group = (size_t)atoi(conf[4]);
157     }
158   }
159
160
161
162
163
164
165   // Defined the device if we use the GPU
166   //TODO explain parameters
167
168
169   two_dot_five( m, k, n, Block_size, group, key,
170                size_row, size_col,  NB_groups);
171
172   // close properly the pragram
173   MPI_Barrier(MPI_COMM_WORLD);
174   MPI_Finalize();
175   return 0;
176 }