Can we use signed integer identifiers? I find unsigned integers too error prone.
You don’t need the size argument if
x_iare containers — the sizes have to match and whatever the size is gives you the argument value.
The serial implementation is going to need to figure out how to store the data, but that should be worth the tradeoff—it shold be doable with a global
std::map, though that’s just one more thing to have to deal with if we ever tr to get multi-threading going.
Why generate an ID? I’d have thought it’d be easier to have the client pass it in.
I don’t think
mapshould be in the name because the data distribution is pre-map and the function includes the reduction step; I’m going to suggest including
_mpibut I’m on the fence about that one, too, as it will be implemented sequentially without MPI if MPI isn’t installed.
I don’t understand how you can pass a functor—in general, a functor can hold data. And it’s a local reference. See below.
All in, I’d think it could be just this:
void register_data_mpi(const VectorXd& x_r, const vector<int>& x_i, long id); template <class F> vector<var> call_mpi(const F& f, const Matrix<var, -1, 1>& theta, long id);
You could get rid of the
f argument to
call_mpi if you replaced the use of
f(...) in the program with
F would have to implement this concept:
static Matrix<var, -1, 1> F::apply(const Matrix<var, -1, 1>& theta, const MatrixXd& x_r, const vector<int>& x_i);
That solves the problem with functors having data in general.