source: src/base/command_list.cpp@ d24c2f

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

Parallel performance update.

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

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