PyXMake Developer Guide 1.0
PyXMake
Loading...
Searching...
No Matches
ssh_make.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Minimum working example for PyXMake.
7
8@note: Compile the complete MCODAC library for ABAQUS remotely.
9Created on 25.06.2018
10
11@version: 1.0
12----------------------------------------------------------------------------------------------
13@requires:
14 - PyXMake
15 - Adopt Paths.log according to your system settings.
16
17@change:
18 -
19
20@author: garb_ma [DLR-FA,STM Braunschweig]
21----------------------------------------------------------------------------------------------
22"""
23import os, sys
24import posixpath
25import argparse
26
27try:
28 import PyXMake as _
29except ImportError:
30 # Script is executed as a plug-in
31 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
32finally:
33 from PyXMake.Build import Make as pyx #@UnresolvedImport
34 from PyXMake.Tools import Utility #@UnresolvedImport
35 from PyXMake import VTL #@UnresolvedImport
36
37# Predefined script local variables
38__user = os.getenv("username","")
39__mcd_cluster_dev = posixpath.join(Utility.AsDrive("home",posixpath.sep),__user,"mcodac")
40__mcd_cluster_incpath = posixpath.join(__mcd_cluster_dev,"include")
41__mcd_cluster_libpath = posixpath.join(__mcd_cluster_dev,"lib")
42
43try:
44 # Import PyCODAC to build library locally during setup.
45 from PyCODAC.Tools.Utility import GetPyCODACPath
46 # Import and set local path to PyCODAC
47 __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
48except ImportError:
49 # This script is not executed as plug-in
50 __mcd_core_path = ""
51except:
52 # Something else went wrong.
53 from PyXMake.Tools import ErrorHandling
55
56def main(BuildID,user, key,
57 # Source and feature paths
58 path2src=os.path.join(__mcd_core_path,"src"),
59 path2feature=os.path.join(__mcd_core_path,"solver"),
60 # Build MCODAC by default
61 files=VTL.GetSourceCode(0),
62 # Feature source code file
63 source_file="mcd_astandard.f",
64 # Build feature (supported FE program)
65 version="abq2019", makeopt=0,
66 # Local scratch folder
67 scratch=VTL.Scratch,
68 # Additional dependencies on the institute cluster
69 dependency=posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","mcodac","stable"), verbosity=2,
70 # Host and port number. Access DLR's institute cluster by default.
71 host="129.247.54.37", port=22,
72 # Additional keyword arguments
73 **kwargs):
74 """
75 Main function to execute the script.
76 """
77 # Program start
78 print('==================================')
79 print('Starting build process on the institute cluster')
80 print('==================================')
81
82 # MCODAC compiler command on Linux.
83 pyx_comp = VTL.GetBuildCommand(5)
84
85 # Custom shared library build & linker commands (depending on ABAQUS, ANSYS, NASTRAN etc.)
86 if makeopt == 0:
87 pyx_make = posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","abaqus","Commands", version)
88 pyx_post = "function ifort() { $pyx_ifort $@ \
89 -O2 -fpe0 -traceback -recursive -qopenmp -DDEBUG -DCLUSTER -lmcd_corex64; } && \
90 export -f ifort; rm -f *.so; rm -f *.o; "+ pyx_make +" make -library pyx_file"
91 elif makeopt == 1:
92 pyx_make = posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","ansys_inc",version,"ansys")
93 pyx_post = "export ANS_PATH="+pyx_make+" && \
94 export FPATH=$FPATH:$ANS_PATH/customize/include && \
95 export CPATH=$CPATH:$ANS_PATH/customize/include && \
96 function fcomp() { $pyx_ifort \
97 -w -c -fpp -openmp -fpic -O2 -ftz \
98 -mcmodel=medium \
99 -module ./ -DLINX64_SYS -DLINUXEM64T_SYS -DFORTRAN -DOPENMP\
100 -DCADOE_SOLVER -DDEBUG -DCLUSTER $@; } && \
101 function flink() { $pyx_ifort \
102 -shared -Xlinker -relax -Xlinker \
103 --whole-archive userlib.a -Xlinker --no-whole-archive \
104 -o libansuser.so -Xlinker -soname=libansuser.so $@; } && \
105 source $ANS_PATH/bin/anssh.ini; \
106 rm -f *.o; rm -f *.so; \
107 fcomp pyx_file.f && wait; \
108 ar -qc userlib.a *.o && flink -lmcd_corex64; rm -f *.a; rm -f *.o; "
109 elif makeopt ==2:
110 # Build MCODAC remotely on DLR's HPC cluster (CARA).
111 host = "cara.dlr.de"
112 dependency = posixpath.join(Utility.AsDrive("home",posixpath.sep),user,"mcodac")
113 pyx_make = version
114 pyx_post = "function ifort() { $pyx_ifort $@ \
115 -O2 -fpe0 -traceback -recursive -qopenmp -DDEBUG -DCLUSTER -lmcd_corex64; } && \
116 export -f ifort; "+'export abaquslm_license_file="27018@abaqussd1.intra.dlr.de"'+"; rm -f *.so; rm -f *.o; "+ pyx_make +" make -library pyx_file"
117 elif makeopt == 7:
118 # Build MCODAC library with Peridigm
119 pyx_comp = VTL.GetBuildCommand(makeopt)
120 # Copy peridigm executable into mcodac binary folder (for now!)
121 pyx_post = "mv --force Peridigm " + posixpath.join(Utility.AsDrive("home",posixpath.sep),user,"mcodac","bin") + " && rm -f pyx_file.f"
122 else:
123 raise NotImplementedError
124
125 # Additional includes from 3rd party software compiled for MCODAC.
126 outpath = posixpath.join(Utility.AsDrive("home",posixpath.sep),user)
127 libpath = posixpath.join(dependency,"lib"); incpath = posixpath.join(dependency,"include")
128 includes = [outpath, [posixpath.join(incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")]]
129 libs = [posixpath.join(libpath,"libinterpx64.a"), posixpath.join(libpath,"libmueslix64.a"),
130 posixpath.join(libpath,"libpchipx64.a"), posixpath.join(libpath,"libbbeamx64.a"),
131 posixpath.join(libpath,"libdispmodulex64.a")]
132
133 # Remote build using SSH connection.
134 SSHBuild = pyx.SSH(BuildID, files, scratch=scratch, verbose=verbosity)
135
136 # Put interface file onto the cluster
137 print('==================================')
138 print('Establishing SSH connection.')
139 print('==================================')
140 SSHBuild.Settings(user, key, host, port, **kwargs)
141 SSH = SSHBuild.ssh_client.open_sftp()
142 if not source_file.endswith(".zip"):
143 SSH.put(os.path.join(path2feature,source_file),"pyx_file.f")
144 else:
145 SSH.put(os.path.join(path2feature,source_file),source_file)
146 SSH.close()
147
148 # This is the default build command.
149 SSHBuild.SourcePath(path2src)
150 SSHBuild.AddIncludePath(includes)
151 SSHBuild.AddDependencyPath(outpath)
152 if makeopt != 2:
153 # Builds on the institute cluster (FA)
154 SSHBuild.Environment(posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d"),"ifort2016.sh")
155 else:
156 # Builds on the DLR HPC cluster (CARA)
157 SSHBuild.Environment(bash=VTL.GetEnvironment(4)[0])
158 if makeopt >= 3:
159 # Special-purpose builds
160 SSHBuild.Environment(posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d"),"mpibuild.sh")
161 SSHBuild.Environment(posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d"),"peridigm.sh")
162 SSHBuild.Build(pyx_comp,run="custom");
163 else:
164 # Custom
165 SSHBuild.Preprocessing(inend='.for', outend='.f90')
166 SSHBuild.Build(pyx_comp, linkedIn=libs)
167 SSHBuild.OutputPath(outpath)
168 SSHBuild.Postprocessing(pyx_post)
169 # Execute all commands.
170 SSHBuild.create()
171
172if __name__ == "__main__":
173# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174# % Access command line inputs %
175# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 parser = argparse.ArgumentParser(description="Build MCODAC's shared library remotely and its subsidiaries on the institute cluster.\
177 Supported features are ABAQUS, ANSYS & NASTRAN")
178 parser.add_argument("BuildID", metavar="BuildID", nargs=1, help="Name ID for build job")
179 parser.add_argument("user", metavar="user", nargs=1, help="Current user for SSH connection")
180 parser.add_argument("key", metavar="key", nargs=1, help="Path to private SSH key")
181 parser.add_argument("source_path", metavar="source", nargs=1, help="Directory containing all source files")
182 parser.add_argument("feature_path", metavar="feature", nargs=1, help="Directory containing the feature source file \
183 in dependence of requested feature: ABAQUS, ANSYS, NASTRAN.")
184 try:
185 _ = sys.argv[1]
186 args, _ = parser.parse_known_args()
187 except:
188 pass
189
190 try:
191 BuildID = args.BuildID[0]
192 user = args.user[0]
193 key = args.key[0]
194 path2src = args.source_path[0]
195 path2feature = args.feature_path[0]
196 except:
197 try:
198 from PyCODAC.Plugin import Peridigm
199 # Build Peridigm together with MCODAC
200 if os.path.exists(Peridigm.PeridigmPath):
201 BuildID = "peridigm"
202 user = __user
203 key = os.path.join(Utility.AsDrive("C"),"Users",user,"Keys","Putty","id_rsa")
204 # Operate fully in a temporary directory
205 with Utility.TemporaryDirectory(VTL.Scratch):
206 Peridigm.GetSourceCode(output=os.getcwd(), user=True)
207 main(BuildID,user,key,path2src=os.getcwd(),files=os.listdir(os.getcwd())[0], scratch=os.getcwd(), makeopt=7)
208 except ImportError:
209 pass
210
211 BuildID = 'mcd_core'
212 user = __user
213 key = os.path.join(Utility.AsDrive("C"),"Users",user,"Keys","Putty","id_rsa")
214 path2src=os.path.join(__mcd_core_path,"src")
215 path2feature=os.path.join(__mcd_core_path,"solver")
216
217 # Build MCODAC on DLR's HPC cluster (DLR)
218 main(BuildID,user,key,path2src,path2feature,version="abaqus",makeopt=2)
219
220 # Build MCODAC on the institute cluster (FA)
221 main(BuildID,user,key,path2src,path2feature)
222
223 # Finish
224 print("==================================")
225 print("Finished")
226 print("==================================")
227 sys.exit()
Base class for all input errors.
Module containing all relevant modules and scripts associated with the building process.
Definition __init__.py:1
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
main(BuildID, user, key, path2src=os.path.join(__mcd_core_path,"src"), path2feature=os.path.join(__mcd_core_path,"solver"), files=VTL.GetSourceCode(0), source_file="mcd_astandard.f", version="abq2019", makeopt=0, scratch=VTL.Scratch, dependency=posixpath.join(Utility.AsDrive("cluster", posixpath.sep),"software","mcodac","stable"), verbosity=2, host="129.247.54.37", port=22, **kwargs)
Definition ssh_make.py:73