aboutsummaryrefslogtreecommitdiff
path: root/src/Panda/part_test.C
blob: 03a7c2c21b18286a57b1d4ef4240caba4aa48052 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*****************************************************************
 *     This is a sample program that shows how the panda library *
 *     is going to be used by the application programs.          *
 *     The example command line format is in test7.script.       *
 *     This example shows the interface with only disk layout    *
 *     info but no stride or subchunking schema. The value for   *
 *     those schemas use the default ones.                       *
 *     The current test varies the size of arrays. However, the  *
 *     wrapper function allows the number of the nodes to be     *
 *     changed as well.                                          *
 *     The first iteration loads all the code in memory.         *
 *     The second run does the simulated disk simulation.        *
 *     From the third run on, the values are the real writes.    *
 *****************************************************************/

#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "definitions.h"
#include "StopWatch.h"
#include "ArrayGroup.h"
#include "ArrayLayout.h"
#include "Array.h"
#include "Panda.h"

int Num_of_Arrays = 1;
int Num_Simulate_Read = 0;
int Num_Read = 0;
int Num_Simulate_Write = 2;
int Num_Write = 2 ;
int interleave = 0;
Panda *global_bear;
int world_rank;

extern int BRANCHING_FACTOR;
extern int SUBCHUNK_SIZE;
int STRATEGY = 1;

void test_timestep(ArrayGroup *t1, int arraysize, Array **arrays)
{
  StopWatch timer;
  int       i;
  int       flag=0;
  char      time_message[100];

#ifdef VERIFYBF
    for (int j=0; j<Num_of_Arrays; j++) arrays[j]->set_byte_pattern();
    t1->set_verify();
#endif


  global_bear->cleanfiles();
  global_bear->createfiles(); 

  for (i=0; i<Num_Simulate_Write+Num_Write; ++i) {
     if (i < Num_Simulate_Write){
              t1->set_simulate_mode();
              flag=0;
	    }
     else {
              t1->reset_simulate_mode();
              flag=1;
	      global_bear->cleanfiles();
	      global_bear->createfiles(); 
	   }


    global_bear->app_barrier();
    t1->set_io_strategy(STRATEGY); 
    timer.start();
    t1->timestep();
    timer.stop(":");
    sprintf(time_message,"%s Write: SIZE: %d, Time %i %s",
		(flag==0? "Simulated":"Real"), 
		arraysize, i, timer.get_description());
    printf("%s", time_message);

    if (Num_Read + Num_Simulate_Read == 0 || i < Num_Simulate_Write + Num_Write-1  ) {
	  global_bear->cleanfiles();
	  global_bear->createfiles();

    }    
   }
}

void test_readtimestep(ArrayGroup *r1, int arraysize, Array **arrays)
{
  StopWatch timer;
  int       i;
  int       flag;
  char time_message[100];
#ifdef VERIFYBF
      for (int j=0; j<Num_of_Arrays; j++) arrays[j]->reset_byte_pattern(); 
#endif

  if (Num_Write + Num_Simulate_Write == 0) {
	  global_bear->cleanfiles();
	  global_bear->createfiles();
  }  



  for (i=0; i<Num_Simulate_Read+Num_Read; ++i) {
    if (i < Num_Simulate_Read) { r1->set_simulate_mode(); flag=0; }
    else {r1->reset_simulate_mode();
          flag=1;
	  global_bear->flushfiles();
     }


    global_bear->app_barrier();
    r1->set_io_strategy(STRATEGY);
    timer.start();
    r1->restart();
    timer.stop(":");

    sprintf(time_message,"%s Read: SIZE: %d, Time %i %s ", 
	(flag==0? "Simulated":"Real"),
	arraysize, i, timer.get_description());
    printf("%s", time_message);

 }
#ifdef VERIFYBF
    for(i=0;i<Num_of_Arrays;i++)
	if (arrays[i]->verify_byte_pattern())
		printf("%d:Byte pattern verified for array %d\n", world_rank, i);
	else
		printf("%d:Byte pattern incorrect for array %d\n",world_rank,i);
#endif
    global_bear->cleanfiles();
}
 
 
int gemein(Panda *bear, int io_nodes, int arrayrank, int *arraysize, int esize,
           int mrank, int *mlayout, int drank, int *dlayout,
           Distribution *mem_dist, Distribution *disk_dist, int cost_model)
{
  ArrayLayout *mem1;              // Memory array layout
  ArrayLayout *disk1;             // Disk array layout
  int i;
  Array **arrays;
  arrays = (Array **)malloc(sizeof(Array*)*Num_of_Arrays);

// Set up memory and disk layouts
  mem1 = new ArrayLayout (mrank,mlayout);
  disk1 = new ArrayLayout(drank,dlayout);

// Create an Array for computation. 
  char *name;
  name = (char *)malloc(sizeof(char)*(strlen("z1Array")+5));
  char temp[5];
  for (i=0; i< Num_of_Arrays; i++) {
    strcpy(name,"z1Array");
    sprintf(temp, "%d", i);
    strcat(name, temp);
    arrays[i] = new Array(name,arrayrank,arraysize,esize,
		     mem1,mem_dist,disk1, disk_dist);
  }
  free(name);

  if (Num_Simulate_Write + Num_Write > 0) {
    ArrayGroup *t1 = new ArrayGroup("z4timestep");
    for (i= 0; i<Num_of_Arrays; i++)  t1->insert(arrays[i]);
    test_timestep(t1, arraysize[arrayrank-1], arrays);
    delete t1;
    if (Num_Simulate_Read + Num_Read > 0) {
      ArrayGroup *r1 = new ArrayGroup("z4timestep");
      for (i= 0; i<Num_of_Arrays; i++)  r1->insert(arrays[i]);
      test_readtimestep(r1, arraysize[arrayrank-1], arrays);
      delete r1;
     }  
  } else {

    ArrayGroup *r1 = new ArrayGroup("z4timestep");
    for (i= 0; i<Num_of_Arrays; i++)  r1->insert(arrays[i]);
    test_readtimestep(r1, arraysize[arrayrank-1], arrays);
    delete r1;
  }

  // delete all objects created

  for (i=0; i<Num_of_Arrays; i++) delete arrays[i];
  free(arrays);
  delete disk1;
  delete mem1;
  return(0);
}

char my_getopt(char *str)
{
  char command[25][15];

  strcpy(command[0], "-Total_nodes");
  strcpy(command[1], "-Io_nodes");
  strcpy(command[2], "-upper");
  strcpy(command[3], "-Arraysize");
  strcpy(command[4], "-Esize");
  strcpy(command[5], "-Mlayout");
  strcpy(command[6], "-Dlayout");
  strcpy(command[7], "-mem_dist");
  strcpy(command[8], "-disk_dist");
  strcpy(command[9], "-num_arrays");
  strcpy(command[10], "-read_simulate");
  strcpy(command[11], "-Read");
  strcpy(command[12], "-write_simulate");
  strcpy(command[13], "-Write");
  strcpy(command[14], "-interleave");
  strcpy(command[15], "-Cost_model");
  strcpy(command[16], "-chunks");
  strcpy(command[17], "-xmax_messages");
  strcpy(command[18], "-tags");
  strcpy(command[19], "-branching_factor");
  strcpy(command[20], "-ymax_memory");
  strcpy(command[21], "-flag");
  strcpy(command[22], "-size_message");
  strcpy(command[23], "-Xfactor");
  strcpy(command[24], "-Optimize");
  
  for (int i= 0; i< 25; i++)  
    if (!strncmp(str, command[i], 2)) return command[i][1];
  printf("undefined input %s, quit!\n",str);
  return NULL;
}

void parse_cl(int argc, char **argv, int &total_nodes, int &io_nodes, 
	      int &upper_bound, int &lower_bound, int &arrayrank, int*& arraysize,
	      int &esize, int &mrank, int*& mlayout, int& drank, int*& dlayout,
	      Distribution*& mem_dist, Distribution*& disk_dist, int &cost_model_mode)
{
  char opt;
  int k;
 
  for (int i=1; i<argc; ) {
    opt = my_getopt(argv[i++]);
    switch(opt) 
    {
      case 'X':
        STRATEGY = atoi(argv[i++]);
	break;
      case 'T':
        total_nodes =  atoi(argv[i++]); 
	break;
      case 'I': 
	io_nodes = atoi(argv[i++]);
	break;
      case 'u': 
	upper_bound = atoi(argv[i++]);  
	break;
      case 'A': 
	arrayrank = atoi(argv[i++]);
        arraysize = (int *) malloc(sizeof(int)* arrayrank);
        mem_dist = (Distribution *)malloc(sizeof(Distribution)*arrayrank);
        disk_dist = (Distribution *)malloc(sizeof(Distribution)*arrayrank);
        for (k = 0; k < arrayrank; k++) arraysize[k] = atoi(argv[i++]);
	lower_bound = arraysize[k-1];
	break;	
      case 'E': 
	esize = atoi(argv[i++]); 
	break;
      case 'M': 
	mrank = atoi(argv[i++]);
	mlayout = (int *) malloc(sizeof(int)* mrank);
        for (k = 0; k < mrank; k++) mlayout[k] = atoi(argv[i++]);
	break;	  
      case 'D':
	drank = atoi(argv[i++]);
	dlayout = (int *) malloc(sizeof(int)* drank);
        for (k = 0; k < drank; k++) dlayout[k] = atoi(argv[i++]);
	break;	
      case 'm':
	for (k = 0; k < arrayrank; k++) mem_dist[k] = (Distribution)atoi(argv[i++]);
	break;
      case 'd':
	for (k = 0; k < arrayrank; k++) disk_dist[k] = (Distribution)atoi(argv[i++]);
	break;
      case 'n':  
	Num_of_Arrays = atoi(argv[i++]);
        break;
      case 'r': 
	Num_Simulate_Read = atoi(argv[i++]);
        break;
      case 'R':
 	Num_Read = atoi(argv[i++]);
	break;
      case 'w':
	Num_Simulate_Write = atoi(argv[i++]);
	break;
      case 'W':    	
	Num_Write = atoi(argv[i++]);
	break;
      case 'i':
	interleave = atoi(argv[i++]);
	break;
      case 'C':
	cost_model_mode = atoi(argv[i++]);
	break;
      case 'b' :
	BRANCHING_FACTOR = atoi(argv[i++]);
	break;
      case 's':
	SUBCHUNK_SIZE = atoi(argv[i++]);
	break;
      }
   }
} 
   		

int main(int argc, char **argv)
{
  int total_nodes;                // The number of total nodes (comp + io)
  int io_nodes;                   // The number of io nodes
  int upper_bound;                // The upper bound of the last dimension of the array
  int lower_bound;                // The starting number of the last dimension of the array
  int arrayrank ;                 // The array rank.
  int *arraysize;                 // The number of elements along each array dimention
  int esize ;                     // element size of each array element
  int mrank ;                     // Compute node mesh rank
  int *mlayout;                   // Compute node mesh layout
  int drank ;                     // IO node mesh rank
  int cost_model_mode;           // Whether the cost model is included.
  int *dlayout;                   // IO node mesh layout
  Distribution *mem_dist;         // The memory array distribution along each dimention
                                  // There are three possible distributions (BLOCK,
                                  // NONE, CYCLIC).
  Distribution *disk_dist;        // The disk array distribution along each dimention
  int my_rank, my_app_size, *world_ranks, leader;
  char sys_command[100];
  
  MPI_Init(&argc, &argv);

// For Parallel architecture (IBM SP2 like),
// Initialize the MPI environment. Only compute nodes will return from 
// this call, the io nodes will not return from the call. All the io nodes
  MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &my_app_size);
  leader = 0; 
  world_ranks = (int *) malloc(sizeof(int)*my_app_size);
  for(int i=0;i< my_app_size; i++)
        world_ranks[i] = leader+i;



  Panda *bear;
  int my_io_rank = my_rank;
  int *io_ranks;

  parse_cl(argc, argv, total_nodes, io_nodes, upper_bound, lower_bound, 
          arrayrank, arraysize, esize, mrank, mlayout, drank, dlayout, 
          mem_dist, disk_dist, cost_model_mode); 

  io_ranks = world_ranks;


  if (my_io_rank<io_nodes)
  {
	global_bear = new Panda(PART_TIME_IO, my_rank, my_app_size, world_ranks,
				 my_io_rank, io_nodes, io_ranks);
	bear = global_bear;
  }
  else
  {
	global_bear = new Panda(PART_TIME_COMPUTE, my_rank, my_app_size, world_ranks,
				 -1, io_nodes, io_ranks);
	bear = global_bear;
  }
  for (int size=lower_bound; size <= upper_bound; size*=2) {
    arraysize[arrayrank-1] = size;
    gemein(bear,io_nodes, arrayrank, arraysize, esize, 
           mrank, mlayout, drank, dlayout, mem_dist, 
	   disk_dist, cost_model_mode);
  }

  free(mlayout);
  free(dlayout);
  free(mem_dist);
  free(disk_dist);
  free(world_ranks);
  delete bear;

  MPI_Finalize();
  return(0);
}