Logo AND Algorithmique Numérique Distribuée

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