-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmdLine.cpp
More file actions
108 lines (94 loc) · 2.83 KB
/
cmdLine.cpp
File metadata and controls
108 lines (94 loc) · 2.83 KB
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
// Process command line arguments
//
//
// Do not change the code in this file, as doing so
// could cause your submission to be graded incorrectly
//
#include <assert.h>
#include <getopt.h>
#include <stdlib.h>
#include <iostream>
#ifdef _MPI_
#include <mpi.h>
#endif
using namespace std;
void Stop();
void cmdLine(int argc, char *argv[], int& n, int& stats_freq, int& plot_freq, int& px, int& py, bool &noComm, int &niter){
/// Command line arguments
// Default value of the domain sizes
static struct option long_options[] = {
{"n", required_argument, 0, 'n'},
{"stats-freq", required_argument, 0, 's'},
{"plot", required_argument, 0, 'p'},
{"px", required_argument, 0, 'x'},
{"py", required_argument, 0, 'y'},
{"niter", required_argument, 0, 'i'},
{"nocomm", no_argument, 0, 'k'},
};
int nprocs=1, myrank=0;
#ifdef _MPI_
MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
#endif
// Process command line arguments
for(int ac=1;ac<argc;ac++) {
int c;
while ((c=getopt_long(argc,argv,"n:x:y:i:j:s:kp:",long_options,NULL)) != -1){
switch (c) {
// Size of the computational box
case 'n':
n = atoi(optarg);
break;
//
// X processor geometry
case 'x':
px = atoi(optarg);
break;
// X processor geometry
case 'y':
py = atoi(optarg);
break;
// # of iterations
// Use this option control the number of mesh sweeps
case 'i':
niter = atoi(optarg);
break;
// Print statistics for assessing correctness
case 's':
stats_freq = atoi(optarg);
break;
// Plot the excitation variable
case 'p':
plot_freq = atoi(optarg);
break;
// Shut off communication
case 'k':
noComm = true;
break;
// Error
default:
cout << "Usage: apf [-n <domain size>] [-i <# iterations>]";
cout << "\n\t ";
cout << " [-s <stats frequency>[-p <plot frequency>]\n\t";
cout << " [-x <x processor geometry>]";
cout << " [-y <x processor geometry>]";
cout << " [-k <no communication>]" << endl;
cout << endl;
exit(-1);
}
}
}
#ifdef _MPI_
if ((px * py) != nprocs){
if (!myrank)
cout << "\n *** The number of processes in the geometry (" << px*py << ") is not the same as the number requested (" << nprocs << ")" << endl << endl;
Stop();
}
#else
if ((px * py) > 1){
if (!myrank)
cout << "\n *** The number of processes in the geometry > 1, but you have not enabled MPI\n";
Stop();
}
#endif
}