1 | /*
|
---|
2 | * vmg - a versatile multigrid solver
|
---|
3 | * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
|
---|
4 | *
|
---|
5 | * vmg is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * vmg is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * @file command_list.cpp
|
---|
21 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
---|
22 | * @date Tue Apr 5 20:15:06 2011
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifdef HAVE_CONFIG_H
|
---|
27 | #include <libvmg_config.h>
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | #ifdef DEBUG_BARRIER
|
---|
31 | #ifdef HAVE_MPI
|
---|
32 | #include <mpi.h>
|
---|
33 | #ifdef HAVE_MARMOT
|
---|
34 | #include <enhancempicalls.h>
|
---|
35 | #include <sourceinfompicalls.h>
|
---|
36 | #endif
|
---|
37 | #endif
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | #include <cstdio>
|
---|
41 |
|
---|
42 | #include "base/command.hpp"
|
---|
43 | #include "base/command_factory.hpp"
|
---|
44 | #include "base/command_list.hpp"
|
---|
45 | #include "base/timer.hpp"
|
---|
46 | #include "base/defs.hpp"
|
---|
47 | #include "mg.hpp"
|
---|
48 |
|
---|
49 | using namespace VMG;
|
---|
50 |
|
---|
51 | Request CommandList::ExecuteList()
|
---|
52 | {
|
---|
53 | Request request;
|
---|
54 | Request final_request = (commands.size() == 0 ? StopCycleNow : Continue);
|
---|
55 |
|
---|
56 | for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter) {
|
---|
57 |
|
---|
58 | #ifdef DEBUG
|
---|
59 | const int num_args = (iter->second.size() > 1 ? iter->second.size() : (iter->second[0] == "" ? 0 : 1));
|
---|
60 | MG::GetCommands().CheckNumberOfArguments(iter->first, num_args);
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | #ifdef DEBUG_BARRIER
|
---|
64 | Comm& comm = *MG::GetComm();
|
---|
65 | comm.Barrier();
|
---|
66 | comm.PrintOnce(Debug, "Command \"%s\" start", iter->first.c_str());
|
---|
67 | #endif
|
---|
68 |
|
---|
69 | Timer::Start(iter->first);
|
---|
70 | request = MG::GetCommands().Get(iter->first)->Run(iter->second);
|
---|
71 | Timer::Stop(iter->first);
|
---|
72 |
|
---|
73 | #ifdef DEBUG_BARRIER
|
---|
74 | comm.Barrier();
|
---|
75 | comm.PrintOnce(Debug, "Command \"%s\" done", iter->first.c_str());
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | if (request == StopCycleLater)
|
---|
79 | final_request = StopCycleNow;
|
---|
80 | else if (request == StopCycleNow) {
|
---|
81 | final_request = StopCycleNow;
|
---|
82 | break;
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | return final_request;
|
---|
87 | }
|
---|
88 |
|
---|
89 | void CommandList::AddCommand(std::string command, std::string arguments)
|
---|
90 | {
|
---|
91 | std::vector<std::string> argument_list;
|
---|
92 | size_t pos;
|
---|
93 |
|
---|
94 | do {
|
---|
95 | pos = arguments.find(':');
|
---|
96 | argument_list.push_back(arguments.substr(0, pos));
|
---|
97 | arguments.erase(0, pos+1);
|
---|
98 | }while (pos != std::string::npos);
|
---|
99 |
|
---|
100 | commands.push_back(std::pair<std::string, std::vector<std::string> >(command, argument_list));
|
---|
101 | }
|
---|
102 |
|
---|
103 | void CommandList::DeleteCommand(const CommandList::iterator& iter)
|
---|
104 | {
|
---|
105 | commands.erase(iter);
|
---|
106 | }
|
---|
107 |
|
---|
108 | void CommandList::DeleteCommand(const std::string& _command)
|
---|
109 | {
|
---|
110 | CommandList::iterator iter = commands.begin();
|
---|
111 | for (;iter != commands.end(); ++iter)
|
---|
112 | if (iter->first == _command)
|
---|
113 | break;
|
---|
114 | assert( iter != commands.end() );
|
---|
115 | DeleteCommand(iter);
|
---|
116 | }
|
---|
117 |
|
---|
118 | void CommandList::Print()
|
---|
119 | {
|
---|
120 | for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter)
|
---|
121 | printf("%s\n", (*iter).first.c_str());
|
---|
122 | }
|
---|
123 |
|
---|
124 | void CommandList::Clear()
|
---|
125 | {
|
---|
126 | commands.clear();
|
---|
127 | }
|
---|