source: src/base/command_list.cpp@ 64ba929

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

Check that mpi.h will be included as the first header.

Needed by certain mpi implementations.

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

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