source: src/base/command_list.cpp@ fcf7f6

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

vmg: Added license files and headers (GPLv3).

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