source: CPL/oasis3-mct/branches/OASIS3-MCT_2.0_branch/util/oasisgui/library/DATA/pluginscripts/unix_neptune.py @ 4775

Last change on this file since 4775 was 4775, checked in by aclsce, 5 years ago
  • Imported oasis3-mct from Cerfacs svn server (not suppotred anymore).

The version has been extracted from https://oasis3mct.cerfacs.fr/svn/branches/OASIS3-MCT_2.0_branch/oasis3-mct@1818

File size: 9.3 KB
Line 
1import os,XDR,shutil
2
3
4DISTANT_UNIX_DIRECTORY = "C3Sm_projects"
5
6class unix_neptune(XDR.Plugin):
7    def __init__(self,typePlugin):
8        XDR.Plugin.__init__(self, typePlugin)
9       
10        print "Using  neptune plugin, check in terminal if password is asked"
11       
12        self.login = self.getPluginParam("login")
13        self.machine = "neptune"
14        self.nbnodes = self.getPluginParam("nbnodes")
15        self.dir2send = []
16        self.distantDirectory = self.getPluginParam("directory")
17       
18        # create the DISTANT_UNIX_DIRECTORY on the distant machine
19        sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+DISTANT_UNIX_DIRECTORY+""" ] ; then mkdir """+DISTANT_UNIX_DIRECTORY+""" ; fi" """
20        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
21       
22        self.distantDirectory = os.path.join(self.distantDirectory,DISTANT_UNIX_DIRECTORY)
23       
24        # then create the project_name folder if needed
25        project_name = XDR.getValue("name","project","meta")
26        sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+project_name+""" ] ; then mkdir """+project_name+""" ; fi" """   
27        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
28       
29        self.distantDirectory = os.path.join(self.distantDirectory,project_name)
30   
31    def sendDirectory(self,directory):
32
33       
34        local_directory = os.path.abspath(directory)
35        directory_basename = os.path.basename(local_directory)
36       
37        if os.path.exists(local_directory):
38            pass
39        else:
40            raise Exception("Error : "+directory+" doesn't exist")
41        # Je te met un exemple avec un scp (avec account et machine definis dans le init:
42        self.dir2send.append(directory)
43        print "Adding "+directory +" to the list of folders for the archive"
44        print self.dir2send
45     
46        #XDR.execute("scp -pr "+local_directory+" "+self.login+"@"+self.machine+":"+self.distantDirectory + "/")
47       
48       
49    def executeDistantCommand(self,command,execDirectory,appli, flags=[]):       
50       
51        execDir_abspath = os.path.join(self.distantDirectory,execDirectory)
52       
53        print "Running executeDistantCommand "+command+" in "+execDirectory+" for appli"+appli
54        ########
55        # INITS
56        ########
57        command_exe = command
58        appli_keyword = "none"
59        supported_applis = []
60        local_directory = os.getcwd()
61        project_name = XDR.getValue("name","project","meta")
62        #project_name = "NOM_PROJET"
63       
64       
65        # Creating batch file
66        batchContent =  """#!/bin/bash
67#PBS -N C3Smjob
68#PBS -l walltime=06:00:00
69#PBS -j oe
70#PBS -l select="""+self.getPluginParam("nbnodes")+"""
71#PBS -m ae
72
73cat \$PBS_NODEFILE
74nb_cpu=\$(wc -l < \$PBS_NODEFILE)
75
76       
77cd """+execDir_abspath+"""
78"""       
79       
80        #####################
81        # SECTION DEPENDING ON APPLICATIONS
82        ####################
83        supported_applis.append("avsp52") 
84        supported_applis.append("avbp621")
85        supported_applis.append("avbp70")
86        supported_applis.append("avtp2")
87        supported_applis.append("aap01")
88        if appli not in supported_applis:
89            XDR.error("this application requires the application tag "+ appli+ ", which is not supported by the plugin unix_neptune.")
90            return
91               
92               
93                   
94        ########
95        # AVSP #
96        ########
97        if appli == "avsp52":
98            if command == "-c3sm_auto_avsp_exe-":
99                command_exe = "cd "+ execDir_abspath+" ; cp /home/rolex/AVSP/avsp53/quiet3.py . ; /usr/bin/python ./quiet3.py &> ./quiet.out"
100                avsp_command = "mpirun -np "+self.nbnodes+ " /home/rolex/AVSP/avsp53/AVSP_V5.3.CORAIL"
101                XDR.replace_pattern_in_file(os.path.join(execDirectory,"user_params.py"),"-c3sm_auto_avsp_exe-",avsp_command)
102                anozzle_command = "/home/rolex/AVSP/avsp53/Anozzle_CORAIL.exe"
103                XDR.replace_pattern_in_file(os.path.join(execDirectory,"user_params.py"),"-c3sm_auto_anozzle_exe-",anozzle_command)
104                   
105        ########
106        # AVBP #
107        ########
108        if appli == "avbp621":
109            if command == "-c3sm_auto_avbp_exe-":
110                command_exe = "/home/rolex/AVBP_V6.X/AVBP_D6.2.1/AVBP_V6.2.1_beta.NEPTUNE > avbp_log.txt"
111
112        if appli == "avbp70":
113            if command == "-c3sm_auto_avbp_exe-":
114                command_exe = "/home/rolex/AVBP_V6.X/AVBP_D7.0/AVBP_V7.0_beta.NEPTUNE > avbp_log.txt"               
115        ########
116        # AVTP #
117        ########
118        if appli == "avtp2":
119            if command == "-c3sm_auto_avtp_exe-":
120                command_exe = "/home/rolex/AVTP_V2.X/AVTP_V2.X.NEPTUNE > avtp_log.txt"
121               
122               
123        ###################
124        # AAP : AVBP-AVTP #
125        ###################
126        if appli == "aap01":
127            if command == "-c3sm_auto_aap_exe-":
128                batchContent +="""
129module load compiler/intel mpi/intelmpi
130
131export NBPROC_main_avtp="""+self.getPluginParam("nbcavtp")+"""
132export NBPROC_main_avbp="""+self.getPluginParam("nbcavbp")+"""
133palm_main=/home/rolex/AAP/AVBP_AVTP/palm_main
134main_avtp=/home/rolex/AAP/AVBP_AVTP/main_avtp
135main_avbp=/home/rolex/AAP/AVBP_AVTP/main_avbp
136cp /home/rolex/AAP/AVBP_AVTP/avbp_avtp.pil .
137"""
138                command_exe = " -np 1 \$palm_main : -np \$NBPROC_main_avtp \$main_avtp : -np \$NBPROC_main_avbp \$main_avbp > cpl_log.txt" 
139       
140        ######################
141        # AAP : AVBP-PRISSMA #
142        ######################
143        if appli == "aap02":
144            if command == "-c3sm_auto_aap_exe-":
145                batchContent +="""
146module load compiler/intel mpi/intelmpi
147
148export NBPROC_main_prissma="""+self.getPluginParam("nbcprissma")+"""
149export NBPROC_main_avbp="""+self.getPluginParam("nbcavbp")+"""
150palm_main=/home/rolex/AAP/AVBP_AVTP/palm_main
151main_avtp=/home/rolex/AAP/AVBP_AVTP/main_prissma
152main_avbp=/home/rolex/AAP/AVBP_AVTP/main_avbp
153cp /home/rolex/AAP/AVBP_AVTP/avbp_prissma.pil .
154"""
155                command_exe = " -np 1 \$palm_main : -np \$NBPROC_main_prissma \$main_prissma : -np \$NBPROC_main_avbp \$main_avbp > cpl_log.txt" 
156       
157        ###########################
158        # AAP : AVBP-AVTP-PRISSMA #
159        ###########################
160        if appli == "aap03":
161            if command == "-c3sm_auto_aap_exe-":
162                batchContent +="""
163module load compiler/intel mpi/intelmpi
164
165export NBPROC_main_prissma="""+self.getPluginParam("nbcprissma")+"""
166export NBPROC_main_avbp="""+self.getPluginParam("nbcavbp")+"""
167export NBPROC_main_avtp="""+self.getPluginParam("nbcavtp")+"""
168palm_main=/home/rolex/AAP/AVBP_AVTP/palm_main
169main_avtp=/home/rolex/AAP/AVBP_AVTP/main_avtp
170main_avbp=/home/rolex/AAP/AVBP_AVTP/main_avbp
171main_avtp=/home/rolex/AAP/AVBP_AVTP/main_prissma
172cp /home/rolex/AAP/AVBP_AVTP/avbp_avtp_prissma.pil .
173"""
174                command_exe = " -np 1 \$palm_main : -np \$NBPROC_main_prissma \$main_prissma : -np \$NBPROC_main_avtp \$main_avtp : -np \$NBPROC_main_avbp \$main_avbp > cpl_log.txt" 
175
176
177        if appli == "avbp621":
178            batchContent +="""export LD_LIBRARY_PATH=/home/cfd/avbp/LIBSUPPORT:$LD_LIBRARY_PATH"""+"\n"
179        batchContent+="mpirun "+command_exe+"\n"
180
181        if appli == "avbp70":
182            batchContent +="""export LD_LIBRARY_PATH=/home/cfd/avbp/LIBSUPPORT:$LD_LIBRARY_PATH"""+"\n"
183        batchContent+="mpirun "+command_exe+"\n"       
184     
185       
186        # create a zip archive of the directories list
187        print "Final composition of c3sm_archive:"
188        print self.dir2send
189        #print "tar -cvf c3sm_archive.tar "+" ".join(self.dir2send)
190        XDR.execute("tar -cvf c3sm_archive.tar "+" ".join(self.dir2send))
191       
192        #sending archive
193        print "Sending archive..."
194        XDR.execute("scp -pr c3sm_archive.tar "+self.login+"@"+self.machine+":"+self.distantDirectory + "/")
195       
196        # extract archive
197       
198        sshCommand = "cd "+self.distantDirectory+" ; tar -xvf "+os.path.join(self.distantDirectory,"c3sm_archive.tar")
199        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
200       
201       
202        sshCommand = """cd """+execDir_abspath+"""; echo " """+batchContent+""" " > batch_C3Sm_neptune ; qsub batch_C3Sm_neptune"""
203        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
204       
205        # back to the initial directory
206        os.chdir(local_directory)
207       
208    def retrieveDirectory(self,directory):
209       
210        local_directory = os.path.abspath(directory)
211        dist_directory = os.path.basename(local_directory)
212        # Retrieve Directory
213        shutil.rmtree(local_directory)
214        scpCommand = "scp -pr "+self.login+"@"+self.machine+":"+self.distantDirectory+"/"+dist_directory+" "+os.path.dirname(local_directory)
215   
216        XDR.execute(scpCommand)
217       
218       
219    def removeDirectory(self,directory):
220        if directory == "*":
221            sshCommand = """bash -c "cd """+self.distantDirectory+"/.. "+"""; if [ -d """+self.distantDirectory+""" ] ; then rm -r """+self.distantDirectory+""" ; fi"
222            """
223        else:
224            sshCommand = "rm -rf "+self.distantDirectory+"/"+directory
225           
226        XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'")
227       
228   
Note: See TracBrowser for help on using the repository browser.