source: src/base/command_list.cpp@ 2a5451

Last change on this file since 2a5451 was 2a5451, checked in by Julian Iseringhausen <isering@…>, 14 years ago

vmg now succeeds on test_comm.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1816 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#ifdef HAVE_MPI
66 comm.Barrier();
67#endif
68 comm.PrintStringOnce("Command \"%s\" start", iter->first.c_str());
69#endif
70
71 Timer::Start(iter->first);
72 request = MG::GetCommands().Get(iter->first)->Run(iter->second);
73 Timer::Stop(iter->first);
74
75#ifdef DEBUG_BARRIER
76#ifdef HAVE_MPI
77 comm.Barrier();
78#endif
79 comm.PrintStringOnce("Command \"%s\" done", iter->first.c_str());
80#endif
81
82 if (request == StopCycleLater)
83 final_request = StopCycleNow;
84 else if (request == StopCycleNow) {
85 final_request = StopCycleNow;
86 break;
87 }
88 }
89
90 return final_request;
91}
92
93void CommandList::AddCommand(std::string command, std::string arguments)
94{
95 std::vector<std::string> argument_list;
96 size_t pos;
97
98 do {
99 pos = arguments.find(':');
100 argument_list.push_back(arguments.substr(0, pos));
101 arguments.erase(0, pos+1);
102 }while (pos != std::string::npos);
103
104 commands.push_back(std::pair<std::string, std::vector<std::string> >(command, argument_list));
105}
106
107void CommandList::DeleteCommand(const CommandList::iterator& iter)
108{
109 commands.erase(iter);
110}
111
112void CommandList::Print()
113{
114 for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter)
115 printf("%s\n", (*iter).first.c_str());
116}
117
118void CommandList::Clear()
119{
120 commands.clear();
121}
Note: See TracBrowser for help on using the repository browser.