Logo AND Algorithmique Numérique Distribuée

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