Debian Codegraph @

doc/platforms/BGQ/config_mira.py

raw symbols SCIP
1 # Copyright (C) 2006 CSC-Scientific Computing Ltd.
2
3 # Please see the accompanying LICENSE file for further information.
4 import os
5 import sys
6 import re
7 import distutils.util
8 from packaging.version import Version
9 from distutils.sysconfig import get_config_var, get_config_vars
10 from glob import glob
11 from os.path import join
12 from stat import ST_MTIME
13
14
15 def check_packages(packages, msg, include_ase, import_numpy):
16 """Check the python version and required extra packages
17
18 If ASE is not installed, the `packages` list is extended with the
19 ASE modules if they are found."""
20
21 if sys.version_info < (2, 3, 0, 'final', 0):
22 raise SystemExit('Python 2.3.1 or later is required!')
23
24 if import_numpy:
25 try:
26 import numpy
27 except ImportError:
28 raise SystemExit('numpy is not installed!')
29 else:
30 msg += ['* numpy is not installed.',
31 ' "include_dirs" in your customize.py must point to "numpy/core/include".']
32
33 if not include_ase:
34 if import_numpy:
35 try:
36 import ase
37 except ImportError:
38 import_ase = True
39 else:
40 import_ase = False
41 else:
42 import_ase = False
43
44 if include_ase or import_ase:
45 # Find ASE directories:
46 # include_ase works in case:
47 # cd gpaw # top-level gpaw source directory
48 # tar zxf ~/python-ase-3.1.0.846.tar.gz
49 # ln -s python-ase-3.1.0.846/ase .
50 ase_root = 'ase'
51 if include_ase:
52 assert os.path.isdir(ase_root), ase_root+': No such file or directory'
53 ase = []
54 for root, dirs, files in os.walk(ase_root):
55 if 'CVS' in dirs:
56 dirs.remove('CVS')
57 if '.svn' in dirs:
58 dirs.remove('.svn')
59 if '__init__.py' in files:
60 ase.append(root.replace('/', '.'))
61
62 if len(ase) == 0:
63 msg += ['* ASE is not installed! You may be able to install',
64 " gpaw, but you can't use it without ASE!"]
65 else:
66 packages += ase
67
68 def find_file(arg, dir, files):
69 #looks if the first element of the list arg is contained in the list files
70 # and if so, appends dir to to arg. To be used with the os.path.walk
71 if arg[0] in files:
72 arg.append(dir)
73
74
75 def get_system_config(define_macros, undef_macros,
76 include_dirs, libraries, library_dirs, extra_link_args,
77 extra_compile_args, runtime_library_dirs, extra_objects,
78 msg, import_numpy):
79
80 undef_macros += ['NDEBUG']
81 if import_numpy:
82 import numpy
83 include_dirs += [numpy.get_include()]
84 include_dirs += ['c/libxc']
85
86 machine = os.uname()[4]
87 if machine == 'sun4u':
88
89 # _
90 # |_ | ||\ |
91 # _||_|| \|
92 #
93
94 extra_compile_args += ['-Kpic', '-fast']
95
96 # Suppress warning from -fast (-xarch=native):
97 f = open('cc-test.c', 'w')
98 f.write('int main(){}\n')
99 f.close()
100 stderr = os.popen3('cc cc-test.c -fast')[2].read()
101 arch = re.findall('-xarch=(\S+)', stderr)
102 os.remove('cc-test.c')
103 if len(arch) > 0:
104 extra_compile_args += [f'-xarch={arch[-1]}']
105
106
107 # We need the -Bstatic before the -lsunperf and -lfsu:
108 # forum.java.sun.com/thread.jspa?threadID=5072537&messageID=9265782
109 extra_link_args += ['-Bstatic', '-lsunperf', '-lfsu', '-Bdynamic']
110 cc_version = os.popen3('cc -V')[2].readline().split()[3]
111 if Version(cc_version) > '5.6':
112 libraries.append('mtsk')
113 else:
114 extra_link_args.append('-lmtsk')
115 #define_macros.append(('NO_C99_COMPLEX', '1'))
116
117 msg += ['* Using SUN high performance library']
118
119 elif sys.platform in ['aix5', 'aix6']:
120
121 #
122 # o|_ _ _
123 # ||_)| | |
124 #
125
126 extra_compile_args += ['-qlanglvl=stdc99']
127 # setting memory limit is necessary on aix5
128 if sys.platform == 'aix5':
129 extra_link_args += ['-bmaxdata:0x80000000',
130 '-bmaxstack:0x80000000']
131
132 libraries += ['f', 'lapack', 'essl']
133 define_macros.append(('GPAW_AIX', '1'))
134
135 elif machine == 'x86_64':
136
137 # _
138 # \/|_||_ |_ |_|
139 # /\|_||_| _ |_| |
140 #
141
142 extra_compile_args += ['-Wall', '-std=c99']
143
144 # Look for ACML libraries:
145 acml = glob('/opt/acml*/g*64/lib')
146 if len(acml) > 0:
147 library_dirs += [acml[-1]]
148 libraries += ['acml']
149 if acml[-1].find('gfortran') != -1: libraries.append('gfortran')
150 if acml[-1].find('gnu') != -1: libraries.append('g2c')
151 extra_link_args += ['-Wl,-rpath=' + acml[-1]]
152 msg += ['* Using ACML library']
153 else:
154 atlas = False
155 for dir in ['/usr/lib', '/usr/local/lib']:
156 if glob(join(dir, 'libatlas.a')) != []:
157 atlas = True
158 break
159 if atlas:
160 libraries += ['lapack', 'atlas', 'blas']
161 library_dirs += [dir]
162 msg += ['* Using ATLAS library']
163 else:
164 libraries += ['blas', 'lapack']
165 msg += ['* Using standard lapack']
166
167 elif machine =='ia64':
168
169 # _ _
170 # |_ | o
171 # _||_||
172 #
173
174 extra_compile_args += ['-Wall', '-std=c99']
175 libraries += ['mkl','mkl_lapack64']
176
177 elif machine == 'i686':
178
179 # _
180 # o|_ |_||_
181 # ||_||_||_|
182 #
183
184 extra_compile_args += ['-Wall', '-std=c99']
185
186 if 'MKL_ROOT' in os.environ:
187 mklbasedir = [os.environ['MKL_ROOT']]
188 else:
189 mklbasedir = glob('/opt/intel/mkl*')
190 libs = ['libmkl_ia32.a']
191 if mklbasedir != []:
192 os.path.walk(mklbasedir[0],find_file, libs)
193 libs.pop(0)
194 if libs != []:
195 libs.sort()
196 libraries += ['mkl_lapack',
197 'mkl_ia32', 'guide', 'pthread', 'mkl']#, 'mkl_def']
198 library_dirs += libs
199 msg += [f'* Using MKL library: {library_dirs[-1]}']
200 #extra_link_args += ['-Wl,-rpath=' + library_dirs[-1]]
201 else:
202 atlas = False
203 for dir in ['/usr/lib', '/usr/local/lib']:
204 if glob(join(dir, 'libatlas.a')) != []:
205 atlas = True
206 break
207 if atlas:
208 libraries += ['lapack', 'atlas', 'blas']
209 library_dirs += [dir]
210 msg += ['* Using ATLAS library']
211 else:
212 libraries += ['blas', 'lapack']
213 msg += ['* Using standard lapack']
214
215 # add libg2c if available
216 g2c=False
217 for dir in ['/usr/lib', '/usr/local/lib']:
218 if glob(join(dir, 'libg2c.so')) != []:
219 g2c=True
220 break
221 if glob(join(dir, 'libg2c.a')) != []:
222 g2c=True
223 break
224 if g2c: libraries += ['g2c']
225
226 elif sys.platform == 'darwin':
227
228 extra_compile_args += ['-Wall', '-std=c99']
229 include_dirs += ['/usr/include/malloc']
230
231 if glob('/System/Library/Frameworks/vecLib.framework') != []:
232 extra_link_args += ['-framework vecLib']
233 msg += ['* Using vecLib']
234 else:
235 libraries += ['blas', 'lapack']
236 msg += ['* Using standard lapack']
237
238 return msg
239
240
241 def get_parallel_config(mpi_libraries,mpi_library_dirs,mpi_include_dirs,
242 mpi_runtime_library_dirs,mpi_define_macros):
243
244 globals = {}
245 exec(open('gpaw/mpi/config.py').read(), globals)
246 mpi = globals['get_mpi_implementation']()
247
248 if mpi == '':
249 mpicompiler = None
250
251 elif mpi == 'sun':
252 mpi_include_dirs += ['/opt/SUNWhpc/include']
253 mpi_libraries += ['mpi']
254 mpi_library_dirs += ['/opt/SUNWhpc/lib']
255 mpi_runtime_library_dirs += ['/opt/SUNWhpc/lib']
256 mpicompiler = get_config_var('CC')
257
258 elif mpi == 'poe':
259 mpicompiler = 'mpcc_r'
260
261 else:
262 #Try to use mpicc
263 mpicompiler = 'mpicc'
264
265 return mpicompiler
266
267 def get_scalapack_config(define_macros):
268 # check ScaLapack settings
269 define_macros.append(('GPAW_WITH_SL', '1'))
270
271
272 def mtime(path, name, mtimes):
273 """Return modification time.
274
275 The modification time of a source file is returned. If one of its
276 dependencies is newer, the mtime of that file is returned.
277 This function fails if two include files with the same name
278 are present in different directories."""
279
280 include = re.compile('^#\s*include "(\S+)"', re.MULTILINE)
281
282 if name in mtimes:
283 return mtimes[name]
284 t = os.stat(os.path.join(path, name))[ST_MTIME]
285 for name2 in include.findall(open(os.path.join(path, name)).read()):
286 path2, name22 = os.path.split(name2)
287 if name22 != name:
288 t = max(t, mtime(os.path.join(path, path2), name22, mtimes))
289 mtimes[name] = t
290 return t
291
292 def check_dependencies(sources):
293 # Distutils does not do deep dependencies correctly. We take care of
294 # that here so that "python setup.py build_ext" always does the right
295 # thing!
296 mtimes = {} # modification times
297
298 # Remove object files if any dependencies have changed:
299 plat = distutils.util.get_platform() + '-' + sys.version[0:3]
300 remove = False
301 for source in sources:
302 path, name = os.path.split(source)
303 t = mtime(path + '/', name, mtimes)
304 o = f'build/temp.{plat}/{source[:-2]}.o' # object file
305 if os.path.exists(o) and t > os.stat(o)[ST_MTIME]:
306 print('removing', o)
307 os.remove(o)
308 remove = True
309
310 so = f'build/lib.{plat}/_gpaw.so'
311 if os.path.exists(so) and remove:
312 # Remove shared object C-extension:
313 # print 'removing', so
314 os.remove(so)
315
316 def test_configuration():
317 raise NotImplementedError
318
319
320 def write_configuration(define_macros, include_dirs, libraries, library_dirs,
321 extra_link_args, extra_compile_args,
322 runtime_library_dirs, extra_objects, mpicompiler,
323 mpi_libraries, mpi_library_dirs, mpi_include_dirs,
324 mpi_runtime_library_dirs, mpi_define_macros):
325
326 # Write the compilation configuration into a file
327 try:
328 out = open('configuration.log', 'w')
329 except IOError as x:
330 print(x)
331 return
332 print("Current configuration", file=out)
333 print("libraries", libraries, file=out)
334 print("library_dirs", library_dirs, file=out)
335 print("include_dirs", include_dirs, file=out)
336 print("define_macros", define_macros, file=out)
337 print("extra_link_args", extra_link_args, file=out)
338 print("extra_compile_args", extra_compile_args, file=out)
339 print("runtime_library_dirs", runtime_library_dirs, file=out)
340 print("extra_objects", extra_objects, file=out)
341 if mpicompiler is not None:
342 print(file=out)
343 print("Parallel configuration", file=out)
344 print("mpicompiler", mpicompiler, file=out)
345 print("mpi_libraries", mpi_libraries, file=out)
346 print("mpi_library_dirs", mpi_library_dirs, file=out)
347 print("mpi_include_dirs", mpi_include_dirs, file=out)
348 print("mpi_define_macros", mpi_define_macros, file=out)
349 print("mpi_runtime_library_dirs", mpi_runtime_library_dirs, file=out)
350 out.close()
351
352
353 def build_interpreter(define_macros, include_dirs, libraries, library_dirs,
354 extra_link_args, extra_compile_args,
355 runtime_library_dirs, extra_objects,
356 mpicompiler, mpilinker, mpi_libraries, mpi_library_dirs,
357 mpi_include_dirs, mpi_runtime_library_dirs,
358 mpi_define_macros):
359
360 #Build custom interpreter which is used for parallel calculations
361
362 cfgDict = get_config_vars()
363 plat = distutils.util.get_platform() + '-' + sys.version[0:3]
364
365 cfiles = glob('c/[a-zA-Z_]*.c') + ['c/bmgs/bmgs.c']
366 cfiles += glob('c/libxc/src/*.c')
367 if ('HDF5', 1) in define_macros:
368 cfiles += glob('h5py/c/*.c')
369 cfiles += glob('h5py/c/lzf/*.c')
370
371 cfiles2remove = ['c/libxc/src/test.c',
372 'c/libxc/src/xc_f.c',
373 'c/libxc/src/work_gga_x.c',
374 'c/libxc/src/work_lda.c'
375 ]
376
377 for c2r in glob('c/libxc/src/funcs_*.c'): cfiles2remove.append(c2r)
378 for c2r in cfiles2remove: cfiles.remove(c2r)
379 sources = ['c/bc.c', 'c/localized_functions.c', 'c/mpi.c', 'c/_gpaw.c',
380 'c/operators.c', 'c/transformers.c', 'c/compiled_WITH_SL.c',
381 'c/blacs.c', 'c/utilities.c']
382 objects = ' '.join(['build/temp.%s/' % plat + x[:-1] + 'o'
383 for x in cfiles])
384
385 if not os.path.isdir(f'build/bin.{plat}/'):
386 os.makedirs(f'build/bin.{plat}/')
387 exefile = f'build/bin.{plat}/' + '/gpaw-python'
388
389 # if you want static linked MPI libraries, uncomment the line below
390 libraries += mpi_libraries
391 library_dirs += mpi_library_dirs
392 define_macros += mpi_define_macros
393 include_dirs += mpi_include_dirs
394 runtime_library_dirs += mpi_runtime_library_dirs
395
396 define_macros.append(('PARALLEL', '1'))
397 define_macros.append(('GPAW_INTERPRETER', '1'))
398 macros = ' '.join(['-D%s=%s' % x for x in define_macros if x[0].strip()])
399
400 include_dirs.append(cfgDict['INCLUDEPY'])
401 include_dirs.append(cfgDict['CONFINCLUDEPY'])
402 includes = ' '.join(['-I' + incdir for incdir in include_dirs])
403
404 library_dirs.append(cfgDict['LIBPL'])
405 lib_dirs = ' '.join(['-L' + lib for lib in library_dirs])
406
407 libs = ' '.join(['-l' + lib for lib in libraries if lib.strip()])
408 # BlueGene/P can statically link everything except
409 # python, runtime and pthread library
410 libs += ' -Wl,-dy'
411 libpl = cfgDict['LIBPL']
412 if glob(libpl + '/libpython*mpi*'):
413 libs += f" -lpython{cfgDict['VERSION']}_mpi"
414 else:
415 libs += f" -lpython{cfgDict['VERSION']}"
416 # libs += ' -lpython%s ' % cfgDict['VERSION']
417 # if you want dynamic linked MPI libraries, uncomment the line below
418 # only really needed for TAU profiling
419 # libs += ' '.join(['-l' + lib for lib in mpi_libraries])
420 libs += ' -lrt -lpthread'
421 libs = ' '.join([libs, cfgDict['LIBS'], cfgDict['LIBM']])
422
423 #Hack taken from distutils to determine option for runtime_libary_dirs
424 if sys.platform[:6] == 'darwin':
425 # MacOSX's linker doesn't understand the -R flag at all
426 runtime_lib_option = '-L'
427 elif sys.platform[:5] == 'hp-ux':
428 runtime_lib_option = '+s -L'
429 elif os.popen('mpicc --showme 2> /dev/null', 'r').read()[:3] == 'gcc':
430 runtime_lib_option = '-Wl,-R'
431 elif os.popen('mpicc -show 2> /dev/null', 'r').read()[:3] == 'gcc':
432 runtime_lib_option = '-Wl,-R'
433 else:
434 runtime_lib_option = '-R'
435
436 runtime_libs = ' '.join([ runtime_lib_option + lib for lib in runtime_library_dirs])
437
438 extra_link_args.append(cfgDict['LDFLAGS'])
439 if sys.platform in ['aix5', 'aix6']:
440 extra_link_args.append(cfgDict['LINKFORSHARED'].replace('Modules', cfgDict['LIBPL']))
441 elif sys.platform == 'darwin':
442 pass
443 else:
444 extra_link_args.append(cfgDict['LINKFORSHARED'])
445
446 if ('IO_WRAPPERS', 1) in define_macros:
447 extra_link_args += ['-Wl,-wrap,fread',
448 '-Wl,-wrap,_IO_getc',
449 '-Wl,-wrap,getc_unlocked',
450 '-Wl,-wrap,fgets',
451 '-Wl,-wrap,ungetc',
452 '-Wl,-wrap,feof',
453 '-Wl,-wrap,ferror',
454 '-Wl,-wrap,fflush',
455 '-Wl,-wrap,fseek',
456 '-Wl,-wrap,rewind',
457 # '-Wl,-wrap,fileno',
458 '-Wl,-wrap,flockfile',
459 '-Wl,-wrap,funlockfile',
460 '-Wl,-wrap,clearerr',
461 '-Wl,-wrap,fgetpos',
462 '-Wl,-wrap,fsetpos',
463 '-Wl,-wrap,setbuf',
464 '-Wl,-wrap,setvbuf',
465 '-Wl,-wrap,ftell',
466 '-Wl,-wrap,fstat',
467 '-Wl,-wrap,fstat64',
468 '-Wl,-wrap,fgetc',
469 # '-Wl,-wrap,fputc',
470 # '-Wl,-wrap,fputs',
471 # '-Wl,-wrap,fwrite',
472 # '-Wl,-wrap,_IO_putc',
473 '-Wl,-wrap,fopen',
474 '-Wl,-wrap,fopen64',
475 '-Wl,-wrap,fclose',
476 ]
477
478 # Compile the parallel sources
479 for src in sources:
480 obj = f'build/temp.{plat}/' + src[:-1] + 'o'
481 cmd = ('%s %s %s %s -o %s -c %s ' ) % \
482 (mpicompiler,
483 macros,
484 ' '.join(extra_compile_args),
485 includes,
486 obj,
487 src)
488 print(cmd)
489 if '--dry-run' not in sys.argv:
490 error=os.system(cmd)
491 if error != 0:
492 msg = ['* compiling FAILED! Only serial version of code will work.']
493 break
494
495 # Link the custom interpreter
496 cmd = ('%s -o %s %s %s %s %s %s %s' ) % \
497 (mpilinker,
498 exefile,
499 objects,
500 ' '.join(extra_objects),
501 lib_dirs,
502 libs,
503 runtime_libs,
504 ' '.join(extra_link_args))
505
506 msg = ['* Building a custom interpreter']
507 print(cmd)
508 if '--dry-run' not in sys.argv:
509 error=os.system(cmd)
510 if error != 0:
511 msg += ['* linking FAILED! Only serial version of code will work.']
512
513
514 return error, msg