Logo AND Algorithmique Numérique Distribuée

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