PyXMake Developer Guide: src/PyXMake/VTL/ssh_ifort.py Source File

| PyXMake Developer Guide 1.0 PyXMake

Loading...
Searching...
No Matches
ssh_ifort.py
1# -*- coding: utf-8 -*-
2# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3# % PyXMake - Build environment for PyXMake %
4# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5"""
6Triple-use minimum working example for PyXMake. This script can be
7executed in three different ways in varying levels of accessibility
8
9@note: Compile Fortran source on the institute cluster.
10 Uses main function
11
12@version: 1.0
13----------------------------------------------------------------------------------------------
14@requires:
15 - PyXMake
16 - SSH key
17
18@author: garb_ma [DLR-FA,STM Braunschweig]
19----------------------------------------------------------------------------------------------
20"""
21import os, sys
22import argparse
23import posixpath
24import collections
25
26try:
27 import PyXMake as _
28except ImportError:
29 # Script is executed as a plug-in
30 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
31finally:
32 from PyXMake.Build import Make as pyx #@UnresolvedImport
33 from PyXMake.Tools import Utility #@UnresolvedImport
34 from PyXMake import VTL #@UnresolvedImport
35
36# Predefined script local variables
37__user = os.getenv("username","")
38__mcd_cluster_dev = posixpath.join(Utility.AsDrive("home",posixpath.sep),__user,"mcodac")
39__mcd_cluster_incpath = posixpath.join(__mcd_cluster_dev,"include")
40__mcd_cluster_libpath = posixpath.join(__mcd_cluster_dev,"lib")
41
42try:
43 # Import PyCODAC to build library locally during setup.
44 from PyCODAC.Tools.Utility import GetPyCODACPath
45 # Import and set local path to PyCODAC
46 __mcd_core_path = os.path.join(GetPyCODACPath(),"Core")
47except ImportError:
48 # This script is not executed as plug-in
49 __mcd_core_path = ""
50except:
51 # Something else went wrong.
52 from PyXMake.Tools import ErrorHandling
53 ErrorHandling.InputError(20)
54
55 def main(
56 # Mandatory arguments
57 BuildID, user, key,
58 # Build MCODAC by default
59 files=VTL.GetSourceCode(0),
60 command=VTL.GetBuildCommand(5),
61 # Resource paths
62 source=os.path.join(__mcd_core_path,"src"),
63 include=[posixpath.join(__mcd_cluster_incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")],
64 make=__mcd_cluster_dev,
65 link=[posixpath.join(__mcd_cluster_libpath, ".".join(["lib"+x,"a"])) for x in VTL.GetLinkDependency(0, 4, "x64")],
66 # Bash environment scripts
67 environment = VTL.GetEnvironment(0),
68 # Architecture, verbose and scratch directory (on host)
69 architecture="x64", scratch=VTL.Scratch, verbosity=0,
70 # Activate / deactivate incremental compilation. Does deactivate pre-processing.
71 incremental = False,
72 # Host and port number. Access DLR's institute cluster by default.
73 host="129.247.54.37", port=22,
74 # Additional keyword arguments
75 **kwargs):
76 """
77 Main function to execute the script.
78 """
79 # Evaluate input parameters
80 envlist = list([]); envlist.append(environment); envlist = list(Utility.ArbitraryFlattening(envlist))
81 makelist = list([]); makelist.append(make); makelist = list(Utility.ArbitraryFlattening(makelist))
82 precommand= kwargs.get("precommand",""); replace = kwargs.get('replace', False)
83 # Remote build using SSH connection.
84 SSHBuild = pyx.SSH(BuildID, files, scratch=scratch, arch=architecture, verbose=verbosity, incremental=incremental)
85 # Combine source code using wrapper module
86 if not incremental:
87 SSHBuild.Wrapper(BuildID)
88 SSHBuild.SourcePath(source)
89 SSHBuild.AddIncludePath(include)
90 # Load environments successively (if given)
91 for x in envlist:
92 SSHBuild.Environment(bash=x)
93 try:
94 # Module & library path are not relative to each other
95 SSHBuild.OutputPath(modulepath=makelist[0], libpath=makelist[1])
96 except:
97 # Module & library path are relative to each other.
98 SSHBuild.OutputPath(modulepath=posixpath.join(makelist[0],"include"), libpath=posixpath.join(makelist[0],"lib"))
99 if isinstance(replace,dict):
100 SSHBuild.Preprocessing(precommand,inend='.for', outend='.f90', replace=replace)
101 # Activate / deactivate incremental compilation & linking
102 elif incremental:
103 SSHBuild.Preprocessing(copyfiles=files)
104 else:
105 SSHBuild.Preprocessing(precommand,inend='.for', outend='.f90')
106 SSHBuild.Build(command, linkedIn=link)
107 SSHBuild.Settings(user, key, host, port, **kwargs)
108 SSHBuild.create(**kwargs)
109
110if __name__ == "__main__":
111# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112# % Access command line inputs %
113# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114 parser = argparse.ArgumentParser(description="Build a static Fortran library remotely on the institute cluster")
115 parser.add_argument("user", metavar="user", nargs=1, help="Current user for SSH connection")
116 parser.add_argument("key", metavar="key", nargs=1, help="Path to private SSH key")
117
118 try:
119 _ = sys.argv[1]
120 args, _ = parser.parse_known_args()
121 except:
122 pass
123
124 try:
125 # SSH key informations
126 user = args.user[0]
127 key = args.key[0]
128 except:
129 # Default settings. Retain pristine version of this script and build all static Fortran libraries associated with MCODAC.
130 user =__user
131 key = os.path.join(Utility.AsDrive("C"),"Users",user,"Keys","Putty","id_rsa")
132
133 # Build BoxBeam; Define files to be processed for BoxBeam
134 box_source = os.path.join(__mcd_core_path,"external","boxbeam")
135 box_make = [posixpath.join(__mcd_cluster_dev,"include","boxbeam"), posixpath.join(__mcd_cluster_dev,"lib")]
136 main('bbeam', user, key, files=VTL.GetSourceCode(1), source=box_source, include=[], make=box_make, link=[])
137
138 # Build DispModule; Define files to be processed for DispModule
139 disp_source=os.path.join(__mcd_core_path,"external","dispmodule","Fortran90","Src")
140 disp_make = [posixpath.join(__mcd_cluster_dev,"include","dispmodule"), posixpath.join(__mcd_cluster_dev,"lib")]
141 main("dispmodule" , user, key, files=VTL.GetSourceCode(5), command=VTL.GetBuildCommand(5, "free"), source=disp_source,
142 include=[], make=disp_make, link=[], incremental=True)
143
144 # Compile all low-level external libraries used by MCODAC using Intel Fortran.
145 # Files to be processed by low-level libraries
146 BuildIDs = [os.path.splitext(x)[0].lower() for x in VTL.GetSourceCode(6)]
147 for BuildID in BuildIDs:
148 srcfile = [x for x in VTL.GetSourceCode(6) if x.startswith(BuildID)]
149 # Mixed format compilation
150 style = "fixed"; combine=False
151 if not BuildID.endswith("790"):
152 style = "free"; combine=True
153 # Define files to be processed for TOMS
154 toms_source = os.path.join(__mcd_core_path,"external","toms")
155 make = [posixpath.join(__mcd_cluster_dev,"include","toms"),posixpath.join(__mcd_cluster_dev,"lib")]
156 # Wrap the original source code and put all subroutines & functions in a module
157 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5, style+" -DPYX_WRAPPER"), make=make,
158 combine=combine, source=toms_source, include=[], libs=[], link=[])
159
160 # Name mangling without changing the original source code. Rename procedures to avoid conflicts in final software.
161 pchip_replace = collections.OrderedDict([('rand',"pchip_rand"), ('RAND',"pchip_rand"), ('subroutine timestamp ( )','subroutine timestamp ( ) BIND(C, NAME="pchip_timestamp")')]) #@UndefinedVariable
162
163 # Compile all low-level external libraries used by MCODAC using Intel Fortran.
164 # Files to be processed by low-level libraries
165 BuildIDs = [os.path.splitext(x)[0].lower() for x in VTL.GetSourceCode(7)]
166 for BuildID in BuildIDs:
167 srcfile = [x for x in VTL.GetSourceCode(7) if x.startswith(BuildID)]
168 # Define files to be processed for NMS, PCHIP, SLATEC & INTERP
169 source = os.path.join(__mcd_core_path,"external",BuildID)
170 if BuildID == "pchip":
171 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5, "free"),
172 source=source, include=[], link=[],
173 precommand="fpp -P", replace=pchip_replace)
174 else:
175 main(BuildID, user, key, files=srcfile, command=VTL.GetBuildCommand(5, "free"), source=source, include=[], link=[])
176
177 # Build MCODAC (default settings)
178 main('mcd_core', user, key)
179 else:
180 # This is not implemented yet.
181 raise NotImplementedError
182
183 # Finish
184 print("==================================")
185 print("Finished")
186 print("==================================")
187 sys.exit()
PyXMake.Tools.ErrorHandling.InputError
Base class for all input errors.
PyXMake.Build
Module containing all relevant modules and scripts associated with the building process.
Definition __init__.py:1
PyXMake.Tools
Module containing basic functionalities defined for convenience.
Definition __init__.py:1
PyXMake.VTL.ssh_ifort.main
main(BuildID, user, key, files=VTL.GetSourceCode(0), command=VTL.GetBuildCommand(5), source=os.path.join(__mcd_core_path,"src"), include=[posixpath.join(__mcd_cluster_incpath, x) for x in VTL.GetIncludeDirectory(__mcd_core_path, 0, 4, "x64")], make=__mcd_cluster_dev, link=[posixpath.join(__mcd_cluster_libpath, ".".join(["lib"+x,"a"])) for x in VTL.GetLinkDependency(0, 4, "x64")], environment=VTL.GetEnvironment(0), architecture="x64", scratch=VTL.Scratch, verbosity=0, incremental=False, host="129.247.54.37", port=22, **kwargs)
Definition ssh_ifort.py:75