33{
34 void LocalDriver ::
35 testInvariant () const
36 {
38 }
39
40
41
42 LocalDriver ::
43 LocalDriver ()
44 {
46 }
47
48
49
50 ::StatusCode LocalDriver ::
51 doManagerStep (Detail::ManagerData&
data)
const
52 {
54 using namespace msgEventLoop;
57 {
58 case Detail::ManagerStep::batchScriptVar:
59 {
60 data.batchSkipReleaseSetup =
true;
61 }
62 break;
63
64 case Detail::ManagerStep::submitJob:
65 case Detail::ManagerStep::doResubmit:
66 {
67
68
69 const std::string dockerImage {
70 data.options.castString(Job::optDockerImage)};
71 const std::string dockerOptions {
72 data.options.castString(Job::optDockerOptions)};
73 int numParallelProcs
74 =
data.options.castDouble (Job::optNumParallelProcs, 1);
75 if (numParallelProcs < 0)
76 {
77 ANA_MSG_ERROR (
"invalid number of parallel processes: " << numParallelProcs);
78 return StatusCode::FAILURE;
79 }
80
81 std::ostringstream basedirName;
82 basedirName <<
data.submitDir <<
"/tmp";
84 {
85 if (gSystem->MakeDirectory (basedirName.str().c_str()) != 0)
86 RCU_THROW_MSG (
"failed to create directory " + basedirName.str());
87 }
88 auto submitSingle = [&] (std::size_t
index)
noexcept -> StatusCode
89 {
90 try
91 {
94 if (gSystem->MakeDirectory (
dirName.str().c_str()) != 0)
95 {
97 return StatusCode::FAILURE;
98 }
99
100 std::ostringstream
cmd;
102 if (!dockerImage.empty())
106 } catch (std::exception& e)
107 {
109 return StatusCode::FAILURE;
110 }
111 return StatusCode::SUCCESS;
112 };
113 if (numParallelProcs == 1)
114 {
115 for (std::size_t
index :
data.batchJobIndices)
116 {
117 if (submitSingle (
index).isFailure())
118 return StatusCode::FAILURE;
119 }
120 } else
121 {
122 if (numParallelProcs == 0)
123 numParallelProcs = std::thread::hardware_concurrency();
124 if (numParallelProcs >
int (
data.batchJobIndices.size()))
125 numParallelProcs =
data.batchJobIndices.size();
126 std::vector<std::thread>
threads;
128 auto indexIter =
data.batchJobIndices.begin();
129 bool abort = false;
131 {
132 threads.emplace_back ([&] ()
noexcept
133 {
134 std::unique_lock<std::mutex> lock (
mutex);
135 while (indexIter !=
data.batchJobIndices.end() && !abort)
136 {
137 auto myindex = *indexIter;
138 ++ indexIter;
139 lock.unlock();
140 if (submitSingle (myindex).isFailure())
141 {
142 abort = true;
143 return;
144 }
145 lock.lock ();
146 }
147 });
148 }
149 for (auto& thread : threads)
150 thread.join();
151 if (abort)
152 return StatusCode::FAILURE;
153 }
154 data.submitted =
true;
155 }
156 break;
157
158 default:
159 break;
160 }
161 return ::StatusCode::SUCCESS;
162 }
163}
#define RCU_NEW_INVARIANT(x)
#define RCU_READ_INVARIANT(x)
char data[hepevt_bytes_allocation_ATLAS]
#define RCU_THROW_MSG(message)
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...