group_leaders_loop.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 "
Solver.hpp
"
22
23
void
mango::Solver::group_leaders_loop
() {
24
double
*
state_vector
=
new
double
[
N_parameters
];
25
double
* gradient =
new
double
[
N_parameters
];
26
27
int
data;
28
double
dummy;
29
30
if
(
verbose
> 0) std::cout <<
"Proc "
<<
mpi_partition
->
get_rank_world
() <<
" in entering group_leaders_loop."
<< std::endl;
31
32
bool
keep_going =
true
;
33
while
(keep_going) {
34
// Wait for proc 0 to send us a message.
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
() <<
" (a group leader) is exiting."
<< std::endl;
38
keep_going =
false
;
39
}
else
{
40
if
(
verbose
> 0) std::cout <<
"proc "
<<
mpi_partition
->
get_rank_world
() <<
" (a group leader) is starting finite-difference gradient calculation."
<< std::endl;
41
finite_difference_gradient
(
state_vector
, &dummy, gradient);
42
}
43
}
44
45
delete
[]
state_vector
;
46
delete
[] gradient;
47
}
mango::Solver::finite_difference_gradient
virtual void finite_difference_gradient(const double *, double *, double *)
Definition:
Solver.cpp:82
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
Solver.hpp
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::Solver::N_parameters
int N_parameters
Definition:
Solver.hpp:43
mango::Solver::group_leaders_loop
virtual void group_leaders_loop()
Definition:
group_leaders_loop.cpp:23