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
45 }
46
47 ::StatusCode SlurmDriver ::
48 doManagerStep (Detail::ManagerData& data) const
49 {
51 using namespace msgEventLoop;
52 ANA_CHECK (BatchDriver::doManagerStep (data));
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 {
70
71 ANA_MSG_ERROR(
"All parameters need to be set before job can be submitted");
72 return ::StatusCode::FAILURE;
73 }
74
76 {
77 ANA_MSG_ERROR (
"resubmission not supported for the Slurm driver");
78 return StatusCode::FAILURE;
79 }
80
81 if (
data.batchJobIndices.empty())
82 {
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 {
99 return StatusCode::FAILURE;
100 }
101 }
102
103 {
104 std::ofstream
file ((
data.submitDir +
"/submit/submit").c_str());
105
106 file <<
"#!/bin/bash \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";
117 file <<
data.options.castString(Job::optBatchSlurmExtraConfigLines) <<
"\n";
119
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 {
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 {
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 {
166 }
167 void SlurmDriver :: SetConstrain(std::string constraint)
168 {
169 m_constraint = constraint;
170 }
171
172}
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
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...