aboutsummaryrefslogtreecommitdiff
path: root/src/Panda/io_main.C
blob: 69b0a63447095b141f942287519acc8860158483 (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
#include "definitions.h"
#include "StopWatch.h"
#include "Panda.h"
#include "ArrayGroup.h"

extern MPIFS* MPIFS_global_obj;
extern int BRANCHING_FACTOR;
extern int SUBCHUNK_SIZE;
Boolean shared_flag = NO;


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

  strcpy(command[0], "-chunks");
  strcpy(command[1], "-xmax_messages");
  strcpy(command[2], "-tags");
  strcpy(command[3], "-branching_factor");
  strcpy(command[4], "-ymax_memory");
  strcpy(command[5], "-flag");
  strcpy(command[6], "-size_message");
  strcpy(command[7], "-Shared");

  for (int i= 0; i< 8; i++)  
    if (!strncmp(str, command[i], 2)) return command[i][1];
  printf("undefined input %s, quit!\n",str);
  exit(0); 
}

void parse_cl(int argc, char **argv)
{
   char opt;
   
   for(int i=1; i< argc; ){
	opt = my_getopt(argv[i++]);
	switch(opt) {
	case 'b' :
	  BRANCHING_FACTOR = atoi(argv[i++]);
	  break;
	case 's':
	  SUBCHUNK_SIZE = atoi(argv[i++]);
	  break;
	case 'S':
	  shared_flag = (Boolean) atoi(argv[i++]);
	  break;
	}
      }
}

main(int argc, char **argv)
{
  int  *world_ranks, my_rank, leader, app_size;
  MPI_Init(&argc, &argv);
  Panda *bear;
  char cmd[100];

  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  sprintf(cmd , "rm -rf  %s", FILEPREFIX); 
  //if (my_rank == 0) 
     system(cmd);
  sprintf(cmd , "mkdir %s", FILEPREFIX); 
  //if (my_rank == 0) 
     system(cmd);
  MPI_Comm_size(MPI_COMM_WORLD, &app_size);
  world_ranks = (int *) malloc(sizeof(int)*app_size);
  leader = 0; 

  for(int i=0;i< app_size; i++)
	world_ranks[i] = leader+i;
  parse_cl(argc, argv);
  if (shared_flag){
    bear = new Panda(IO_NODE, 0, my_rank, app_size,
		     world_ranks, YES);
  }
  else {
    bear = new Panda(IO_NODE, 0, my_rank, app_size, world_ranks);
  }
  delete bear;
//  sprintf(cmd , "rm -rf  %s", FILEPREFIX); if (my_rank == 0) system(cmd);
  MPI_Finalize();
}