Commit 4b876ed5 authored by Michael Ott's avatar Michael Ott
Browse files

Check whether dcdbslurmjob runs in slurmd context and execute only on first node in nodelist

parent bd79521e
...@@ -95,6 +95,7 @@ void usage() { ...@@ -95,6 +95,7 @@ void usage() {
std::cout << " -i<userid> Numerical user id [default: SLURM_JOB_USER var]" << std::endl; std::cout << " -i<userid> Numerical user id [default: SLURM_JOB_USER var]" << std::endl;
std::cout << " -s<pattern> Nodelist substitution pattern [default: none]" << std::endl; std::cout << " -s<pattern> Nodelist substitution pattern [default: none]" << std::endl;
std::cout << " -m<pattern> Maximum job length in h [default: none]" << std::endl; std::cout << " -m<pattern> Maximum job length in h [default: none]" << std::endl;
std::cout << " -f Force job insert/update [default: no]" << std::endl;
std::cout << std::endl; std::cout << std::endl;
std::cout << " -h This help page" << std::endl; std::cout << " -h This help page" << std::endl;
std::cout << std::endl; std::cout << std::endl;
...@@ -263,10 +264,11 @@ int main(int argc, char** argv) { ...@@ -263,10 +264,11 @@ int main(int argc, char** argv) {
std::string domainId = JOB_DEFAULT_DOMAIN; std::string domainId = JOB_DEFAULT_DOMAIN;
std::string substitution=""; std::string substitution="";
int maxJobLength = -1; int maxJobLength = -1;
bool force = false;
uint64_t ts=0; uint64_t ts=0;
// Defining options // Defining options
const char *opts = "b:q:o:c:u:p:n:t:d:j:i:s:m:h"; const char *opts = "b:q:o:c:u:p:n:t:d:j:i:s:m:fh";
char ret; char ret;
while ((ret = getopt(argc, argv, opts))!=-1) { while ((ret = getopt(argc, argv, opts))!=-1) {
...@@ -349,6 +351,9 @@ int main(int argc, char** argv) { ...@@ -349,6 +351,9 @@ int main(int argc, char** argv) {
case 'm': case 'm':
maxJobLength = std::stoull(optarg); maxJobLength = std::stoull(optarg);
break; break;
case 'f':
force = true;
break;
case 'h': case 'h':
default: default:
usage(); usage();
...@@ -356,6 +361,21 @@ int main(int argc, char** argv) { ...@@ -356,6 +361,21 @@ int main(int argc, char** argv) {
} }
} }
// Check whether we are started by slurmd and are the first node in the nodelist
std::string slurmNodename = getEnv("SLURMD_NODENAME");
std::string slurmNodelist = getEnv("SLURM_JOB_NODELIST");
if (slurmNodelist == "") {
slurmNodelist = getEnv("SLURM_NODELIST");
}
DCDB::NodeList nl;
splitNodeList(slurmNodelist, nl);
if (!force && (slurmNodename.size() > 0)) {
if (slurmNodename != nl.front()) {
std::cout << "Running in slurmd context but not the first node in nodelist. Exiting." << std::endl;
return 0;
}
}
if (hostList.size() == 0) { if (hostList.size() == 0) {
hostList.push_back("localhost"); hostList.push_back("localhost");
} }
...@@ -460,21 +480,18 @@ int main(int argc, char** argv) { ...@@ -460,21 +480,18 @@ int main(int argc, char** argv) {
} }
} }
DCDB::NodeList nl, pnl; DCDB::NodeList pnl;
if (start) { if (start) {
if(nodelist=="") { // Check whether a nodelist was provided as command line argument.
nodelist = getEnv("SLURM_JOB_NODELIST"); // Otherwise we have populated nl above already.
if (nodelist == "") { if(nodelist.size() > 0) {
nodelist = getEnv("SLURM_NODELIST"); splitNodeList(nodelist, nl);
} }
convertNodeList(nl, substitution);
// Getting the whole pack's node list, if necessary // Getting the whole pack's node list, if necessary
if(isPackLeader) { if(isPackLeader) {
pnodelist = getEnv("SLURM_PACK_JOB_NODELIST"); pnodelist = getEnv("SLURM_PACK_JOB_NODELIST");
} }
}
splitNodeList(nodelist, nl);
convertNodeList(nl, substitution);
std::cout << "DOMAINID = " << domainId << std::endl; std::cout << "DOMAINID = " << domainId << std::endl;
std::cout << "JOBID = " << jobId << std::endl; std::cout << "JOBID = " << jobId << std::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment