Skip to content
Snippets Groups Projects
Commit e8eec018 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add a simple stop() function to the language

This allows to decide some actions in the script when a stoppage is
manually required.

By now it just checks that the presence of a recent "STOP" file in the
execution directory. A simple use is for instance:
```
  if (stop()) {
    checkpoint_and_exit();
  }
```
parent 0f20b330
No related branches found
No related tags found
1 merge request!199Integrate checkpointing
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <language/utils/UnaryOperatorRegisterForRn.hpp> #include <language/utils/UnaryOperatorRegisterForRn.hpp>
#include <language/utils/UnaryOperatorRegisterForRnxn.hpp> #include <language/utils/UnaryOperatorRegisterForRnxn.hpp>
#include <language/utils/UnaryOperatorRegisterForZ.hpp> #include <language/utils/UnaryOperatorRegisterForZ.hpp>
#include <utils/ExecutionStatManager.hpp>
#include <utils/Messenger.hpp> #include <utils/Messenger.hpp>
#include <utils/PugsUtils.hpp> #include <utils/PugsUtils.hpp>
#include <utils/RandomEngine.hpp> #include <utils/RandomEngine.hpp>
...@@ -144,6 +145,33 @@ CoreModule::CoreModule() : BuiltinModule(true) ...@@ -144,6 +145,33 @@ CoreModule::CoreModule() : BuiltinModule(true)
)); ));
this->_addBuiltinFunction("stop",
std::function(
[]() -> bool {
bool has_stop_file = false;
if (parallel::rank() == 0) {
std::filesystem::path stop_file("STOP");
if (std::filesystem::exists(stop_file)) {
const double elapse_time = ExecutionStatManager::getInstance().getElapseTime();
const double stop_file_age = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now() -
std::chrono::clock_cast<std::chrono::system_clock>(
std::filesystem::last_write_time(stop_file)))
.count();
has_stop_file = elapse_time > stop_file_age;
}
}
parallel::broadcast(has_stop_file, 0);
return has_stop_file;
}
));
this->_addNameValue("cout", ast_node_data_type_from<std::shared_ptr<const OStream>>, this->_addNameValue("cout", ast_node_data_type_from<std::shared_ptr<const OStream>>,
EmbeddedData{std::make_shared<DataHandler<const OStream>>(std::make_shared<OStream>(std::cout))}); EmbeddedData{std::make_shared<DataHandler<const OStream>>(std::make_shared<OStream>(std::cout))});
......
...@@ -161,6 +161,12 @@ ExecutionStatManager::printInfo() ...@@ -161,6 +161,12 @@ ExecutionStatManager::printInfo()
} }
} }
double
ExecutionStatManager::getElapseTime() const
{
return m_elapse_time.seconds();
}
double double
ExecutionStatManager::getCumulativeElapseTime() const ExecutionStatManager::getCumulativeElapseTime() const
{ {
......
...@@ -29,6 +29,8 @@ class ExecutionStatManager ...@@ -29,6 +29,8 @@ class ExecutionStatManager
~ExecutionStatManager() = default; ~ExecutionStatManager() = default;
public: public:
double getElapseTime() const;
double getCumulativeElapseTime() const; double getCumulativeElapseTime() const;
double getCumulativeTotalCPUTime() const; double getCumulativeTotalCPUTime() const;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment