group_leaders_loop_least_squares.cpp
Go to the documentation of this file.
1 // Copyright 2019, University of Maryland and the MANGO development team.
2 //
3 // This file is part of MANGO.
4 //
5 // MANGO is free software: you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License as
7 // published by the Free Software Foundation, either version 3 of the
8 // License, or (at your option) any later version.
9 //
10 // MANGO is distributed in the hope that it will be useful, but
11 // WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with MANGO. If not, see
17 // <https://www.gnu.org/licenses/>.
18 
19 #include <iostream>
20 #include "mango.hpp"
21 #include "Least_squares_solver.hpp"
22 
24  // This method overrides mango::Solver::group_leaders_loop().
25 
26  double* state_vector = new double[N_parameters];
27  double* base_case_residual = new double[N_terms];
28  double* Jacobian = new double[N_parameters*N_terms];
29 
30  int data;
31 
32  bool keep_going = true;
33  while (keep_going) {
34  // Wait for proc 0 to send us a message that we should start.
35  MPI_Bcast(&data,1,MPI_INT,0,mpi_partition->get_comm_group_leaders());
36  if (data < 0) {
37  if (verbose > 0) std::cout << "proc " << mpi_partition->get_rank_world() <<
38  " (a group leader) is exiting." << std::endl;
39  keep_going = false;
40  } else {
41  if (verbose > 0) std::cout << "proc " << mpi_partition->get_rank_world() <<
42  " (a group leader) is starting finite-difference Jacobian calculation." << std::endl;
43  finite_difference_Jacobian(state_vector, base_case_residual, Jacobian);
44  }
45  }
46 
47  delete[] state_vector;
48  delete[] base_case_residual;
49  delete[] Jacobian;
50 
51 }
Least_squares_solver.hpp
mango::Least_squares_solver::N_terms
int N_terms
Definition: Least_squares_solver.hpp:38
mango::Solver::verbose
int verbose
Definition: Solver.hpp:63
mango::MPI_Partition::get_comm_group_leaders
MPI_Comm get_comm_group_leaders()
Get the MPI communicator for MANGO's "group leaders" communicator.
Definition: mpi_partition.cpp:51
mango::Solver::state_vector
double * state_vector
Definition: Solver.hpp:58
mango::Solver::mpi_partition
MPI_Partition * mpi_partition
Definition: Solver.hpp:65
mango.hpp
mango::MPI_Partition::get_rank_world
int get_rank_world()
Get the MPI rank of this processor in MANGO's world communicator.
Definition: mpi_partition.cpp:66
mango::Least_squares_solver::group_leaders_loop
void group_leaders_loop()
Definition: group_leaders_loop_least_squares.cpp:23
mango::Solver::N_parameters
int N_parameters
Definition: Solver.hpp:43
mango::Least_squares_solver::finite_difference_Jacobian
void finite_difference_Jacobian(const double *, double *, double *)
Definition: Least_squares_solver.cpp:54