Newer
Older
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
/*
* Settings.cpp
*
* Created on: Feb 2017
* Author: Norbert Podhorszki
*/
#include <errno.h>
#include <cstdlib>
#include "Settings.h"
static int convertToInt( std::string varName, char *arg )
{
char *end;
int retval = std::strtoll( arg, &end, 10);
if( end[0] || errno == ERANGE )
{
throw std::invalid_argument( "Invalid value given for " + varName + ": "
+ std::string(arg) );
}
return retval;
}
Settings::Settings( int argc, char* argv [], int rank, int nproc )
: rank{rank}, nproc{nproc}
{
if (argc < 8)
{
throw std::invalid_argument( "Not enough arguments" );
}
outputfile = argv[1];
npx = convertToInt("N", argv[2]);
npy = convertToInt("M", argv[3]);
ndx = convertToInt("nx", argv[4]);
ndy = convertToInt("ny", argv[5]);
steps = convertToInt("steps", argv[6]);
iterations = convertToInt("iterations", argv[7]);
if( npx * npy != nproc )
{
throw std::invalid_argument( "N*M must equal the number of processes" );
}
// calculate global array size and the local offsets in that global space
gndx = npx * ndx;
gndy = npy * ndy;
posx = rank % npx;
posy = rank / npx;
offsx = posx * ndx;
offsy = posy * ndy;
// determine neighbors
if( posx == 0 )
rank_left = -1;
else
rank_left = rank-1;
if( posx == npx-1 )
rank_right = -1;
else
rank_right = rank+1;
if( posy == 0 )
rank_up = -1;
else
rank_up = rank - npx;
if( posy == npy-1 )
rank_down = -1;
else
rank_down = rank + npx;
}
Settings::~Settings()
{
}