HyPar
1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
EnsembleSimulationsDefine.cpp
Go to the documentation of this file.
1
6
#include <string>
7
#include <
ensemble_simulations.h
>
8
28
int
EnsembleSimulation::define
(
int
a_rank,
29
int
a_nproc
30
)
31
{
32
if
(
m_is_defined
) {
33
fprintf(stderr,
"Error: object already defined on rank %d.\n"
, a_rank);
34
return
1;
35
}
36
37
m_rank
= a_rank;
38
m_nproc
= a_nproc;
39
40
/* default value */
41
m_nsims
= -1;
42
43
if
(!
m_rank
) {
44
45
FILE *in;
46
in = fopen(
_ENSEMBLE_SIM_INP_FNAME_
,
"r"
);
47
48
if
(!in) {
49
fprintf(stderr,
"Error in EnsembleSimulations::Define() - %s file not found.\n"
,
50
_ENSEMBLE_SIM_INP_FNAME_
);
51
}
else
{
52
53
int
ferr;
54
char
word[
_MAX_STRING_SIZE_
];
55
ferr = fscanf(in,
"%s"
, word);
if
(ferr != 1)
return
(1);
56
57
if
(std::string(word) ==
"begin"
) {
58
59
while
(std::string(word) !=
"end"
) {
60
61
ferr = fscanf(in,
"%s"
,word);
if
(ferr != 1)
return
(1);
62
63
if
(std::string(word) ==
"nsims"
) {
64
ferr = fscanf(in,
"%d"
,&
m_nsims
);
if
(ferr != 1)
return
(1);
65
}
else
if
(std::string(word) !=
"end"
) {
66
char
useless[
_MAX_STRING_SIZE_
];
67
ferr = fscanf(in,
"%s"
,useless);
68
printf(
"Warning: keyword %s in file \"%s\" with value %s not recognized or extraneous. Ignoring.\n"
,
69
_ENSEMBLE_SIM_INP_FNAME_
, word, useless );
70
}
71
72
if
(ferr != 1)
return
(1);
73
}
74
75
}
else
{
76
fprintf(stderr,
"Error: Illegal format in file \"%s\". Word read is: %s\n"
,
77
_ENSEMBLE_SIM_INP_FNAME_
, word);
78
return
1;
79
}
80
81
fclose(in);
82
83
}
84
85
if
(
m_nsims
< 1) {
86
fprintf(stderr,
"Error in InitializeSimulation(): invalid value for nsims (%d)!\n"
,
m_nsims
);
87
return
1;
88
}
89
90
printf(
"Number of simulation domains: %d\n"
,
m_nsims
);
91
92
}
93
94
#ifndef serial
95
MPI_Bcast(&
m_nsims
,1,MPI_INT,0,MPI_COMM_WORLD);
96
#endif
97
98
if
(
m_nsims
< 0) {
99
return
1;
100
}
101
102
m_sims
.resize(
m_nsims
);
103
for
(
int
ns = 0; ns <
m_nsims
; ns++) {
104
m_sims
[ns].solver.my_idx = ns;
105
m_sims
[ns].solver.nsims =
m_nsims
;
106
m_sims
[ns].mpi.rank =
m_rank
;
107
m_sims
[ns].mpi.nproc =
m_nproc
;
108
}
109
110
if
(!
m_rank
) {
111
printf(
"Allocated simulation object(s).\n"
);
112
}
113
114
m_is_defined
=
true
;
115
return
0;
116
}
EnsembleSimulation::m_nsims
int m_nsims
Definition:
ensemble_simulations.h:193
EnsembleSimulation::m_is_defined
bool m_is_defined
Definition:
ensemble_simulations.h:192
EnsembleSimulation::define
int define(int, int)
Definition:
EnsembleSimulationsDefine.cpp:28
EnsembleSimulation::m_sims
std::vector< SimulationObject > m_sims
Definition:
ensemble_simulations.h:197
EnsembleSimulation::m_rank
int m_rank
Definition:
ensemble_simulations.h:194
ensemble_simulations.h
Ensemble simulation class.
_MAX_STRING_SIZE_
#define _MAX_STRING_SIZE_
Definition:
basic.h:14
EnsembleSimulation::m_nproc
int m_nproc
Definition:
ensemble_simulations.h:194
_ENSEMBLE_SIM_INP_FNAME_
#define _ENSEMBLE_SIM_INP_FNAME_
Definition:
ensemble_simulations.h:13