@@ -36,7 +36,7 @@ namespace MPIMCI
36
36
}
37
37
38
38
// set different random seeds per thread from a file
39
- void setSeed (MCI * const mci, const std::string filename)
39
+ void setSeed (MCI * const mci, const std::string & filename, const int &offset = 0 ) // with offset you can control how many seeds to skip initially
40
40
{
41
41
int myrank = rank ();
42
42
int nranks = size ();
@@ -47,7 +47,13 @@ namespace MPIMCI
47
47
std::ifstream seedfile;
48
48
seedfile.open (filename);
49
49
50
+ for (int i=0 ; i<offset; ++i) {
51
+ if (seedfile.eof ()) {throw std::runtime_error (" Chosen seed offset is already larger than the number of seeds in seed file." );}
52
+ uint_fast64_t skip;
53
+ seedfile >> skip;
54
+ }
50
55
for (int i=0 ; i<nranks; ++i) {
56
+ if (seedfile.eof ()) {throw std::runtime_error (" Seed file doesn't provide enough seeds for the chosen number of ranks and offset." );}
51
57
seedfile >> seeds[i];
52
58
}
53
59
seedfile.close ();
@@ -65,9 +71,9 @@ namespace MPIMCI
65
71
// make sure the user has MPI in the correct state
66
72
int isinit, isfinal;
67
73
MPI_Initialized (&isinit);
68
- if (isinit==0 ) throw std::runtime_error (" MPI not initialized!" );
74
+ if (isinit==0 ) { throw std::runtime_error (" MPI not initialized!" );}
69
75
MPI_Finalized (&isfinal);
70
- if (isfinal==1 ) throw std::runtime_error (" MPI already finalized!" );
76
+ if (isfinal==1 ) { throw std::runtime_error (" MPI already finalized!" );}
71
77
72
78
int nranks = size ();
73
79
@@ -98,9 +104,9 @@ namespace MPIMCI
98
104
// make sure the user has MPI in the correct state
99
105
int isinit, isfinal;
100
106
MPI_Initialized (&isinit);
101
- if (isinit==0 ) throw std::runtime_error (" MPI not initialized!" );
107
+ if (isinit==0 ) { throw std::runtime_error (" MPI not initialized!" );}
102
108
MPI_Finalized (&isfinal);
103
- if (isfinal==1 ) throw std::runtime_error (" MPI already finalized!" );
109
+ if (isfinal==1 ) { throw std::runtime_error (" MPI already finalized!" );}
104
110
105
111
MPI_Finalize ();
106
112
}
0 commit comments