ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
PhysicsAnalysis
D3PDTools
EventLoop
Root
SlurmDriver.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3
*/
4
6
7
8
//
9
// includes
10
//
11
12
#include <
EventLoop/SlurmDriver.h
>
13
14
#include <
AsgMessaging/StatusCode.h
>
15
#include <
EventLoop/BatchJob.h
>
16
#include <
EventLoop/Job.h
>
17
#include <
EventLoop/ManagerData.h
>
18
#include <
EventLoop/MessageCheck.h
>
19
#include <
RootCoreUtils/Assert.h
>
20
#include <
RootCoreUtils/ShellExec.h
>
21
#include <TSystem.h>
22
#include <fstream>
23
#include <memory>
24
#include <sstream>
25
26
//
27
// method implementations
28
//
29
30
ClassImp
(
EL::SlurmDriver
)
31
32
namespace
EL
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
}
Assert.h
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition
Assert.h:221
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition
Assert.h:217
BatchJob.h
ANA_MSG_ERROR
#define ANA_MSG_ERROR(xmsg,...)
Macro printing error messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:295
ANA_MSG_INFO
#define ANA_MSG_INFO(xmsg,...)
Macro printing info messages.
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:291
ANA_CHECK
#define ANA_CHECK(EXP)
check whether the given expression was successful
Definition
Control/AthToolSupport/AsgMessaging/AsgMessaging/MessageCheck.h:325
StatusCode.h
Job.h
ManagerData.h
MessageCheck.h
ShellExec.h
ClassImp
ClassImp(EL::SlurmDriver) namespace EL
Definition
SlurmDriver.cxx:30
SlurmDriver.h
empty
static const Attributes_t empty
Definition
XmlStreamer.cxx:16
EL::BatchDriver::doManagerStep
virtual::StatusCode doManagerStep(Detail::ManagerData &data) const override
EL::Job::optSubmitFlags
static const std::string optSubmitFlags
description: the name of the option for supplying extra submit parameters to batch systems rationale:...
Definition
Job.h:292
EL::Job::optBatchSlurmWrapperExec
static const std::string optBatchSlurmWrapperExec
Append a command before the main executable is called This is useful is you want to execute the comma...
Definition
Job.h:514
EL::Job::optBatchSlurmExtraConfigLines
static const std::string optBatchSlurmExtraConfigLines
The content of this string will be executed in the job script on the worker node before the main exec...
Definition
Job.h:511
EL::SlurmDriver
a Driver for running on SLURM batch systems
Definition
SlurmDriver.h:21
EL::Detail::ManagerStep::doResubmit
@ doResubmit
call the actual doResubmit method
Definition
ManagerStep.h:116
EL::Detail::ManagerStep::submitJob
@ submitJob
do the actual job submission
Definition
ManagerStep.h:92
EL::Detail::ManagerStep::batchScriptVar
@ batchScriptVar
create the variables needed for the batch-run script
Definition
ManagerStep.h:83
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition
AsgComponentFactories.h:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition
PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
RCU::Shell::quote
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
file
TFile * file
Definition
tile_monitor.h:29
Generated on
for ATLAS Offline Software by
1.17.0