ATLAS Offline Software
Loading...
Searching...
No Matches
SlurmDriver.cxx File Reference
#include <EventLoop/SlurmDriver.h>
#include <AsgMessaging/StatusCode.h>
#include <EventLoop/BatchJob.h>
#include <EventLoop/Job.h>
#include <EventLoop/ManagerData.h>
#include <EventLoop/MessageCheck.h>
#include <RootCoreUtils/Assert.h>
#include <RootCoreUtils/ShellExec.h>
#include <TSystem.h>
#include <fstream>
#include <memory>
#include <sstream>

Go to the source code of this file.

Functions

 ClassImp (EL::SlurmDriver) namespace EL

Function Documentation

◆ ClassImp()

ClassImp ( EL::SlurmDriver )
Author
Nils Krumnack

Definition at line 30 of file SlurmDriver.cxx.

33{
34 //****************************************************
35 void SlurmDriver :: testInvariant () const
36 {}
37 //****************************************************
38 SlurmDriver :: SlurmDriver ()
39 {
40 m_b_job_name = false;
41 m_b_account = false;
42 m_b_run_time = false;
43
44 RCU_NEW_INVARIANT (this);
45 }
46 //****************************************************
47 ::StatusCode SlurmDriver ::
48 doManagerStep (Detail::ManagerData& data) const
49 {
50 RCU_READ_INVARIANT (this);
51 using namespace msgEventLoop;
52 ANA_CHECK (BatchDriver::doManagerStep (data));
53 switch (data.step)
54 {
55 case Detail::ManagerStep::batchScriptVar:
56 {
57 data.batchInit = "export PATH LD_LIBRARY_PATH PYTHONPATH";
58 }
59 break;
60
61 case Detail::ManagerStep::submitJob:
62 case Detail::ManagerStep::doResubmit:
63 {
64 auto all_set = m_b_job_name && m_b_account && m_b_run_time;
65 if (!all_set)
66 {
67 ANA_MSG_INFO ("Job Name " << m_job_name);
68 ANA_MSG_INFO ("Account " << m_account);
69 ANA_MSG_INFO ("Run Time " << m_run_time);
70
71 ANA_MSG_ERROR("All parameters need to be set before job can be submitted");
72 return ::StatusCode::FAILURE;
73 }
74
75 if (data.resubmit)
76 {
77 ANA_MSG_ERROR ("resubmission not supported for the Slurm driver");
78 return StatusCode::FAILURE;
79 }
80
81 if (data.batchJobIndices.empty())
82 {
83 ANA_MSG_ERROR ("no job indices to submit");
84 return ::StatusCode::FAILURE;
85 }
86 if (data.batchJobIndices.back() + 1 != data.batchJobIndices.size())
87 {
88 ANA_MSG_ERROR ("submitting a non-contiguous set of job indices is not supported");
89 return ::StatusCode::FAILURE;
90 }
91 const std::size_t njob = data.batchJobIndices.size();
92
93 if(!data.sharedFileSystem)
94 {
95 int status=gSystem->CopyFile("RootCore.par",(data.submitDir+"/submit/RootCore.par").c_str());
96 if(status != 0)
97 {
98 ANA_MSG_ERROR ("failed to copy RootCore.par");
99 return StatusCode::FAILURE;
100 }
101 }
102
103 {
104 std::ofstream file ((data.submitDir + "/submit/submit").c_str());
105
106 file << "#!/bin/bash \n";
107 file << "\n";
108 file << "#SBATCH --job-name=" << m_job_name << "\n";
109 file << "#SBATCH --output=slurm-%j.out\n";
110 file << "#SBATCH --error=slurm-%j.err\n";
111 file << "#SBATCH --account=" << m_account << "\n";
112 if(!m_partition .empty()) file << "#SBATCH --partition=" << m_partition << "\n";
113 file << "#SBATCH --time=" << m_run_time << "\n";
114 if(!m_memory .empty()) file << "#SBATCH --mem=" << m_memory << "\n";
115 if(!m_constraint.empty()) file << "#SBATCH --constraint=" << m_constraint << "\n";
116 file << "\n";
117 file << data.options.castString(Job::optBatchSlurmExtraConfigLines) << "\n";
118 file << "\n";
119 //note: no "\n" at the of this string since this goes as pre-command to the execution of the next line
120 file << data.options.castString(Job::optBatchSlurmWrapperExec);
121 file << "./run ${SLURM_ARRAY_TASK_ID}\n";
122 }
123
124 {
125 std::ostringstream cmd;
126 cmd << "cd " << RCU::Shell::quote (data.submitDir) << "/submit && sbatch --array=0-" << njob-1 << " " << data.options.castString (Job::optSubmitFlags) << " submit";
127 if (gSystem->Exec (cmd.str().c_str()) != 0)
128 {
129 ANA_MSG_ERROR ("failed to execute: " << cmd.str());
130 return StatusCode::FAILURE;
131 }
132 }
133 data.submitted = true;
134 }
135 break;
136
137 default:
138 break;
139 }
140 return ::StatusCode::SUCCESS;
141 }
142
143 //****************************************************
144 void SlurmDriver :: SetJobName(std::string job_name)
145 {
146 m_b_job_name = true;
147 m_job_name = job_name;
148 }
149 void SlurmDriver :: SetAccount(std::string account)
150 {
151 m_b_account = true;
152 m_account = account;
153 }
154 void SlurmDriver :: SetPartition(std::string partition)
155 {
156 m_partition = partition;
157 }
158 void SlurmDriver :: SetRunTime(std::string run_time)
159 {
160 m_b_run_time = true;
161 m_run_time = run_time;
162 }
163 void SlurmDriver :: SetMemory(std::string memory)
164 {
165 m_memory = memory;
166 }
167 void SlurmDriver :: SetConstrain(std::string constraint)
168 {
169 m_constraint = constraint;
170 }
171 //****************************************************
172}
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
#define ANA_CHECK(EXP)
check whether the given expression was successful
static const Attributes_t empty
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
Definition ShellExec.cxx:65
status
Definition merge.py:16
TFile * file