1 | import os,XDR,shutil |
---|
2 | |
---|
3 | |
---|
4 | DISTANT_UNIX_DIRECTORY = "C3Sm_projects" |
---|
5 | |
---|
6 | class cerfacs_neptune_ssh(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.nbtasks = self.getPluginParam("nbtasks") |
---|
15 | |
---|
16 | self.nbcores = "none" |
---|
17 | if self.nbtasks == "one" : |
---|
18 | self.nbnodes = "1" |
---|
19 | self.nbcores = "1" |
---|
20 | self.nbcores_per_node = "1" |
---|
21 | |
---|
22 | if self.nbtasks == "two" : |
---|
23 | self.nbnodes = "1" |
---|
24 | self.nbcores = "2" |
---|
25 | self.nbcores_per_node = "2" |
---|
26 | |
---|
27 | if self.nbtasks == "four" : |
---|
28 | self.nbnodes = "1" |
---|
29 | self.nbcores = "4" |
---|
30 | self.nbcores_per_node = "4" |
---|
31 | |
---|
32 | if self.nbtasks == "eight" : |
---|
33 | self.nbnodes = "1" |
---|
34 | self.nbcores = "8" |
---|
35 | self.nbcores_per_node = "8" |
---|
36 | |
---|
37 | if self.nbtasks == "sixteen" : |
---|
38 | self.nbnodes = "1" |
---|
39 | self.nbcores = "16" |
---|
40 | self.nbcores_per_node = "16" |
---|
41 | |
---|
42 | if self.nbtasks == "thirtytwo" : |
---|
43 | self.nbnodes = "2" |
---|
44 | self.nbcores = "32" |
---|
45 | self.nbcores_per_node = "16" |
---|
46 | |
---|
47 | if self.nbtasks == "sixtyfour" : |
---|
48 | self.nbnodes = "4" |
---|
49 | self.nbcores = "64" |
---|
50 | self.nbcores_per_node = "16" |
---|
51 | |
---|
52 | if self.nbtasks == "onehundredtwentyeight" : |
---|
53 | self.nbnodes = "8" |
---|
54 | self.nbcores = "128" |
---|
55 | self.nbcores_per_node = "16" |
---|
56 | |
---|
57 | |
---|
58 | if self.nbcores == "none": |
---|
59 | msg_err = "Problem : option nbtasks ="+self.nbtasks+" not recognized in plugin neptune" |
---|
60 | error(msg_err) |
---|
61 | |
---|
62 | |
---|
63 | self.jobname = self.getPluginParam("jobname").replace(" ","_") |
---|
64 | self.dir2send = [] |
---|
65 | self.distantDirectory = self.getPluginParam("directory") |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | # create the DISTANT_UNIX_DIRECTORY on the distant machine |
---|
70 | sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+DISTANT_UNIX_DIRECTORY+""" ] ; then mkdir """+DISTANT_UNIX_DIRECTORY+""" ; fi" """ |
---|
71 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
72 | |
---|
73 | self.distantDirectory = os.path.join(self.distantDirectory,DISTANT_UNIX_DIRECTORY) |
---|
74 | |
---|
75 | # then create the project_name folder if needed |
---|
76 | project_name = XDR.getValue("name","project","meta") |
---|
77 | sshCommand = """bash -c "cd """+self.distantDirectory+"""; if [ ! -d """+project_name+""" ] ; then mkdir """+project_name+""" ; fi" """ |
---|
78 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
79 | |
---|
80 | self.distantDirectory = os.path.join(self.distantDirectory,project_name) |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | |
---|
86 | @XDR.supported_applications(['avsp52','avbp621','avbp70','avtp2','aap','prissma']) |
---|
87 | def executeDistantCommand(self,command,execDirectory,appli, flags=[]): |
---|
88 | |
---|
89 | |
---|
90 | execDir_abspath = os.path.join(self.distantDirectory,execDirectory) |
---|
91 | print "Running executeDistantCommand "+command+" in "+execDirectory+" for appli"+appli |
---|
92 | ######## |
---|
93 | # INITS |
---|
94 | ######## |
---|
95 | command_exe = command |
---|
96 | appli_keyword = "none" |
---|
97 | supported_applis = [] |
---|
98 | local_directory = os.getcwd() |
---|
99 | project_name = XDR.getValue("name","project","meta") |
---|
100 | #project_name = "NOM_PROJET" |
---|
101 | |
---|
102 | # Creating batch file |
---|
103 | batchContent = "#!/bin/bash \n" |
---|
104 | batchContent +="#PBS -N "+self.jobname+" \n" |
---|
105 | batchContent +="#PBS -l walltime=06:00:00 \n" |
---|
106 | batchContent +="#PBS -j oe \n" |
---|
107 | batchContent +="#PBS -l select="+self.nbnodes+":mpiprocs="+self.nbcores_per_node+":ncpus="+self.nbcores_per_node+"\n" |
---|
108 | batchContent +="#PBS -m ae \n" |
---|
109 | |
---|
110 | batchContent +="cat $PBS_NODEFILE \n " |
---|
111 | batchContent +="nb_cpu=$(wc -l < $PBS_NODEFILE)\n" |
---|
112 | |
---|
113 | batchContent +="cd "+execDir_abspath+"\n" |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | # no modification before this line |
---|
119 | ################################################################################################################################ |
---|
120 | ################################################################################################################################ |
---|
121 | ################################################################################################################################ |
---|
122 | |
---|
123 | |
---|
124 | ######## |
---|
125 | # AVSP # |
---|
126 | ######## |
---|
127 | if appli == "avsp52": |
---|
128 | if command == "-c3sm_auto_avsp_exe-": |
---|
129 | batchContent+="module load avsp \n" |
---|
130 | command_exe = "cp /home/rolex/AVSP/avsp53/quiet3.py . ; /usr/bin/python ./quiet3.py &> ./quiet.out" |
---|
131 | avsp_command = "mpirun -np "+self.nbcores+ " /home/rolex/AVSP/avsp53/AVSP_V5.3.NEPTUNE" |
---|
132 | XDR.replace_pattern_in_file(os.path.join(execDirectory,"user_params.py"),"-c3sm_auto_avsp_exe-",avsp_command) |
---|
133 | anozzle_command = "/home/rolex/AVSP/avsp53/Anozzle_NEPTUNE.exe" |
---|
134 | XDR.replace_pattern_in_file(os.path.join(execDirectory,"user_params.py"),"-c3sm_auto_anozzle_exe-",anozzle_command) |
---|
135 | |
---|
136 | ######## |
---|
137 | # AVBP # |
---|
138 | ######## |
---|
139 | if appli == "avbp621": |
---|
140 | #batchContent.append("export LD_LIBRARY_PATH=/home/cfd/avbp/LIBSUPPORT:$LD_LIBRARY_PATH") |
---|
141 | batchContent +="export LD_LIBRARY_PATH=/home/cfd/avbp/LIBSUPPORT:$LD_LIBRARY_PATH\n" |
---|
142 | if command == "-c3sm_auto_avbp_exe-": |
---|
143 | command_exe = "mpirun -np $nb_cpu /home/rolex/AVBP_V6.X/AVBP_D6.2.1/AVBP_V6.2.1_beta.NEPTUNE > avbp_log.txt" |
---|
144 | if appli == "avbp70": |
---|
145 | batchContent +="export LD_LIBRARY_PATH=/home/cfd/avbp/LIBSUPPORT:$LD_LIBRARY_PATH\n" |
---|
146 | if command == "-c3sm_auto_avbp_exe-": |
---|
147 | #command_exe = "mpirun -np $nb_cpu /home/rolex/AVBP_V6.X/AVBP_D7.0/AVBP_V7.0_beta.NEPTUNE > avbp_log.txt" |
---|
148 | command_exe = "mpirun -np $nb_cpu /scratch/cfd/bonhomme/AVBP_D7.0/HOST/NEPTUNE/AVBPEXEC/AVBP_V7.0_beta.NEPTUNE > avbp_log.txt" |
---|
149 | |
---|
150 | |
---|
151 | ######## |
---|
152 | # AVTP # |
---|
153 | ######## |
---|
154 | if appli == "avtp2": |
---|
155 | if command == "-c3sm_auto_avtp_exe-": |
---|
156 | command_exe = "mpirun -np $nb_cpu /home/rolex/AVTP_V2.X/AVTP_V2.X.NEPTUNE > avtp_log.txt" |
---|
157 | |
---|
158 | ########### |
---|
159 | # prissma # |
---|
160 | ########### |
---|
161 | if appli == "prissma": |
---|
162 | if command == "-c3sm_auto_prissma_exe-": |
---|
163 | batchContent+="cp -r /home/rolex/PRISSMA/DATA/SPECTRAL . \n" |
---|
164 | command_exe = "mpirun -np $nb_cpu /home/rolex/PRISSMA/mpiprissma_V3.0.e_NEPTUNE > prissma_log.txt" |
---|
165 | |
---|
166 | |
---|
167 | ####### |
---|
168 | # AAP # |
---|
169 | ####### |
---|
170 | if appli == "aap": |
---|
171 | home_aap = "/home/rolex/AAP/" |
---|
172 | batchContent +="module load compiler/intel mpi/intelmpi \n" |
---|
173 | |
---|
174 | |
---|
175 | ################### |
---|
176 | # AAP : AVBP-AVTP # |
---|
177 | ################### |
---|
178 | if command.startswith("-c3sm_auto_avbp_avtp_exe-") and len(command.split(" ")) == 3: |
---|
179 | palm_main=home_aap+"AVBP_AVTP/"+"palm_main" |
---|
180 | main_avtp=home_aap+"AVBP_AVTP/"+"main_avtp" |
---|
181 | main_avbp=home_aap+"AVBP_AVTP/"+"main_avbp" |
---|
182 | nb_cores_avbp = command.split(" ")[1] |
---|
183 | nb_cores_avtp = command.split(" ")[2] |
---|
184 | batchContent +="export NBPROC_main_avbp="+nb_cores_avbp+" \n" |
---|
185 | batchContent +="export NBPROC_main_avtp="+nb_cores_avtp+" \n" |
---|
186 | batchContent +="cp "+home_aap+"AVBP_AVTP/avbp_avtp.pil . \n" |
---|
187 | command_exe = "mpirun -np 1 "+palm_main+" : -np $NBPROC_main_avtp "+main_avtp+" : -np $NBPROC_main_avbp "+main_avbp+" > cpl_log.txt" |
---|
188 | |
---|
189 | ###################### |
---|
190 | # AAP : PRISSMA-AVBP # |
---|
191 | ###################### |
---|
192 | |
---|
193 | if command.startswith("-c3sm_auto_avbp_prissma_exe-") and len(command.split(" ")) == 3: |
---|
194 | palm_main=home_aap+"AVBP_PRISSMA/"+"palm_main" |
---|
195 | main_prissma=home_aap+"AVBP_PRISSMA/"+"main_prissma" |
---|
196 | main_avbp=home_aap+"AVBP_PRISSMA/"+"main_avbp" |
---|
197 | nb_cores_avbp = command.split(" ")[1] |
---|
198 | nb_cores_prissma = command.split(" ")[2] |
---|
199 | batchContent +="export NBPROC_main_avbp="+nb_cores_avbp+" \n" |
---|
200 | batchContent +="export NBPROC_main_prissma="+nb_cores_prissma+" \n" |
---|
201 | batchContent +="cp "+home_aap+"AVBP_PRISSMA/avbp_prissma.pil . \n" |
---|
202 | batchContent+="cp -r /home/rolex/PRISSMA/DATA/SPECTRAL ./PRISSMA01/ \n" |
---|
203 | command_exe ="mpirun -np 1 "+palm_main+" : -np $NBPROC_main_prissma "+main_prissma+" : -np $NBPROC_main_avbp "+main_avbp+" > cpl_log.txt" |
---|
204 | |
---|
205 | ########################### |
---|
206 | # AAP : AVBP-AVTP-PRISSMA # |
---|
207 | ########################### |
---|
208 | |
---|
209 | if command.startswith("-c3sm_auto_avbp_avtp_prissma_exe-") and len(command.split(" ")) == 4 : |
---|
210 | nb_cores_avbp = command.split(" ")[1] |
---|
211 | nb_cores_avtp = command.split(" ")[2] |
---|
212 | nb_cores_prissma = command.split(" ")[3] |
---|
213 | palm_main=home_aap+"AVBP_AVTP_PRISSMA/"+"palm_main" |
---|
214 | main_prissma=home_aap+"AVBP_AVTP_PRISSMA/"+"main_prissma" |
---|
215 | main_avbp=home_aap+"AVBP_AVTP_PRISSMA/"+"main_avbp" |
---|
216 | main_avtp=home_aap+"AVBP_AVTP_PRISSMA/"+"main_avtp" |
---|
217 | batchContent +="cp "+home_aap+"AVBP_AVTP_PRISSMA/3codescoupling.pil . \n" |
---|
218 | batchContent+="cp -r /home/rolex/PRISSMA/DATA/SPECTRAL ./PRISSMA01/ \n" |
---|
219 | batchContent +="export NBPROC_main_avbp="+nb_cores_avbp+" \n" |
---|
220 | batchContent +="export NBPROC_main_avtp="+nb_cores_avtp+" \n" |
---|
221 | batchContent +="export NBPROC_main_prissma="+nb_cores_prissma+" \n" |
---|
222 | command_exe ="mpirun -np 1 "+palm_main+" : -np $NBPROC_main_avtp "+main_avtp+" : -np $NBPROC_main_prissma "+main_prissma+" : -np $NBPROC_main_avbp "+main_avbp+" > cpl_log.txt" |
---|
223 | |
---|
224 | |
---|
225 | ################################################################################################################################ |
---|
226 | ################################################################################################################################ |
---|
227 | ################################################################################################################################ |
---|
228 | # no modification after this line |
---|
229 | if command_exe.startswith("-c3sm_auto_"): |
---|
230 | XDR.error("command was not understood: "+command_exe ) |
---|
231 | batchContent +=command_exe |
---|
232 | |
---|
233 | |
---|
234 | |
---|
235 | batchFile = open(os.path.join(XDR.getCurrentRun(), "batch_C3Sm_NEPTUNE"), 'w') |
---|
236 | batchFile.write(batchContent) |
---|
237 | batchFile.close() |
---|
238 | |
---|
239 | # create a zip archive of the directories list |
---|
240 | print "Final composition of c3sm_archive:" |
---|
241 | print self.dir2send |
---|
242 | |
---|
243 | XDR.ssh_send(self.machine,self.login, self.distantDirectory, self.dir2send, options="") |
---|
244 | |
---|
245 | sshCommand = "cd {0}; /opt/pbs/default/bin/qsub batch_C3Sm_NEPTUNE".format(execDir_abspath) |
---|
246 | XDR.ssh(self.machine,self.login, sshCommand, options="") |
---|
247 | |
---|
248 | |
---|
249 | |
---|
250 | def retrieveDirectory(self,directory): |
---|
251 | |
---|
252 | local_directory = os.path.abspath(directory) |
---|
253 | dist_directory = os.path.basename(local_directory) |
---|
254 | # Retrieve Directory |
---|
255 | shutil.rmtree(local_directory) |
---|
256 | scpCommand = "scp -pr "+self.login+"@"+self.machine+":"+self.distantDirectory+"/"+dist_directory+" "+os.path.dirname(local_directory) |
---|
257 | |
---|
258 | XDR.execute(scpCommand) |
---|
259 | |
---|
260 | |
---|
261 | def removeDirectory(self,directory): |
---|
262 | if directory == "*": |
---|
263 | sshCommand = """bash -c "cd """+self.distantDirectory+"/.. "+"""; if [ -d """+self.distantDirectory+""" ] ; then rm -r """+self.distantDirectory+""" ; fi" |
---|
264 | """ |
---|
265 | else: |
---|
266 | sshCommand = "rm -rf "+self.distantDirectory+"/"+directory |
---|
267 | |
---|
268 | XDR.execute("ssh "+self.login+"@"+self.machine+" '"+sshCommand+"'") |
---|
269 | |
---|
270 | |
---|