-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_mpi.cpp
More file actions
121 lines (98 loc) · 4.43 KB
/
example_mpi.cpp
File metadata and controls
121 lines (98 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//==================================================================================
// FireFly - Reconstructing rational functions and polynomial over finite fields.
// Copyright (C) 2020 Jonas Klappert and Fabian Lange
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//==================================================================================
#include "firefly/DenseSolver.hpp"
#include "firefly/Reconstructor.hpp"
namespace firefly {
// Example of how one can use the black-box functor for the automatic interface
class BlackBoxUser : public BlackBoxBase<BlackBoxUser> {
public:
// Constructor of the derived class
// A default constructor is sufficient if no internal variables are required.
// In this example a ShuntingYardParser
BlackBoxUser(const ShuntingYardParser& par_) : par(par_) {};
// The evaluation of the black box
// Return a vector of FFIntTemp objects, which are the results of the black-box evaluation
// with values inserted for the variables.
// In this example we compute functions which are parsed from a file with a
// ShuntingYardParser object and the determinant of a matrix.
template<typename FFIntTemp>
std::vector<FFIntTemp> operator()(const std::vector<FFIntTemp>& values) {
//std::vector<FFIntTemp> result;
// Get results from parsed expressions
std::vector<FFIntTemp> result = par.evaluate_pre(values);
result.emplace_back(result[0] / result[3]);
// Build the matrix mat
mat_ff<FFIntTemp> mat = {{result[0], result[1]}, {result[2], result[3]}};
// Permutation vector
std::vector<int> p {};
// Compute LU decomposition of mat
calc_lu_decomposition(mat, p, 2);
// Compute determinant of mat
result.emplace_back(calc_determinant_lu(mat, p, 2));
return result;
}
// This function is called from Reconstructor when the prime field changes.
// Update the internal variables if required.
// In this example we precompute a few things for the ShuntingYardParser in
// the new prime field.
inline void prime_changed() {
par.precompute_tokens();
}
private:
// Internal variables for the black box
// In this example a ShuntingYardParser
ShuntingYardParser par;
};
}
using namespace firefly;
int main() {
// Initialization of MPI processes
// ---------------------------------------------------------------------------
int provided;
MPI_Init_thread(NULL, NULL, MPI_THREAD_SERIALIZED, &provided);
int process;
MPI_Comm_rank(MPI_COMM_WORLD, &process);
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
// ---------------------------------------------------------------------------
std::string root_dir = FIREFLY_ROOT_DIR;
// Parse the functions from "../s_y_4_v.m" with the variables x1, y, zZ, W
ShuntingYardParser par(root_dir + "/parser_test/s_y_4_v.m", {"x1", "y", "zZ", "W"});
// Create the user defined black box
BlackBoxUser bb(par);
// Interpolate on master and calculate probes on workers
if (process == master) {
Reconstructor<BlackBoxUser> reconst(4 /*n_vars*/,
std::thread::hardware_concurrency() /*n_threads*/,
1 /*bunch size*/,
bb /*black box*//*,
Reconstructor<BlackBoxUser>::CHATTY*/ /* verbosity mode*/);
reconst.enable_factor_scan();
reconst.enable_shift_scan();
reconst.reconstruct();
} else {
MPIWorker<BlackBoxUser>(4 /*n_vars*/,
std::thread::hardware_concurrency() /*n_threads*/,
1 /*bunch size*/,
bb /*black box*/);
}
// Finish MPI environment
MPI_Finalize();
return 0;
}