source: src/base/command_list.cpp@ f57182

Last change on this file since f57182 was d13e27, checked in by Julian Iseringhausen <isering@…>, 13 years ago

vmg: Work on output verbosity.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@2845 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 3.0 KB
Line 
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 <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
49using namespace VMG;
50
51Request 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
89void 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
103void CommandList::DeleteCommand(const CommandList::iterator& iter)
104{
105 commands.erase(iter);
106}
107
108void CommandList::Print()
109{
110 for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter)
111 printf("%s\n", (*iter).first.c_str());
112}
113
114void CommandList::Clear()
115{
116 commands.clear();
117}
Note: See TracBrowser for help on using the repository browser.