Performance contract: the std::function<double(int)> parameter is type-erased; lambdas larger than the SBO threshold (~24-32 bytes on libstdc++) heap-allocate on construction. Callers should construct the std::function ONCE outside the loop and reuse it, not re-bind on every probe. The probe lambda itself is invoked n_probes / nprocs times under RankLocal kind, n_probes times under Distributed kind.
50{
51 if (n_probes <= 0) return Eigen::VectorXd();
52
53
54
55
56 if (!ctx.is_distributed()) {
57 return run_sequential(n_probes, probe_fn);
58 }
59
60#if defined(GPR_HAVE_MPI) || defined(GPR_LINALG_SCALAPACK)
61
62
63
64
65
67
68
69
70
71 Eigen::VectorXd
out = Eigen::VectorXd::Zero(n_probes);
72 bool local_failed = false;
73 for (int idx = 0; idx < n_probes; ++idx) {
74 const double v = probe_fn(idx);
75 if (std::isnan(v)) {
76 local_failed = true;
77 continue;
78 }
80 }
81 bool global_failed = false;
82 MPI_Allreduce(&local_failed, &global_failed, 1, MPI_C_BOOL, MPI_LOR,
83 ctx.comm);
84 if (global_failed) return Eigen::VectorXd::Constant(n_probes, kNaN);
86 }
87
88
89
90
91
92 Eigen::VectorXd local = Eigen::VectorXd::Zero(n_probes);
93 bool local_failed = false;
94 for (int idx = 0; idx < n_probes; ++idx) {
95 if (idx % ctx.nprocs != ctx.rank) continue;
96 const double v = probe_fn(idx);
97 if (std::isnan(v)) {
98 local_failed = true;
99
100
101
102
103
104 break;
105 }
106 local(idx) = v;
107 }
108
109
110
111
112
113
114
115
116
117 bool global_failed = false;
118 MPI_Allreduce(&local_failed, &global_failed, 1, MPI_C_BOOL, MPI_LOR,
119 ctx.comm);
120
121 if (global_failed) {
122
123
124
125
126
127 return Eigen::VectorXd::Constant(n_probes, kNaN);
128 }
129
130 Eigen::VectorXd global = Eigen::VectorXd::Zero(n_probes);
131 MPI_Allreduce(local.data(), global.data(), static_cast<int>(local.size()),
132 MPI_DOUBLE, MPI_SUM, ctx.comm);
133 return global;
134#else
135
136
137
138
139
140
141
142
143
144
145 if (ctx.nprocs != 1) {
146 throw std::logic_error(
147 "ProbeExecutor: nprocs > 1 requires the SCALAPACK build");
148 }
149 (void)kind;
150 return run_sequential(n_probes, probe_fn);
151#endif
152}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out