-
Notifications
You must be signed in to change notification settings - Fork 200
/
blacs.py
235 lines (180 loc) · 8.45 KB
/
blacs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
##
# Copyright 2009-2012 Stijn De Weirdt
# Copyright 2010 Dries Verdegem
# Copyright 2010-2012 Kenneth Hoste
# Copyright 2011 Pieter De Baets
# Copyright 2011-2012 Jens Timmerman
#
# This file is part of EasyBuild,
# originally created by the HPC team of the University of Ghent (http://ugent.be/hpc).
#
# http://github.com/hpcugent/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for building and installing BLACS, implemented as an easyblock
"""
import glob
import re
import os
import shutil
import easybuild.tools.toolkit as toolchain
from easybuild.easyblocks.configuremake import EB_ConfigureMake #@UnresolvedImport
from easybuild.tools.filetools import run_cmd
from easybuild.tools.modules import get_software_root
# also used by ScaLAPACK
def det_interface(log, path):
"""Determine interface through 'xintface' heuristic tool"""
(out, _) = run_cmd(os.path.join(path,"xintface"), log_all=True, simple=False)
intregexp = re.compile(".*INTFACE\s*=\s*-D(\S+)\s*")
res = intregexp.search(out)
if res:
return res.group(1)
else:
log.error("Failed to determine interface, output for xintface: %s" % out)
class EB_BLACS(EB_ConfigureMake):
"""
Support for building/installing BLACS
- configure: symlink BMAKES/Bmake.MPI-LINUX to Bmake.inc
- make install: copy files
"""
def configure_step(self):
"""Configure BLACS build by copying Bmake.inc file."""
src = os.path.join(self.cfg['start_dir'], 'BMAKES', 'Bmake.MPI-LINUX')
dest = os.path.join(self.cfg['start_dir'], 'Bmake.inc')
if not os.path.isfile(src):
self.log.error("Can't find source file %s" % src)
if os.path.exists(dest):
self.log.error("Destination file %s exists" % dest)
try:
shutil.copy(src, dest)
except OSError, err:
self.log.error("Copying %s to % failed: %s" % (src, dest, err))
def build_step(self):
"""Build BLACS using build_step, after figuring out the make options based on the heuristic tools available."""
# determine MPI base dir and lib
known_mpis = {
toolchain.OPENMPI: "-L$(MPILIBdir) -lmpi_f77",
toolchain.MVAPICH2: "$(MPILIBdir)/libmpich.a $(MPILIBdir)/libfmpich.a " + \
"$(MPILIBdir)/libmpl.a -lpthread"
}
mpi_type = self.toolchain.mpi_type()
base, mpilib = None, None
if mpi_type in known_mpis.keys():
base = get_software_root(mpi_type)
mpilib = known_mpis[mpi_type]
else:
self.log.error("Unknown MPI lib %s used (known MPI libs: %s)" % (mpi_type, known_mpis.keys()))
opts = {
'mpicc': "%s %s" % (os.getenv('MPICC'), os.getenv('CFLAGS')),
'mpif77': "%s %s" % (os.getenv('MPIF77'), os.getenv('FFLAGS')),
'f77': os.getenv('F77'),
'cc': os.getenv('CC'),
'builddir': os.getcwd(),
'base': base,
'mpilib': mpilib
}
# determine interface and transcomm settings
comm = ''
interface = 'UNKNOWN'
try:
cwd = os.getcwd()
os.chdir('INSTALL')
# need to build
cmd = "make"
cmd += " CC='%(mpicc)s' F77='%(mpif77)s -I$(MPIINCdir)' MPIdir=%(base)s" \
" MPILIB='%(mpilib)s' BTOPdir=%(builddir)s INTERFACE=NONE" % opts
# determine interface using xintface
run_cmd("%s xintface" % cmd, log_all=True, simple=True)
interface = det_interface(self.log, "./EXE")
# try and determine transcomm using xtc_CsameF77 and xtc_UseMpich
if not comm:
run_cmd("%s xtc_CsameF77" % cmd, log_all=True, simple=True)
(out, _) = run_cmd("mpirun -np 2 ./EXE/xtc_CsameF77", log_all=True, simple=False)
# get rid of first two lines, that inform about how to use this tool
out = '\n'.join(out.split('\n')[2:])
notregexp = re.compile("_NOT_")
if not notregexp.search(out):
# if it doesn't say '_NOT_', set it
comm = "TRANSCOMM='-DCSameF77'"
else:
(_, ec) = run_cmd("%s xtc_UseMpich" % cmd, log_all=False, log_ok=False, simple=False)
if ec == 0:
(out, _) = run_cmd("mpirun -np 2 ./EXE/xtc_UseMpich", log_all=True, simple=False)
if not notregexp.search(out):
commregexp = re.compile('Set TRANSCOMM\s*=\s*(.*)$')
res = commregexp.search(out)
if res:
# found how to set TRANSCOMM, so set it
comm = "TRANSCOMM='%s'" % res.group(1)
else:
# no match, set empty TRANSCOMM
comm = "TRANSCOMM=''"
else:
# if it fails to compile, set empty TRANSCOMM
comm = "TRANSCOMM=''"
os.chdir(cwd)
except OSError, err:
self.log.error("Failed to determine interface and transcomm settings: %s" % err)
opts.update({
'comm': comm,
'int': interface,
'base': base
})
add_makeopts = ' MPICC="%(mpicc)s" MPIF77="%(mpif77)s" %(comm)s ' % opts
add_makeopts += ' INTERFACE=%(int)s MPIdir=%(base)s BTOPdir=%(builddir)s mpi ' % opts
self.cfg.update('makeopts', add_makeopts)
super(EB_BLACS, self).build_step()
def install_step(self):
"""Install by copying files to install dir."""
# include files and libraries
for (srcdir, destdir, ext) in [
(os.path.join("SRC", "MPI"), "include", ".h"), # include files
("LIB", "lib", ".a"), # libraries
]:
src = os.path.join(self.cfg['start_dir'], srcdir)
dest = os.path.join(self.installdir, destdir)
try:
os.makedirs(dest)
os.chdir(src)
for lib in glob.glob('*%s' % ext):
# copy file
shutil.copy2(os.path.join(src, lib), dest)
self.log.debug("Copied %s to %s" % (lib, dest))
if destdir == 'lib':
# create symlink with more standard name for libraries
symlink_name = "lib%s.a" % lib.split('_')[0]
os.symlink(os.path.join(dest, lib), os.path.join(dest, symlink_name))
self.log.debug("Symlinked %s/%s to %s" % (dest, lib, symlink_name))
except OSError, err:
self.log.error("Copying %s/*.%s to installation dir %s failed: %s"%(src, ext, dest, err))
# utilities
src = os.path.join(self.cfg['start_dir'], 'INSTALL', 'EXE', 'xintface')
dest = os.path.join(self.installdir, 'bin')
try:
os.makedirs(dest)
shutil.copy2(src, dest)
self.log.debug("Copied %s to %s" % (src, dest))
except OSError, err:
self.log.error("Copying %s to installation dir %s failed: %s" % (src, dest, err))
def sanity_check_step(self):
"""Custom sanity check for BLACS."""
custom_paths = {
'files': [fil for filptrn in ["blacs", "blacsCinit", "blacsF77init"]
for fil in ["lib/lib%s.a" % filptrn,
"lib/%s_MPI-LINUX-0.a" % filptrn]] +
["bin/xintface"],
'dirs': []
}
super(EB_BLACS, self).sanity_check_step(custom_paths=custom_paths)