Initial commit
This commit is contained in:
Executable
+55
@@ -0,0 +1,55 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wfr/common/types/WfsTypes.h>
|
||||
#include <wfr/common/exceptions/exceptions.h>
|
||||
#include <wfr/common/resource/ResourceCapabilities.h>
|
||||
#include <boost/format.hpp>
|
||||
#include <initializer_list>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace wfr {
|
||||
namespace utils {
|
||||
|
||||
typedef std::initializer_list<std::pair<std::string, std::string>> PropertyList;
|
||||
|
||||
|
||||
class Properties {
|
||||
private:
|
||||
std::map<std::string, std::string> properties;
|
||||
|
||||
public:
|
||||
Properties() {}
|
||||
Properties(PropertyList props) {
|
||||
for (auto i : props) {
|
||||
properties.insert(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool hasProperty(const std::string& key) const noexcept {
|
||||
return properties.find(key) != properties.end();
|
||||
}
|
||||
|
||||
const std::string& getProperty(const std::string& key) const {
|
||||
auto i = properties.find(key);
|
||||
if (i != properties.end()) {
|
||||
return i->second;
|
||||
} else {
|
||||
throw exception::wfr_not_found((boost::format("Property \"%1%\" not found.") % key).str());
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<std::string, std::string>& getProperties() const {
|
||||
return properties;
|
||||
}
|
||||
|
||||
void addProperty(const std::string& key, const std::string& value) noexcept {
|
||||
properties[key] = value;
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace utils */
|
||||
} /* namespace wfr */
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
/* Precompiled boost was not compiled with -std=c++11 */
|
||||
#define BOOST_NO_CXX11_SCOPED_ENUMS
|
||||
|
||||
#include <wfr/common/wfs/ActivityInstance.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
|
||||
namespace wfr {
|
||||
|
||||
namespace filesystem {
|
||||
|
||||
|
||||
boost::filesystem::path createWorkingFolder(wfr::wfs::ActivityInstance& instance);
|
||||
boost::filesystem::path createWorkingFolder(std::string name);
|
||||
|
||||
boost::filesystem::path createFolder(wfr::wfs::ActivityInstance& instance, boost::filesystem::path pdir, std::string fname);
|
||||
|
||||
void copy_file(const boost::filesystem::path& from, const boost::filesystem::path& to,
|
||||
boost::filesystem::copy_option::enum_type option = boost::filesystem::copy_option::enum_type::overwrite_if_exists);
|
||||
|
||||
|
||||
} // end namespace filesystem
|
||||
} // end namespace wfr
|
||||
|
||||
@@ -0,0 +1,268 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <wfr/common/types/WfsTypes.h>
|
||||
#include <wfr/common/types/WfrTypes.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
|
||||
namespace wfr {
|
||||
namespace print {
|
||||
|
||||
|
||||
inline std::string toString(const wfs::WorkflowStatus& status) {
|
||||
std::string retval;
|
||||
switch (status) {
|
||||
case wfs::WorkflowStatus::Unknown:
|
||||
retval = "Unknown";
|
||||
break;
|
||||
case wfs::WorkflowStatus::Created:
|
||||
retval = "Created";
|
||||
break;
|
||||
case wfs::WorkflowStatus::Initialized:
|
||||
retval = "Initialized";
|
||||
break;
|
||||
case wfs::WorkflowStatus::Running:
|
||||
retval = "Running";
|
||||
break;
|
||||
case wfs::WorkflowStatus::Finished:
|
||||
retval = "Finished";
|
||||
break;
|
||||
case wfs::WorkflowStatus::Error:
|
||||
retval = "Error";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown Status>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
inline std::string toString(const wfs::ActivityStatus& status) {
|
||||
std::string retval;
|
||||
switch (status) {
|
||||
case wfs::ActivityStatus::Unknown:
|
||||
retval = "Unknown";
|
||||
break;
|
||||
case wfs::ActivityStatus::Created:
|
||||
retval = "Created";
|
||||
break;
|
||||
case wfs::ActivityStatus::Initialized:
|
||||
retval = "Initialized";
|
||||
break;
|
||||
case wfs::ActivityStatus::Running:
|
||||
retval = "Running";
|
||||
break;
|
||||
case wfs::ActivityStatus::Finished:
|
||||
retval = "Finished";
|
||||
break;
|
||||
case wfs::ActivityStatus::Error:
|
||||
retval = "Error";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown Status>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
inline std::string toString(const wfs::ActivityInstanceStatus& status) {
|
||||
std::string retval;
|
||||
switch (status) {
|
||||
case wfs::ActivityInstanceStatus::Unknown:
|
||||
retval = "Unknown";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Created:
|
||||
retval = "Created";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Initialized:
|
||||
retval = "Initialized";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::WaitingForData:
|
||||
retval = "WaitingForData";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::WaitingForDependency:
|
||||
retval = "WaitingForDependency";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::ReadyForExecution:
|
||||
retval = "ReadyForExecution";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Scheduled:
|
||||
retval = "Scheduled";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Queued:
|
||||
retval = "Queued";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::WaitingForFreeResources:
|
||||
retval = "WaitingForFreeResources";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Running:
|
||||
retval = "Running";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Error:
|
||||
retval = "Error";
|
||||
break;
|
||||
case wfs::ActivityInstanceStatus::Finished:
|
||||
retval = "Finished";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown Status>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
inline std::string toString(const wfs::ComputingResourceStatus& status) {
|
||||
std::string retval;
|
||||
switch (status) {
|
||||
case wfs::ComputingResourceStatus::Unknown:
|
||||
retval = "Unknown";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::Created:
|
||||
retval = "Created";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::Idle:
|
||||
retval = "Idle";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::Sleep:
|
||||
retval = "Sleep";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::WokenUp:
|
||||
retval = "WokenUp";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::Busy:
|
||||
retval = "Busy";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::ExecutingTask:
|
||||
retval = "ExecutingTask";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::FinishedTask:
|
||||
retval = "FinishedTask";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::Shutdown:
|
||||
retval = "Shutdown";
|
||||
break;
|
||||
case wfs::ComputingResourceStatus::Error:
|
||||
retval = "Error";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown Status>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
inline std::string toString(const wfs::ActivityImplementationType& type) {
|
||||
std::string retval;
|
||||
switch (type) {
|
||||
case wfs::ActivityImplementationType::PThread:
|
||||
retval = "PThread";
|
||||
break;
|
||||
case wfs::ActivityImplementationType::OpenMP:
|
||||
retval = "OpenMP";
|
||||
break;
|
||||
case wfs::ActivityImplementationType::OpenCL:
|
||||
retval = "OpenCL";
|
||||
break;
|
||||
case wfs::ActivityImplementationType::CUDA:
|
||||
retval = "CUDA";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown Device>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
inline std::string toString(const wfs::ComponentType& type) {
|
||||
std::string retval;
|
||||
switch (type) {
|
||||
case wfs::ComponentType::Unknown:
|
||||
retval = "Unknown";
|
||||
break;
|
||||
case wfs::ComponentType::Enactment:
|
||||
retval = "Enactment";
|
||||
break;
|
||||
case wfs::ComponentType::Scheduler:
|
||||
retval = "Scheduler";
|
||||
break;
|
||||
case wfs::ComponentType::ExecutionLayer:
|
||||
retval = "ExecutionLayer";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown Type>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
inline std::string toString(const wfs::ComponentStatus& state) {
|
||||
std::string retval;
|
||||
switch (state) {
|
||||
case wfs::ComponentStatus::Unknown:
|
||||
retval = "Unknown";
|
||||
break;
|
||||
case wfs::ComponentStatus::Idle:
|
||||
retval = "Idle";
|
||||
break;
|
||||
case wfs::ComponentStatus::Busy:
|
||||
retval = "Busy";
|
||||
break;
|
||||
case wfs::ComponentStatus::Finished:
|
||||
retval = "Finished";
|
||||
break;
|
||||
case wfs::ComponentStatus::Error:
|
||||
retval = "Error";
|
||||
break;
|
||||
default:
|
||||
retval = "<<Unknown State>>";
|
||||
break;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
inline std::string toString(const wfs::ActivityType& type) {
|
||||
switch (type) {
|
||||
case wfs::ActivityType::Atomic:
|
||||
return "Atomic";
|
||||
case wfs::ActivityType::Conditional:
|
||||
return "Conditional";
|
||||
case wfs::ActivityType::Container:
|
||||
return "Container";
|
||||
case wfs::ActivityType::ForLoop:
|
||||
return "ForLoop";
|
||||
case wfs::ActivityType::WhileLoop:
|
||||
return "WhileLoop";
|
||||
case wfs::ActivityType::Unknown:
|
||||
return "Unknown";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return "<<Unknown Type>>";
|
||||
}
|
||||
|
||||
|
||||
inline std::string toString(const wfr_timestamp_sc_t& timestamp) {
|
||||
std::stringstream ss;
|
||||
std::time_t time = std::chrono::system_clock::to_time_t(timestamp);
|
||||
std::tm* tm_time = std::localtime(&time);
|
||||
char temp[30];
|
||||
std::strftime(temp, sizeof(temp), "%d.%m.%Y %H:%M:", tm_time);
|
||||
ss << temp;
|
||||
std::chrono::duration<double> msecs = timestamp - std::chrono::system_clock::from_time_t(time) + std::chrono::seconds(tm_time->tm_sec);
|
||||
ss << std::fixed << std::setw(9) << std::setfill('0') << msecs.count();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
|
||||
} /* namespace print */
|
||||
} /* namespace wfr */
|
||||
Executable
+216
@@ -0,0 +1,216 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <wfr/common/types/LwdTypes.h>
|
||||
#include <wfr/common/wfs/ActivityInstance.h>
|
||||
#include <wfr/common/wfs/instances/LoopActivityInstance.h>
|
||||
|
||||
namespace wfr {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy port values.
|
||||
*
|
||||
* Generic case
|
||||
**/
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(C& dest, const C& src) {
|
||||
if ( !dest.isReady() && src.isReady() ) {
|
||||
dest = src;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(C& dest, const lwd::_lwd_member_type<C>& src) {
|
||||
if ( !dest.isReady() && src.getValue().isReady() ) {
|
||||
dest = src.getValue();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy port values.
|
||||
*
|
||||
* Specialised cases for loop ports.
|
||||
**/
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(lwd::_lwd_loop_port<C>& dest, const C& src, const wfr_size_t& nextIter) {
|
||||
if ( src.isReady() && dest.getNextIterationID() < nextIter ) {
|
||||
dest.setValue(src.getValue());
|
||||
dest.setNextIterationID(nextIter);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(C& dest, const lwd::_lwd_loop_port<C>& src, const wfr_id_t& iterationID) {
|
||||
if ( !dest.isReady() && src.getNextIterationID()-1 == iterationID ) {
|
||||
dest.setValue(src.getValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Copy port values.
|
||||
*
|
||||
* Specialised cases for collections.
|
||||
**/
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, 1>& dest, const C& src, const wfr_id_t& index) {
|
||||
if (dest.getSize() <= index || !dest.getEntry(index).isReady()) {
|
||||
dest.setEntryValue(index, src);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, 1>& dest, const lwd::_lwd_member_type<C>& src, const wfr_id_t& index) {
|
||||
if ((dest.getSize() <= index || !dest.getEntry(index).isReady()) && src.isReady() ) {
|
||||
dest.setEntryValue(index, src.getValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C, wfr_size_t N>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N-1>& src, const wfr_id_t& index) {
|
||||
if (dest.getSize() <= index || !dest.getEntry(index).isReady()) {
|
||||
dest.setEntryValue(index, src);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C, wfr_size_t N>
|
||||
inline bool portbuffer_copy(lwd::iwir_collection<C, N>& dest, const lwd::_lwd_member_type<lwd::iwir_collection<C, N-1>>& src, const wfr_id_t& index) {
|
||||
if ((dest.getSize() <= index || !dest.getEntry(index).isReady()) && src.isReady() ) {
|
||||
dest.setEntryValue(index, src.getValue());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template<class C, wfr_size_t N, wfr_size_t F>
|
||||
struct collection_flatten {
|
||||
inline wfr_size_t operator()(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N+F-1>& src, const wfr_id_t& index) {
|
||||
wfr_size_t retval = 0;
|
||||
for (wfr_size_t i = 0; i < src.getSize(); i++) {
|
||||
retval += collection_flatten<C, N, F-1>()(dest, src.getEntryValue(i), index + retval);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
};
|
||||
|
||||
template<class C, wfr_size_t N>
|
||||
struct collection_flatten<C, N, 1> {
|
||||
inline wfr_size_t operator()(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N>& src, const wfr_id_t& index) {
|
||||
for (wfr_size_t i = 0; i < src.getSize(); i++) {
|
||||
if (dest.getSize() <= index+i || !dest.getEntryStatus(index + i)) {
|
||||
dest.setEntryValue(index + i, src.getEntryValue(i));
|
||||
}
|
||||
}
|
||||
return src.getSize();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<wfr_size_t F, class C, wfr_size_t N>
|
||||
inline wfr_size_t portbuffer_copy_flatten(lwd::iwir_collection<C, N>& dest, const lwd::iwir_collection<C, N+F-1>& src, const wfr_id_t& index = 0) {
|
||||
if (!dest.isReady() && src.isReady()) {
|
||||
return collection_flatten<C, N, F>()(dest, src, index);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the predecessor with the given index has finished execution.
|
||||
**/
|
||||
inline bool wfr_pred_isfinished(const wfs::ActivityInstance& instance, const wfr_id_t& predIndex) {
|
||||
auto predname = instance.getPredecessors()[predIndex];
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::Finished;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the predecessor with the given index is ready-for-execution.
|
||||
**/
|
||||
inline bool wfr_pred_isReady(const wfr::wfs::ActivityInstance& instance, const wfr_id_t& predIndex) {
|
||||
auto predname = instance.getPredecessors()[predIndex];
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::ReadyForExecution;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the previous loop iteration has finished execution.
|
||||
**/
|
||||
inline bool wfr_previter_isfinished(const wfr::wfs::ActivityInstance& loopinstance, const wfr_id_t& currentIterID) {
|
||||
if (currentIterID == 0) {
|
||||
return true;
|
||||
} else {
|
||||
return loopinstance.as<wfr::wfs::LoopActivityInstance>().hasIterationFinished(currentIterID -1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the parent activity is ready-for-execution.
|
||||
**/
|
||||
inline bool wfr_parent_isReady(const wfr::wfs::ActivityInstance& instance) {
|
||||
auto predname = instance.getParentActivity();
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::ReadyForExecution;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether the parent activity has finished execution.
|
||||
**/
|
||||
inline bool wfr_parent_isfinished(const wfr::wfs::ActivityInstance& instance) {
|
||||
auto predname = instance.getParentActivity();
|
||||
if (predname != nullptr) {
|
||||
return predname->getInstanceStatus() == wfr::wfs::ActivityInstanceStatus::Finished;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // end namespace wfr
|
||||
Reference in New Issue
Block a user