X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FLauncher%2FLauncher_Job_SALOME.cxx;h=ee2812c1b6f5cae12d61d3d316d198bb928ee3a9;hb=4d57f98cebfdeb55bfcc1a73b698bfe7a36abb4e;hp=fe38e09b6d2cab61a2542fe91600e07075357af1;hpb=17ab24d3f5a6a3f0c0613ff389a73c85cf21b449;p=modules%2Fkernel.git diff --git a/src/Launcher/Launcher_Job_SALOME.cxx b/src/Launcher/Launcher_Job_SALOME.cxx index fe38e09b6..ee2812c1b 100644 --- a/src/Launcher/Launcher_Job_SALOME.cxx +++ b/src/Launcher/Launcher_Job_SALOME.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2009-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2009-2017 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,16 +26,18 @@ #include #endif -#ifdef WNT +#ifdef WIN32 #include #define _chmod chmod #endif +#include + Launcher::Job_SALOME::Job_SALOME() {} Launcher::Job_SALOME::~Job_SALOME() {} -void +void Launcher::Job_SALOME::setResourceDefinition(const ParserResourcesType & resource_definition) { // Check resource_definition @@ -53,27 +55,27 @@ Launcher::Job_SALOME::update_job() #ifdef WITH_LIBBATCH Batch::Parametre params = common_job_params(); params[Batch::EXECUTABLE] = buildSalomeScript(params); - params[Batch::EXCLUSIVE] = true; _batch_job->setParametre(params); #endif } #ifdef WITH_LIBBATCH -std::string +std::string Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) { // parameters std::string work_directory = params[Batch::WORKDIR].str(); - - std::string launch_script = Kernel_Utils::GetTmpDir() + "runSalome_" + _job_file_name + "_" + _launch_date + ".sh"; + std::ostringstream str_pid; + str_pid << ::getpid(); + std::string launch_script = Kernel_Utils::GetTmpDir() + "runSalome_" + _job_file_name + "_" + _launch_date + "-" + str_pid.str() + ".sh"; std::ofstream launch_script_stream; - launch_script_stream.open(launch_script.c_str(), + launch_script_stream.open(launch_script.c_str(), std::ofstream::out -#ifdef WIN32 +#ifdef WIN32 | std::ofstream::binary //rnv: to avoid CL+RF end of line on windows #endif ); - + // Begin of script launch_script_stream << "#!/bin/sh -f" << std::endl; launch_script_stream << "cd " << work_directory << std::endl; @@ -91,35 +93,38 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) launch_script_stream << "if [ \"x$LIBBATCH_NODEFILE\" != \"x\" ]; then " << std::endl; launch_script_stream << "CATALOG_FILE=" << "CatalogResources_" << _launch_date << ".xml" << std::endl; launch_script_stream << "export USER_CATALOG_RESOURCES_FILE=" << "$CATALOG_FILE" << std::endl; - launch_script_stream << "echo '' > $CATALOG_FILE" << std::endl; - launch_script_stream << "echo '' >> $CATALOG_FILE" << std::endl; - launch_script_stream << "cat $LIBBATCH_NODEFILE | sort | uniq -c | while read nbproc host" << std::endl; + launch_script_stream << "{" << std::endl; + launch_script_stream << "echo ''" << std::endl; + launch_script_stream << "echo ''" << std::endl; + launch_script_stream << "sort \"$LIBBATCH_NODEFILE\" | uniq -c | while read nbproc host" << std::endl; launch_script_stream << "do" << std::endl; // Full name doesn't work. eg: sagittaire-7 instead of sagittaire-7.lyon.grid5000.fr - launch_script_stream << "host_basename=$(echo $host | cut -f1 -d.)" << std::endl; - launch_script_stream << "echo '> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo ' userName=\"" << _resource_definition.UserName << "\"' >> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo ' appliPath=\"" << _resource_definition.AppliPath << "\"' >> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo ' mpi=\"" << _resource_definition.getMpiImplTypeStr() << "\"' >> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo ' nbOfNodes='\\\"$nbproc\\\" >> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo ' nbOfProcPerNode=\"1\"' >> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo ' can_run_containers=\"true\"' >> $CATALOG_FILE" << std::endl; - launch_script_stream << "echo '/>' >> $CATALOG_FILE" << std::endl; + launch_script_stream << "host_basename=$(echo \"$host\" | cut -f1 -d.)" << std::endl; + launch_script_stream << "echo ''" << std::endl; launch_script_stream << "done" << std::endl; - launch_script_stream << "echo '' >> $CATALOG_FILE" << std::endl; + launch_script_stream << "echo ''" << std::endl; + launch_script_stream << "} > $CATALOG_FILE" << std::endl; launch_script_stream << "fi" << std::endl; // Create file for ns-port-log - launch_script_stream << "NS_PORT_FILE_PATH=`mktemp " << _resource_definition.AppliPath << "/USERS/nsport_XXXXXX` &&\n"; - launch_script_stream << "NS_PORT_FILE_NAME=`basename $NS_PORT_FILE_PATH` &&\n"; + launch_script_stream << "NS_PORT_FILE_PATH=$(mktemp " << _resource_definition.AppliPath << "/USERS/nsport_XXXXXX) &&\n"; // Launch SALOME with an appli - launch_script_stream << _resource_definition.AppliPath << "/runAppli --terminal --ns-port-log=$NS_PORT_FILE_NAME --server-launch-mode=fork "; + launch_script_stream << _resource_definition.AppliPath << "/salome start --terminal --ns-port-log=\"$NS_PORT_FILE_PATH\" --server-launch-mode=fork "; launch_script_stream << "> logs/salome_" << _launch_date << ".log 2>&1 &&" << std::endl; launch_script_stream << "current=0 &&\n" << "stop=20 &&\n" - << "while ! test -s $NS_PORT_FILE_PATH\n" + << "while ! test -s \"$NS_PORT_FILE_PATH\"\n" << "do\n" << " sleep 2\n" << " current=$((current+1))\n" @@ -128,15 +133,14 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) << " exit\n" << " fi\n" << "done &&\n" - << "appli_port=`cat $NS_PORT_FILE_PATH` &&\n" - << "rm $NS_PORT_FILE_PATH &&\n"; + << "appli_port=$(cat \"$NS_PORT_FILE_PATH\") &&\n" + << "rm \"$NS_PORT_FILE_PATH\" &&\n"; // Call real job type addJobTypeSpecificScript(launch_script_stream); // End - launch_script_stream << _resource_definition.AppliPath << "/runSession -p $appli_port shutdownSalome.py" << std::endl; - launch_script_stream << "sleep 10" << std::endl; + launch_script_stream << _resource_definition.AppliPath << "/salome kill \"$appli_port\"" << std::endl; // Return launch_script_stream.flush(); @@ -145,4 +149,3 @@ Launcher::Job_SALOME::buildSalomeScript(Batch::Parametre params) return launch_script; } #endif -