Skip to content
Permalink
Browse files

#85: adding SimpleWMS example

  • Loading branch information...
rafaelfsilva committed Dec 14, 2018
1 parent de460eb commit 2896f631527b80dcdc10d58dfff72ded0ab09eb0
Showing with 137 additions and 6 deletions.
  1. +2 −6 examples/simple-example/SimpleWMS.cpp
  2. +135 −0 tools/wrench/wrench-init
@@ -57,7 +57,6 @@ namespace wrench {
WRENCH_INFO("About to execute a workflow with %lu tasks", this->getWorkflow()->getNumberOfTasks());

// Create a job manager

this->job_manager = this->createJobManager();

// Create a data movement manager
@@ -82,18 +81,15 @@ namespace wrench {
// Submit pilot jobs
if (this->getPilotJobScheduler()) {
WRENCH_INFO("Scheduling pilot jobs...");
this->getPilotJobScheduler()->schedulePilotJobs(
this->getAvailableComputeServices());
this->getPilotJobScheduler()->schedulePilotJobs(this->getAvailableComputeServices());
}

// Perform dynamic optimizations
runDynamicOptimizations();

// Run ready tasks with defined scheduler implementation
WRENCH_INFO("Scheduling tasks...");
this->getStandardJobScheduler()->scheduleTasks(
this->getAvailableComputeServices(),
ready_tasks);
this->getStandardJobScheduler()->scheduleTasks(this->getAvailableComputeServices(), ready_tasks);

// Wait for a workflow execution event, and process it
try {
@@ -79,6 +79,7 @@ def _write_cmakelists(project_dir):
'',
'# source files',
'set(SOURCE_FILES',
' src/SimpleWMS.cpp'
' src/main.cpp',
' )',
'',
@@ -123,6 +124,7 @@ def _write_main(project_dir):
' */',
'',
'#include <wrench.h>',
'#include "SimpleWMS.h"',
'',
'int main(int argc, char **argv) {',
'',
@@ -214,10 +216,137 @@ def _write_main(project_dir):
' }',
'',
' return 0;',
'}',
''
])


def _write_simple_wms(project_dir):
logger.debug('Writing src/SimpleWMS.h example file')
_write_contents(project_dir + '/src/SimpleWMS.h', [
'/**',
' * ADD A HEADER TO YOUR WRENCH WMS',
' */',
'',
'#ifndef WRENCH_SIMPLEWMS_H',
'#define WRENCH_SIMPLEWMS_H',
'',
'#include <wrench-dev.h>',
'',
'class Simulation;',
'',
'/**',
' * @brief A simple WMS implementation',
' */',
'class SimpleWMS : public wrench::WMS {',
'public:',
' SimpleWMS(std::unique_ptr<wrench::StandardJobScheduler> standard_job_scheduler,',
' std::unique_ptr<wrench::PilotJobScheduler> pilot_job_scheduler,',
' const std::set<wrench::ComputeService *> &compute_services,',
' const std::set<wrench::StorageService *> &storage_services,',
' const std::string &hostname);',
'',
'private:',
' int main() override;',
'',
' /** @brief The job manager */',
' std::shared_ptr<wrench::JobManager> job_manager;',
'};',
'',
'#endif //WRENCH_SIMPLEWMS_H',
''
])

logger.debug('Writing src/SimpleWMS.cpp example file')
_write_contents(project_dir + '/src/SimpleWMS.cpp', [
'/**',
' * ADD A HEADER TO YOUR WRENCH WMS',
' */',
'',
'#include <iostream>',
'',
'#include "SimpleWMS.h"',
'',
'XBT_LOG_NEW_DEFAULT_CATEGORY(simple_wms, "Log category for Simple WMS");',
'',
'/**',
' * @brief Create a Simple WMS with a workflow instance, a scheduler implementation, and a list of compute services',
' */',
'SimpleWMS::SimpleWMS(std::unique_ptr<wrench::StandardJobScheduler> standard_job_scheduler,',
' std::unique_ptr<wrench::PilotJobScheduler> pilot_job_scheduler,',
' const std::set<wrench::ComputeService *> &compute_services,',
' const std::set<wrench::StorageService *> &storage_services,',
' const std::string &hostname) : wrench::WMS(',
' std::move(standard_job_scheduler),',
' std::move(pilot_job_scheduler),',
' compute_services,',
' storage_services,',
' {}, nullptr,',
' hostname,',
' "simple") {}',
'',
'/**',
' * @brief main method of the SimpleWMS daemon',
' */',
'int SimpleWMS::main() {',
'',
' wrench::TerminalOutput::setThisProcessLoggingColor(wrench::TerminalOutput::COLOR_GREEN);',
'',
' // Check whether the WMS has a deferred start time',
' checkDeferredStart();',
'',
' WRENCH_INFO("About to execute a workflow with %lu tasks", this->getWorkflow()->getNumberOfTasks());',
'',
' // Create a job manager',
' this->job_manager = this->createJobManager();',
'',
' // Create a data movement manager',
' std::shared_ptr<wrench::DataMovementManager> data_movement_manager = this->createDataMovementManager();',
'',
' while (true) {',
' // Get the ready tasks',
' std::vector<wrench::WorkflowTask *> ready_tasks = this->getWorkflow()->getReadyTasks();',
'',
' // Get the available compute services',
' std::set<wrench::ComputeService *> compute_services = this->getAvailableComputeServices();',
'',
' if (compute_services.empty()) {',
' WRENCH_INFO("Aborting - No compute services available!");',
' break;',
' }',
'',
' // Run ready tasks with defined scheduler implementation',
' this->getStandardJobScheduler()->scheduleTasks(this->getAvailableComputeServices(), ready_tasks);',
'',
' // Wait for a workflow execution event, and process it',
' try {',
' this->waitForAndProcessNextEvent();',
' } catch (wrench::WorkflowExecutionException &e) {',
' WRENCH_INFO("Error while getting next execution event (%s)... ignoring and trying again",',
' (e.getCause()->toString().c_str()));',
' continue;',
' }',
'',
' if (this->getWorkflow()->isDone()) {',
' break;',
' }',
' }',
'',
' wrench::S4U_Simulation::sleep(10);',
'',
' this->job_manager.reset();',
'',
' return 0;',
'}'
])


def _write_simple_scheduler(project_dir):
logger.debug('Writing src/SimpleScheduler.h example file')
_write_contents(project_dir + '/src/SimpleScheduler.h', [
])


def main():
# Application's arguments
parser = argparse.ArgumentParser(description='Create a skeleton for a WRENCH-based project.')
@@ -247,6 +376,12 @@ def main():
# write CMakeLists.txt
_write_cmakelists(args.project_dir)

# create SimpleWMS
_write_simple_wms(args.project_dir)

# create SimpleScheduler
_write_simple_scheduler(args.project_dir)

# create main.cpp
_write_main(args.project_dir)

0 comments on commit 2896f63

Please sign in to comment.
You can’t perform that action at this time.