PyXMake Developer Guide: D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/ssh_make.py Source File

| PyXMake Developer Guide 1.0 PyXMake

D:/03_Workspaces/01_Eclipse/pyx_core/PyXMake/VTL/ssh_make.py
1 # -*- coding: utf-8 -*-
2 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 # % PyXMake - Build environment for PyXMake %
4 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 """
6 Minimum working example for PyXMake.
7
8 @note: Compile the complete MCODAC library for ABAQUS remotely.
9 Created 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 """
23 import os, sys
24 import posixpath
25 import argparse
26
27 try:
28 import PyXMake as _
29 except 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__)))))
32 finally:
33 from PyXMake.Build import Make as pyx
34 from PyXMake.Tools import Utility
35 from PyXMake import VTL
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
43 try:
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")
48 except ImportError:
49 # This script is not executed as plug-in
50 __mcd_core_path = ""
51 except:
52 # Something else went wrong.
53 from PyXMake.Tools import ErrorHandling
54 ErrorHandling.InputError(20)
55
56 def 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=0,
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 ='-fpp -qopenmp -DCLUSTER -DDEBUG -fPIC -auto -lmkl -extend_source -O2 -fixed -parallel -fpe0 -recursive'
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 else:
110 raise NotImplementedError
111
112 # Additional includes from 3rd party software compiled for MCODAC.
113 outpath = posixpath.join(Utility.AsDrive("home",posixpath.sep),user)
114 libpath = posixpath.join(dependency,"lib"); incpath = posixpath.join(dependency,"include")
115 includes = [outpath, [posixpath.join(incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")]]
116 libs = [posixpath.join(libpath,"libinterpx64.a"), posixpath.join(libpath,"libmueslix64.a"),
117 posixpath.join(libpath,"libpchipx64.a"), posixpath.join(libpath,"libbbeamx64.a"),
118 posixpath.join(libpath,"libdispmodulex64.a")]
119
120 # Remote build using SSH connection.
121 SSHBuild = pyx.SSH(BuildID, files, scratch=scratch, verbose=verbosity)
122
123 # Put interface file onto the cluster
124 print('==================================')
125 print('Establishing SSH connection.')
126 print('==================================')
127 SSHBuild.Settings(user, key, host, port)
128 SSH = SSHBuild.ssh_client.open_sftp()
129 SSH.put(os.path.join(path2feature,source_file),"pyx_file.f")
130 SSH.close()
131
132 # This is the default build command.
133 SSHBuild.SourcePath(path2src)
134 SSHBuild.AddIncludePath(includes)
135 SSHBuild.AddDependencyPath(outpath)
136 SSHBuild.Environment(posixpath.join(Utility.AsDrive("cluster",posixpath.sep),"software","slurm","etc","env.d"),"ifort2016.sh")
137 SSHBuild.OutputPath(outpath)
138 SSHBuild.Preprocessing(inend='.for', outend='.f90')
139 SSHBuild.Build(pyx_comp, linkedIn=libs)
140 SSHBuild.Postprocessing(pyx_post)
141
142 # Execute all commands.
143 SSHBuild.create()
144
145 if __name__ == "__main__":
146 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147 # % Access command line inputs %
148 # %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 parser = argparse.ArgumentParser(description="Build MCODAC's shared library remotely and its subsidiaries on the institute cluster.\
150 Supported features are ABAQUS, ANSYS & NASTRAN")
151 parser.add_argument("BuildID", metavar="BuildID", nargs=1, help="Name ID for build job")
152 parser.add_argument("user", metavar="user", nargs=1, help="Current user for SSH connection")
153 parser.add_argument("key", metavar="key", nargs=1, help="Path to private SSH key")
154 parser.add_argument("source_path", metavar="source", nargs=1, help="Directory containing all source files")
155 parser.add_argument("feature_path", metavar="feature", nargs=1, help="Directory containing the feature source file \
156 in dependence of requested feature: ABAQUS, ANSYS, NASTRAN.")
157 try:
158 _ = sys.argv[1]
159 args, _ = parser.parse_known_args()
160 except:
161 pass
162
163 try:
164 BuildID = args.BuildID[0]
165 user = args.user[0]
166 key = args.key[0]
167 path2src = args.source_path[0]
168 path2feature = args.feature_path[0]
169 except:
170 BuildID = 'mcd_core'
171 user = __user
172 key = os.path.join(Utility.AsDrive("C"),"Users",user,"Keys","Putty","id_rsa")
173 path2src=os.path.join(__mcd_core_path,"src")
174 path2feature=os.path.join(__mcd_core_path,"solver")
175
176 main(BuildID,user,key,path2src,path2feature)
177
178 # Finish
179 print("==================================")
180 print("Finished")
181 print("==================================")
182 sys.exit()
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition: __init__.py:1
PyXMake.VTL.ssh_make.main
def 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=0, host="129.247.54.37", port=22, kwargs)
Definition: ssh_make.py:73
PyXMake.Build
Module containing all relevant modules and scripts associated with the building process.
Definition: __init__.py:1