source: src/base/command_list.cpp@ ac6d04

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

Merge recent changes of the vmg library into ScaFaCos.

Includes a fix for the communication problems on Jugene.

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

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file command_list.cpp
3 * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
4 * @date Tue Apr 5 20:15:06 2011
5 *
6 */
7
8#ifdef HAVE_CONFIG_H
9#include <config.h>
10#endif
11
12#ifdef DEBUG_BARRIER
13#ifdef HAVE_MPI
14#include <mpi.h>
15#ifdef HAVE_MARMOT
16#include <enhancempicalls.h>
17#include <sourceinfompicalls.h>
18#endif
19#endif
20#endif
21
22#include <cstdio>
23
24#include "base/command.hpp"
25#include "base/command_factory.hpp"
26#include "base/command_list.hpp"
27#include "base/timer.hpp"
28#include "base/defs.hpp"
29#include "mg.hpp"
30
31using namespace VMG;
32
33Request CommandList::ExecuteList()
34{
35 Request request;
36 Request final_request = (commands.size() == 0 ? StopCycleNow : Continue);
37 Comm* comm = MG::GetComm();
38
39 for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter) {
40
41#ifdef DEBUG
42 const int num_args = (iter->second.size() > 1 ? iter->second.size() : (iter->second[0] == "" ? 0 : 1));
43 MG::GetCommands().CheckNumberOfArguments(iter->first, num_args);
44#endif
45
46#ifdef DEBUG_BARRIER
47#ifdef HAVE_MPI
48 MPI_Barrier(MPI_COMM_WORLD);
49#endif
50 comm->PrintString("Command \"%s\" start", iter->first.c_str());
51#endif
52
53 Timer::Start(iter->first);
54 request = MG::GetCommands().Get(iter->first)->Run(iter->second);
55 Timer::Stop(iter->first);
56
57#ifdef DEBUG_BARRIER
58#ifdef HAVE_MPI
59 MPI_Barrier(MPI_COMM_WORLD);
60#endif
61 comm->PrintString("Command \"%s\" done", iter->first.c_str());
62#endif
63
64 if (request == StopCycleLater)
65 final_request = StopCycleNow;
66 else if (request == StopCycleNow) {
67 final_request = StopCycleNow;
68 break;
69 }
70 }
71
72 return final_request;
73}
74
75void CommandList::AddCommand(std::string command, std::string arguments)
76{
77 std::vector<std::string> argument_list;
78 size_t pos;
79
80 do {
81 pos = arguments.find(':');
82 argument_list.push_back(arguments.substr(0, pos));
83 arguments.erase(0, pos+1);
84 }while (pos != std::string::npos);
85
86 commands.push_back(std::pair<std::string, std::vector<std::string> >(command, argument_list));
87}
88
89void CommandList::DeleteCommand(const CommandList::iterator& iter)
90{
91 commands.erase(iter);
92}
93
94void CommandList::Print()
95{
96 for (CommandList::iterator iter=commands.begin(); iter!=commands.end(); ++iter)
97 printf("%s\n", (*iter).first.c_str());
98}
99
100void CommandList::Clear()
101{
102 commands.clear();
103}
Note: See TracBrowser for help on using the repository browser.