-
Notifications
You must be signed in to change notification settings - Fork 4
/
LeeWiswall_Driver.cpp
53 lines (47 loc) · 1.35 KB
/
LeeWiswall_Driver.cpp
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
/*
* NelderMead_Driver.cpp
*
* Based on the implementations by Kyle Klein and Jeff Borggaard.
*
*/
#include <cmath>
#include <iostream>
#include <mpi.h>
#include "LeeWiswall.hpp"
#include "ObjFunction.hpp"
int main(int argc, char **argv) {
int rank = 0, size = 1;
int prob_size = 300, max_iterations = -1;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (argc <= 1) {
std::cerr << "Error: incorrect usage ./execname <prob_size>"
"<max iterations (optional)>\n";
exit(1);
}
if (argc > 2) {
max_iterations = atoi(argv[2]);
} else {
max_iterations = -1;
}
prob_size = atoi(argv[1]);
double *guess = new double[prob_size];
for (int i = 0; i < prob_size; i++)
guess[i] = -1.0;
LeeWiswall *solver = new LeeWiswall(guess, 1.0, prob_size, objFunction3, rank, size);
double t1, t2;
t1 = MPI_Wtime();
double *answer = solver->solve(max_iterations);
t2 = MPI_Wtime();
if (rank == 0) {
std::cout << "Elapsed time during solve: " << t2 - t1 << std::endl;
for (int i = 0; i < prob_size - 1; i++) {
std::cout << answer[i] << ", ";
}
std::cout << answer[prob_size - 1] << std::endl;
}
delete solver;
MPI_Finalize();
return 0;
}