| 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.hpp | 
|---|
| 21 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de> | 
|---|
| 22 | * @date   Tue Apr  5 19:21:37 2011 | 
|---|
| 23 | * | 
|---|
| 24 | * @brief  Base class for commands that can be added to several | 
|---|
| 25 | *         command lists. Commands in the lists COMMANDLIST_INIT, | 
|---|
| 26 | *         COMMAND_LIST_LOOP and COMMANDLIST_FINALIZE will be | 
|---|
| 27 | *         executed automatically. However the user may create | 
|---|
| 28 | *         other command lists and execute them manually. | 
|---|
| 29 | * | 
|---|
| 30 | */ | 
|---|
| 31 |  | 
|---|
| 32 | #ifndef COMMAND_HPP_ | 
|---|
| 33 | #define COMMAND_HPP_ | 
|---|
| 34 |  | 
|---|
| 35 | #include <string> | 
|---|
| 36 | #include <vector> | 
|---|
| 37 |  | 
|---|
| 38 | #include "base/defs.hpp" | 
|---|
| 39 | #include "base/proxy.hpp" | 
|---|
| 40 | #include "comm/comm.hpp" | 
|---|
| 41 | #include "mg.hpp" | 
|---|
| 42 |  | 
|---|
| 43 | #ifdef HAVE_MPE | 
|---|
| 44 | #include <mpe_log.h> | 
|---|
| 45 | #define MPE_EVENT_BEGIN() static int eventID_begin;\ | 
|---|
| 46 | static int eventID_end;\ | 
|---|
| 47 | if (eventID_begin == 0 && eventID_end == 0) {\ | 
|---|
| 48 | MPE_Log_get_state_eventIDs(&eventID_begin, &eventID_end);\ | 
|---|
| 49 | if (MG::GetComm()->GlobalRank() == 0)\ | 
|---|
| 50 | MPE_Describe_state(eventID_begin, eventID_end, Name(), "pink");   \ | 
|---|
| 51 | }\ | 
|---|
| 52 | MPE_Log_event(eventID_begin, 0, NULL); | 
|---|
| 53 | #define MPE_EVENT_END() MPE_Log_event(eventID_end, 0, NULL); | 
|---|
| 54 | #else | 
|---|
| 55 | #define MPE_EVENT_BEGIN() | 
|---|
| 56 | #define MPE_EVENT_END() | 
|---|
| 57 | #endif /* HAVE_MPE */ | 
|---|
| 58 |  | 
|---|
| 59 | #define CREATE_INITIALIZER(a) void Initialize##a() {            \ | 
|---|
| 60 | VMG::MG::GetCommands().Register(new VMG::CommandProxy<a>);  \ | 
|---|
| 61 | } | 
|---|
| 62 |  | 
|---|
| 63 | namespace VMG | 
|---|
| 64 | { | 
|---|
| 65 |  | 
|---|
| 66 | class Command | 
|---|
| 67 | { | 
|---|
| 68 | public: | 
|---|
| 69 | typedef std::vector<std::string> argument_vector; ///< Holds arguments for execution | 
|---|
| 70 |  | 
|---|
| 71 | virtual ~Command() {} | 
|---|
| 72 |  | 
|---|
| 73 | /** | 
|---|
| 74 | * This function will be executed when command flow in a certain command | 
|---|
| 75 | * list reaches this command. | 
|---|
| 76 | * | 
|---|
| 77 | * @param arguments Holds arguments for execution as strings. When using multiple arguments, | 
|---|
| 78 | *                  ':' serves as the separator. | 
|---|
| 79 | * | 
|---|
| 80 | * @return Certain commands may want to change the following command flow of the command list | 
|---|
| 81 | *         (e.g. stopping criteria). This can be achieved by returning either "StopNow", which | 
|---|
| 82 | *         stops execution right after this command or by returning "StopLater", which will stop | 
|---|
| 83 | *         execution of a loop after the remaining commands have also been executed. | 
|---|
| 84 | */ | 
|---|
| 85 | virtual Request Run(Command::argument_vector arguments) = 0; | 
|---|
| 86 | }; | 
|---|
| 87 |  | 
|---|
| 88 | } | 
|---|
| 89 |  | 
|---|
| 90 | #endif /* COMMAND_HPP_ */ | 
|---|