read_input_file.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 <string>
20 #include <fstream>
21 #include <iostream>
22 #include <stdexcept>
23 #include "mango.hpp"
24 
25 void mango::Problem::read_input_file(std::string filename) {
26  std::ifstream file;
27 
28  file.open(filename.c_str());
29  if (!file.is_open()) {
30  std::cerr << "Error! Unable to open file " << filename << std::endl;
31  throw std::runtime_error("Error in mango::Problem::read_input_file. Unable to open file.");
32  }
33 
34  int N_worker_groups;
35  std::string algorithm_str;
36  file >> N_worker_groups;
37  file >> algorithm_str;
38  set_algorithm(algorithm_str);
39  file.close();
40 
41  mpi_partition.set_N_worker_groups(N_worker_groups);
42 }
mango::MPI_Partition::set_N_worker_groups
void set_N_worker_groups(int N_worker_groups)
Set the number of worker groups to the given integer.
Definition: mpi_partition.cpp:106
mango::Problem::mpi_partition
MPI_Partition mpi_partition
Definition: mango.hpp:449
mango::Problem::set_algorithm
void set_algorithm(algorithm_type algorithm)
Sets the optimization algorithm.
Definition: algorithms.cpp:25
mango.hpp
mango::Problem::read_input_file
void read_input_file(std::string filename)
Reads in the number of worker groups and algorithm from a file.
Definition: read_input_file.cpp:25