You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cout << "where g(x)=|x|/5 is a candidate sampling function since it's positive on the domain [-1:3] and its integral on the domain is equal to 1." << endl << endl;
53
+
int myrank = MPIMCI::init(); // first run custom MPI init
59
54
60
-
cout << "We start by initializing MPI and setting the MCI:" << endl;
61
-
62
-
MPIMCI::init();
63
-
64
-
// --- From now on we run in parallel ---
65
-
66
-
int myrank = MPI::COMM_WORLD.Get_rank();
55
+
if (myrank == 0) {
56
+
// intro
57
+
cout << "We want to compute the integral" << endl;
cout << "where g(x)=|x|/5 is a candidate sampling function since it's positive on the domain [-1:3] and its integral on the domain is equal to 1." << endl << endl;
62
+
63
+
cout << "We start by initializing MPI and setting the MCI:" << endl;
64
+
}
67
65
68
66
constint ndim = 1;
69
67
MCI * mci = newMCI(ndim);
@@ -174,22 +172,20 @@ int main() {
174
172
175
173
MPIMCI::finalize(mci); // also deletes all mci
176
174
175
+
// from now on just root thread
176
+
if (myrank == 0) {
177
+
cout << "The integral gives as result = " << average[0] << " +- " << error[0] << endl;
cout << "Using a sampling function in this case gives worse performance. In fact, the error bar is larger." << endl;
187
-
cout << "This implies that the variance of the re-factored f(x) written for introducing a sampling function, is larger than the original f(x)." << endl;
188
-
181
+
// final comments
182
+
cout << "Using a sampling function in this case gives worse performance. In fact, the error bar is larger." << endl;
183
+
cout << "This implies that the variance of the re-factored f(x) written for introducing a sampling function, is larger than the original f(x)." << endl;
0 commit comments