-
Notifications
You must be signed in to change notification settings - Fork 0
/
SConstruct
1521 lines (1292 loc) · 53.1 KB
/
SConstruct
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import print_function
# vim: set filetype=python et ts=4 sw=4:
#
# Always run scons from the root directory of tmv
import os
import sys
import SCons
import platform
print('SCons is version',SCons.__version__,'using python version',platform.python_version())
# Subdirectories containing SConscript files. We always process these, but
# there are some other optional ones
subdirs = ['src','bin','share','tests']
# Configurations will be saved here so command line options don't
# have to be sent more than once
config_file = 'tmv_scons.conf'
# Default directory for installation.
# This is the only UNIX specific things I am aware
# of in the script. On the other hand, these are not required for the
# script to work since prefix can be set on the command line and the
# extra paths are not needed, but I wish I knew how to get the default
# prefix for the system so I didn't have to set this.
default_prefix = '/usr/local'
# first check for a saved conf file
opts = Variables(config_file)
# Now set up options for the command line
opts.Add('CXX','Name of c++ compiler','g++')
opts.Add('FLAGS','Flags to send to the compiler','')
opts.Add('EXTRA_FLAGS','Extra flags to send to the compiler','')
opts.Add(BoolVariable('DEBUG',
'Turn on debugging statements in compilied library',False))
opts.Add(PathVariable('PREFIX',
'prefix for installation',default_prefix, PathVariable.PathAccept))
opts.Add(PathVariable('FINAL_PREFIX',
'final installation prefix if different from PREFIX','', PathVariable.PathAccept))
opts.Add(BoolVariable('WITH_OPENMP',
'Look for openmp and use if found.', True))
opts.Add(BoolVariable('INST_FLOAT',
'Instantiate <float> templates in compiled library', True))
opts.Add(BoolVariable('INST_DOUBLE',
'Instantiate <double> templates in compiled library', True))
opts.Add(BoolVariable('INST_INT',
'Instantiate <int> templates in compiled library', True))
opts.Add(BoolVariable('INST_LONGDOUBLE',
'Instantiate <long double> templates in compiled library', False))
opts.Add(BoolVariable('SHARED',
'Build a shared library',True))
opts.Add(BoolVariable('TEST_FLOAT',
'Instantiate <float> in the test suite', True))
opts.Add(BoolVariable('TEST_DOUBLE',
'Instantiate <double> in the test suite', True))
opts.Add(BoolVariable('TEST_INT',
'Instantiate <int> in the test suite', True))
opts.Add(BoolVariable('TEST_LONGDOUBLE',
'Instantiate <long double> in the test suite', False))
opts.Add(PathVariable('EXTRA_PATH',
'Extra paths for executables (separated by : if more than 1)',
'',PathVariable.PathAccept))
opts.Add(PathVariable('EXTRA_LIB_PATH',
'Extra paths for linking (separated by : if more than 1)',
'',PathVariable.PathAccept))
opts.Add(PathVariable('EXTRA_INCLUDE_PATH',
'Extra paths for header files (separated by : if more than 1)',
'',PathVariable.PathAccept))
opts.Add(BoolVariable('IMPORT_PATHS',
'Import PATH, C_INCLUDE_PATH and LIBRARY_PATH/LD_LIBRARY_PATH environment variables',
False))
opts.Add(BoolVariable('IMPORT_ENV',
'Import full environment from calling shell', True))
opts.Add(BoolVariable('IMPORT_PREFIX',
'Use PREFIX/include and PREFIX/lib in search paths', False))
opts.Add(BoolVariable('WITH_BLAS',
'Look for blas libraries and link if found.', True))
opts.Add(BoolVariable('WITH_LAPACK',
'Look for lapack libraries and link if found.', False))
opts.Add(BoolVariable('FORCE_MKL',
'Force scons to use MKL for BLAS and/or LAPACK', False))
opts.Add(BoolVariable('FORCE_ACML',
'Force scons to use ACML for BLAS and/or LAPACK', False))
#opts.Add(BoolVariable('FORCE_CLAMD',
#'Force scons to use clAmdBlas', False))
opts.Add(BoolVariable('FORCE_GOTO',
'Force scons to use GOTO BLAS', False))
opts.Add(BoolVariable('FORCE_ATLAS',
'Force scons to use ATLAS for BLAS', False))
opts.Add(BoolVariable('FORCE_CBLAS',
'Force scons to use CBLAS', False))
opts.Add(BoolVariable('FORCE_FBLAS',
'Force scons to use Fortran BLAS', False))
opts.Add(BoolVariable('FORCE_CLAPACK',
'Force scons to use CLAPACK', False))
opts.Add(BoolVariable('FORCE_ATLAS_LAPACK',
'Force scons to use ATLAS subset of LAPACK', False))
opts.Add(BoolVariable('FORCE_FLAPACK',
'Force scons to use Fortran LAPACK', False))
opts.Add(BoolVariable('USE_STEGR',
'Use the LAPACK function ?stegr for finding eigenvectors', False))
opts.Add(BoolVariable('USE_GEQP3',
'Use the LAPACK function ?qeqp3 for finding strict QRP decomposition', False))
opts.Add('LIBS','Libraries to send to the linker','')
opts.Add('LINKFLAGS','Flags to use when linking','')
opts.Add(BoolVariable('TEST_DEBUG',
'Turn on debugging statements in the test suite',False))
opts.Add(BoolVariable('STATIC','Use static linkage', False))
opts.Add(BoolVariable('WITH_SSE',
'Use SSE commands (only necessary for icpc compilations)', True))
opts.Add('XTEST',
'Do extra tests in the test suite (1=non-unit step, 2=extra sizes/shapes, 4=mix real/complex, 8=degenerate, 16=extra arithmetic, 32=FortranStyle, 64=extreme matrices) ', 0)
opts.Add(BoolVariable('MEM_DEBUG','Do extra tests for memory leaks other memroy problems', False))
opts.Add(BoolVariable('NAN_TEST','Test memory initialized with nans', False))
opts.Add(BoolVariable('SMALL_TESTS',
'Make the small test programs: tmvtest1a, tmvtest1b, etc.', False))
opts.Add(BoolVariable('WARN',
'Add warning compiler flags, like -Wall', False))
opts.Add(BoolVariable('PROFILE',
'Add profiling compiler flags like -pg', False))
opts.Add(BoolVariable('CACHE_LIB',
'Cache the results of the library checks', True))
opts.Add(BoolVariable('WITH_UPS',
'Install the ups directory under PREFIX/ups', False))
opts.Add('N_BUILD_THREADS',
'Number of build threads to use (0 means use ncpus)', 0)
opts.Add(BoolVariable('USE_UNKNOWN_VARS',
'Allow other parameters besides the ones listed here.',False))
# This helps us determine of openmp is available
openmp_mingcc_vers = 4.1
openmp_minclang_vers = 3.7
openmp_minicpc_vers = 9.1 # 9.0 is supposed to work but has bugs
openmp_minpgcc_vers = 6.0
openmp_mincc_vers = 5.0 # I don't actually know what this should be.
# used only in /bin right now
def RunInstall(env, targets, subdir):
install_dir = os.path.join(env['INSTALL_PREFIX'], subdir)
env.Alias(target='install',
source=env.Install(dir=install_dir, source=targets))
def RunUninstall(env, targets, subdir):
# There is no env.Uninstall method, we must build our own
install_dir = os.path.join(env['INSTALL_PREFIX'], subdir)
deltarget = Delete("$TARGET")
# delete from $prefix/bin/
files = []
for t in targets:
ifile = os.path.join(install_dir, os.path.basename(str(t)))
files.append(ifile)
for f in files:
env.Alias('uninstall', env.Command(f, None, deltarget))
def BasicCCFlags(env):
"""
"""
compiler = env['CXXTYPE']
version = env['CXXVERSION_NUMERICAL']
# First parse the LIBS options if present
if env['LIBS'] == '':
env.Replace(LIBS=[])
else:
libs = env['LIBS'].split(' ')
env.Replace(LIBS=libs)
if compiler == 'g++':
if version >= 4.4:
# Workaround for a bug in the g++ v4.4 exception handling
# I don't think 4.5 actually needs it, but keep >= for now
# just to be safe.
env.AppendUnique(LIBS='pthread')
if env['FLAGS'] == '':
if compiler == 'g++':
env.Replace(CCFLAGS=['-O2'])
env.Append(CCFLAGS=['-fno-strict-aliasing'])
env['TEST_FLAGS'] = ['-O0']
if env['PROFILE']:
env.Append(CCFLAGS=['-pg'])
env['TEST_FLAGS'] += ['-pg']
if env['WARN']:
env.Append(CCFLAGS=['-g3','-ansi','-pedantic-errors','-Wall','-Werror','-Wno-long-long'])
env['TEST_FLAGS'] += ['-g3','-ansi','-pedantic-errors','-Wall','-Werror','-Wno-long-long']
elif compiler == 'clang++':
env.Replace(CCFLAGS=['-O2'])
env['TEST_FLAGS'] = ['-O0']
if env['PROFILE']:
env.Append(CCFLAGS=['-pg'])
env['TEST_FLAGS'] += ['-pg']
if env['WARN']:
env.Append(CCFLAGS=['-g3','-ansi','-pedantic-errors','-Wall','-Werror','-Wno-long-long'])
env['TEST_FLAGS'] += ['-g3','-ansi','-pedantic-errors','-Wall','-Werror','-Wno-long-long']
elif compiler == 'icpc':
env.Replace(CCFLAGS=['-O2'])
if env['WITH_SSE']:
env.Append(CCFLAGS=['-msse2'])
env['TEST_FLAGS'] = ['-O0']
if env['PROFILE']:
env.Append(CCFLAGS=['-pg'])
env['TEST_FLAGS'] += ['-pg']
if env['WARN']:
env.Append(CCFLAGS=['-g','-Wall','-Werror','-wd279,383,810,981'])
env['TEST_FLAGS'] += ['-g','-Wall','-Werror','-wd279,383,810,981']
if version >= 9:
env.Append(CCFLAGS=['-wd1572'])
env['TEST_FLAGS'] += ['-wd1572']
if version >= 10 and env['WITH_BLAS']:
# These warning only show up in mkl.h:
env.Append(CCFLAGS=['-wd424,193'])
if version >= 11:
env.Append(CCFLAGS=['-wd2259'])
env['TEST_FLAGS'] += ['-wd2259']
elif compiler == 'pgCC':
env.Replace(CCFLAGS=['-O2','-fast','-Mcache_align'])
env['TEST_FLAGS'] = ['-O0']
if env['PROFILE']:
# Not sure if this is right...
env.Append(CCFLAGS=['-pg'])
env['TEST_FLAGS'] += ['-pg']
if env['WARN']:
env.Append(CCFLAGS=['-g'])
env['TEST_FLAGS'] += ['-g']
elif compiler == 'CC':
env.Replace(CCFLAGS=['-O2','-fast','-instances=semiexplicit'])
env['TEST_FLAGS'] = ['-O1','-instances=semiexplicit']
if env['WARN']:
env.Append(CCFLAGS=['-g','+w'])
env['TEST_FLAGS'] += ['-g','+w']
elif compiler == 'cl':
env.Replace(CCFLAGS=['/EHsc','/nologo','/O2','/Oi'])
env['TEST_FLAGS'] = ['/EHsc','/nologo','/O1']
if env['WARN']:
env.Append(CCFLAGS=['/W2','/WX'])
env['TEST_FLAGS'] += ['/W1','/WX']
else:
print('WARNING: Unknown compiler. You should set FLAGS directly.')
env.Replace(CCFLAGS=[])
env['TEST_FLAGS'] = []
else :
# If flags are specified as an option use them:
cxx_flags = env['FLAGS'].split(' ')
env.Replace(CCFLAGS=cxx_flags)
env['TEST_FLAGS'] = cxx_flags
cxx_flags = env['EXTRA_FLAGS'].split(' ')
env.AppendUnique(CCFLAGS=cxx_flags)
env['TEST_FLAGS'] += cxx_flags
def AddOpenMPFlag(env):
"""
Make sure you do this after you have determined the version of
the compiler.
g++ uses -fopemnp
clang++ uses -fopenmp starting with version 3.7
icpc uses -qopenmp for >= 17.0, -openmp before that
pgCC uses -mp
CC uses -xopenmp
Other compilers?
"""
compiler = env['CXXTYPE']
version = env['CXXVERSION_NUMERICAL']
if compiler == 'g++':
if version < openmp_mingcc_vers:
print('No OpenMP support for g++ versions before ',openmp_mingcc_vers)
env['WITH_OPENMP'] = False
return
flag = ['-fopenmp']
ldflag = ['-fopenmp']
xlib = ['pthread']
elif compiler == 'clang++':
if version < openmp_minclang_vers:
print('No OpenMP support for clang++ versions before ',openmp_minclang_vers)
env['WITH_OPENMP'] = False
return
flag = ['-fopenmp']
ldflag = ['-fopenmp']
xlib = ['pthread']
elif compiler == 'icpc':
if version < openmp_minicpc_vers:
print('No OpenMP support for icpc versions before ',openmp_minicpc_vers)
env['WITH_OPENMP'] = False
return
if version >= 17:
flag = ['-qopenmp']
ldflag = ['-qopenmp']
else:
flag = ['-openmp']
ldflag = ['-openmp']
xlib = ['pthread']
elif compiler == 'pgCC':
if version < openmp_minpgcc_vers:
print('No OpenMP support for pgCC versions before ',openmp_minpgcc_vers)
env['WITH_OPENMP'] = False
return
flag = ['-mp','--exceptions']
ldflag = ['-mp']
xlib = ['pthread']
elif compiler == 'CC':
if version < openmp_mincc_vers:
print('No OpenMP support for CC versions before ',openmp_mincc_vers)
env['WITH_OPENMP'] = False
return
flag = ['-xopenmp']
ldflag = ['-xopenmp']
xlib = ['pthread']
elif compiler == 'cl':
#flag = ['/openmp']
#ldflag = ['/openmp']
#xlib = []
# The Express edition, which is the one I have, doesn't come with
# the file omp.h, which we need. So I am unable to test TMV's
# OpenMP with cl.
# I believe the Professional edition has full OpenMP support,
# so if you have that, the above lines might work for you.
# Just uncomment those, and commend the below three lines.
print('No OpenMP support for cl')
env['WITH_OPENMP'] = False
return
else:
print('No OpenMP support for compiler ',compiler)
env['WITH_OPENMP'] = False
return
#print 'Adding openmp support:',flag
#print 'Using OpenMP'
env['OMP_FLAGS'] = flag
env.AppendUnique(CCFLAGS=flag)
env.AppendUnique(LINKFLAGS=ldflag)
env.AppendUnique(LIBS=xlib)
def which(program):
"""
Mimic functionality of unix which command
"""
def is_exe(fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
if sys.platform == "win32" and not program.endswith(".exe"):
program += ".exe"
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def GetCompilerVersion(env):
"""
"""
compiler = which(env['CXX'])
print('Using compiler:',compiler)
compiler_real = os.path.realpath(compiler)
compiler_base = os.path.basename(compiler)
# Get the compiler type without suffix or path.
# e.g. /sw/bin/g++-4 -> g++
if 'icpc' in compiler_base :
compilertype = 'icpc'
versionflag = '--version'
linenum=0
elif 'pgCC' in compiler_base :
compilertype = 'pgCC'
versionflag = '--version'
linenum=1
# pgCC puts the version number on the second line of output.
elif 'clang++' in compiler_base :
compilertype = 'clang++'
versionflag = '--version'
linenum=0
elif 'g++' in compiler_base :
compilertype = 'g++'
versionflag = '--version'
linenum=0
elif 'CC' in compiler_base :
compilertype = 'CC'
versionflag = '-V'
linenum=0
elif 'cl' in compiler_base :
compilertype = 'cl'
versionflag = ''
linenum=0
elif 'c++' in compiler_base :
compilertype = 'c++'
versionflag = '--version'
linenum=0
else :
compilertype = 'unknown'
version = 0
vnum = 0
if compilertype != 'unknown':
cmd = compiler + ' ' + versionflag + ' 2>&1'
lines = os.popen(cmd).readlines()
# Check if g++ is a symlink for something else:
if compilertype == 'g++':
if 'clang' in lines[0] or 'clang' in lines[1]:
print('Detected clang++ masquerading as g++')
compilertype = 'clang++'
# When it is masquerading, the line with the version is the second line.
linenum=1
# Check if c++ is a symlink for something else:
if compilertype == 'c++':
if 'clang' in lines[0] or 'clang' in lines[1]:
print('Detected that c++ is really clang++')
compilertype = 'clang++'
elif 'g++' in lines[0] or 'gcc' in lines[0]:
print('Detected that c++ is really g++')
compilertype = 'g++'
else:
print('Cannot determine what kind of compiler c++ really is')
compilertype = 'unknown'
# Any others I should look for?
# redo this check in case was c++ -> unknown
if compilertype != 'unknown':
line = lines[linenum]
import re
# For clange, the version can show up in one of two places depending on whether this is
# Apple clang or regular clang.
if 'LLVM' in line:
match = re.search(r'LLVM [0-9]+(\.[0-9]+)+', line)
match_num = 1
else:
match = re.search(r'[0-9]+(\.[0-9]+)+', line)
match_num = 0
if match:
version = match.group(match_num)
# Get the version up to the first decimal
# e.g. for 4.3.1 we only keep 4.3
vnum = version[0:version.find('.')+2]
else:
version = 0
vnum = 0
print('compiler version:',version)
env['CXXTYPE'] = compilertype
env['CXXVERSION'] = version
env['CXXVERSION_NUMERICAL'] = float(vnum)
def AddPath(pathlist, newpath):
"""
Add path(s) to a list of paths. Check the path exists and that it is
not already in the list
"""
if type(newpath) == list:
for l in newpath:
AddPath(pathlist, l)
else:
# to deal with expansions and possible end / which
# messes up uniqueness test
p = os.path.abspath(newpath)
if os.path.exists(p):
if pathlist.count(p) == 0:
pathlist.append(p)
def AddExtraPaths(env):
"""
Add some include and library paths.
Also merge in $PATH, $C_INCLUDE_PATH and $LIBRARY_PATH/$LD_LIBRARY_PATH
environment variables if requested.
The set itself is created in order of appearance here, but then this
whole set is prepended. The order within this list is:
local lib and include paths
paths in PREFIX directory
paths in EXTRA_*PATH parameters
paths from the user's environment
Only paths that actually exists are kept.
"""
# local includes and lib paths
# The # symbol means to interpret these from the top-level scons
# directory even when we are in a sub-directory (src,tests,etc.)
bin_paths = []
cpp_paths = ['#include']
lib_paths1 = ['#lib']
lib_paths2 = []
# PREFIX directory
env['INSTALL_PREFIX'] = env['PREFIX']
# FINAL_PREFIX is designed for installations like that done by fink where it installs
# everything into a temporary directory, and then once it finished successfully, it
# copies the resulting files to a final location. This pretty much just matters for the
# tmv-link file to have the right -L flag.
if env['FINAL_PREFIX'] == '':
env['FINAL_PREFIX'] = env['PREFIX']
if env['IMPORT_PREFIX']:
AddPath(bin_paths, os.path.join(env['PREFIX'],'bin'))
AddPath(cpp_paths, os.path.join(env['PREFIX'],'include'))
AddPath(lib_paths1, os.path.join(env['PREFIX'],'lib'))
# Paths specified in EXTRA_*
bin_paths += env['EXTRA_PATH'].split(':')
cpp_paths += env['EXTRA_INCLUDE_PATH'].split(':')
lib_paths2 += env['EXTRA_LIB_PATH'].split(':')
# Paths found in environment paths
if env['IMPORT_PATHS'] and 'PATH' in os.environ:
paths=os.environ['PATH']
paths=paths.split(os.pathsep)
AddPath(bin_paths, paths)
if env['IMPORT_PATHS'] and 'C_INCLUDE_PATH' in os.environ:
paths=os.environ['C_INCLUDE_PATH']
paths=paths.split(os.pathsep)
AddPath(cpp_paths, paths)
if env['IMPORT_PATHS'] and 'LIBRARY_PATH' in os.environ:
paths=os.environ['LIBRARY_PATH']
paths=paths.split(os.pathsep)
AddPath(lib_paths2, paths)
if env['IMPORT_PATHS'] and 'LD_LIBRARY_PATH' in os.environ:
paths=os.environ['LD_LIBRARY_PATH']
paths=paths.split(os.pathsep)
AddPath(lib_paths2, paths)
#print 'bin paths = ',bin_paths
#print 'cpp paths = ',cpp_paths
#print 'lib paths1 = ',lib_paths1
#print 'lib paths2 = ',lib_paths2
env.PrependENVPath('PATH', bin_paths)
env.Prepend(CPPPATH= cpp_paths)
env.Prepend(LIBPATH= lib_paths2)
env.Prepend(LIBPATH= lib_paths1)
env['LIBPATH2'] = lib_paths2 # used for the tmv-link file
def ReadFileList(fname):
"""
This reads a list of whitespace separated values from the input file fname
and stores it as a list. We will make this part of the environment so
other SConscripts can use it
"""
try:
files=open(fname).read().split()
except:
print('Could not open file:',fname)
sys.exit(45)
files = [f.strip() for f in files]
return files
def CheckLibs(context,try_libs,source_file):
init_libs = context.env['LIBS']
context.env.PrependUnique(LIBS=try_libs)
result = context.TryLink(source_file,'.cpp')
if not result :
context.env.Replace(LIBS=init_libs)
return result
def CheckOMP(context):
omp_source_file = """
#include <omp.h>
#include <vector>
int main()
{
double res=0.;
#pragma omp parallel
{
int num_threads = omp_get_num_threads();
int mythread = omp_get_thread_num();
std::vector<double> x(100);
#pragma omp parallel for
for (int i=0;i<100;i++) x[i] = i+ num_threads * mythread;
for (int i=0;i<100;i++) res *= x[i];
}
return int(res);
}
"""
context.Message('Checking for OpenMP library... ')
AddOpenMPFlag(context.env)
if context.TryCompile(omp_source_file,'.cpp'):
result = (
CheckLibs(context,[],omp_source_file) or
CheckLibs(context,['gomp'],omp_source_file) or
CheckLibs(context,['omp'],omp_source_file) or
False)
context.Result(result)
if not result:
print('Unable to determine correct OpenMP library.')
print('To enable OpenMP, you may need to explicitly specify the correct library')
print('with the LIBS flag.')
else:
result = 0
context.Result(result)
print('Unable to compile code using OpenMP pragmas.')
return result
def CheckMKL(context):
mkl_source_file = """
#include "mkl.h"
int main()
{
char ta='N', tb='N';
int M=1,N=1,K=1,lda=1,ldb=1,ldc=1;
double alpha=1.,beta=1., *A=0, *B=0, *C=0;
dgemm(&ta,&tb,&M,&N,&K,&alpha,A,&lda,B,&ldb,&beta,C,&ldc);
return 0;
}
"""
simple_source_file = "int main() { return 0; }\n"
context.Message('Checking for MKL... ')
if context.TryCompile(mkl_source_file,'.cpp'):
# If guide or iomp5 are available, link them along with pthread
pthread = ['pthread']
if CheckLibs(context,['guide']+pthread,simple_source_file):
pthread = ['guide']+pthread
if CheckLibs(context,['iomp5']+pthread,simple_source_file):
pthread = ['iomp5']+pthread
if CheckLibs(context,['dl']+pthread,simple_source_file):
pthread = ['dl']+pthread
# Try to pick out the correct thread library
if context.env['CXXTYPE'] == 'icpc':
threadlib = ['mkl_intel_thread']
elif context.env['CXXTYPE'] == 'pgCC':
threadlib = ['mkl_pgi_thread']
else:
threadlib = ['mkl_gnu_thread']
if CheckLibs(context,['gomp']+pthread,simple_source_file):
pthread = ['gomp']+pthread
result = (
CheckLibs(context,[],mkl_source_file) or
CheckLibs(context,['mkl'],mkl_source_file) or
CheckLibs(context,['mkl']+pthread,mkl_source_file) or
CheckLibs(context,['mkl_em64t']+pthread,mkl_source_file) or
CheckLibs(context,['mkl_ipf']+pthread,mkl_source_file) or
CheckLibs(context,['mkl_ia32']+pthread,mkl_source_file) or
CheckLibs(context,['mkl_intel_lp64','mkl_core']+threadlib+pthread,mkl_source_file) or
CheckLibs(context,['mkl_gf_lp64','mkl_core']+threadlib+pthread,mkl_source_file) or
CheckLibs(context,['mkl_intel_lp64','mkl_core','mkl_sequential'],mkl_source_file) or
CheckLibs(context,['mkl_intel_lp64','mkl_core','mkl_sequential']+pthread,mkl_source_file) or
CheckLibs(context,['mkl_gf_lp64','mkl_core','mkl_sequential'],mkl_source_file) or
CheckLibs(context,['mkl_gf_lp64','mkl_core','mkl_sequential']+pthread,mkl_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_MKL']:
print('WARNING: Forced use of MKL even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your MKL version.")
print(" You should figure out what libraries you need to link with here:")
print(" http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_MKL']:
print()
print('Error: FORCE_MKL, but failed to find or compile with mkl.h')
Exit(1)
return result
def CheckACML(context):
acml_source_file = """
#include "acml.h"
int main()
{
char uplo='U', compq='I';
int n=1,ldu=1,ldv=1,*iq=0,*info=0;
double *d=0, *e=0, *u=0, *v=0, *q=0;
dbdsdc(uplo,compq,n,d,e,u,ldu,v,ldv,q,iq,info);
return 0;
}
"""
context.Message('Checking for ACML... ')
if context.TryCompile(acml_source_file,'.cpp'):
result = (
CheckLibs(context,[],acml_source_file) or
CheckLibs(context,['acml'],acml_source_file) or
CheckLibs(context,['acml','gfortran'],acml_source_file) or
CheckLibs(context,['acml','gfortran','pthread'],acml_source_file) or
CheckLibs(context,['acml','pgftnrtl'],acml_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_ACML']:
print('WARNING: Forced use of ACML even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your ACML version.")
print(" You should figure out what libraries you need to link with")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_ACML']:
print()
print('Error: FORCE_ACML, but failed to find or compile with acml.h')
Exit(1)
return result
def CheckCLAMD(context):
# NB: This doesn't work yet...
clamd_source_file = """
#include "clAmdBlas.h"
int main()
{
char ta='N', tb='N';
int M=1,N=1,K=1,lda=1,ldb=1,ldc=1;
double alpha=1.,beta=1., *A=0, *B=0, *C=0;
dgemm_(ta,tb,M,N,K,alpha,A,lda,B,ldb,beta,C,ldc,1,1);
return 0;
}
"""
context.Message('Checking for clAmdBlas... ')
if context.TryCompile(clamd_source_file,'.cpp'):
result = (
CheckLibs(context,[],clamd_source_file) or
CheckLibs(context,['clAmdBlas'],clamd_source_file) or
CheckLibs(context,['clAmdBlas','OpenCL'],clamd_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_CLAMD']:
print('WARNING: Forced use of clAmdBlas even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your CLAMD version.")
print(" You should figure out what libraries you need to link with")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_CLAMD']:
print()
print('Error: FORCE_CLAMD, but failed to find or compile with clAmdBlas.h')
Exit(1)
return result
def CheckGOTO(context):
fblas_source_file = """
extern "C" {
#include "../src/fblas.h"
}
int main()
{
char ta='N', tb='N';
int M=1,N=1,K=1,lda=1,ldb=1,ldc=1;
double alpha=1.,beta=1., *A=0, *B=0, *C=0;
dgemm_(ta,tb,M,N,K,alpha,A,lda,B,ldb,beta,C,ldc,1,1);
return 0;
}
"""
context.Message('Checking for GotoBLAS... ')
if context.TryCompile(fblas_source_file,'.cpp'):
result = (
CheckLibs(context,[],fblas_source_file) or
CheckLibs(context,['goto2'],fblas_source_file) or
CheckLibs(context,['goto2','pthread'],fblas_source_file) or
CheckLibs(context,['goto2','gomp','pthread'],fblas_source_file) or
CheckLibs(context,['goto2','gfortran'],fblas_source_file) or
CheckLibs(context,['goto2','gfortran','pthread'],fblas_source_file) or
CheckLibs(context,['goto2','gfortran','gomp','pthread'],fblas_source_file) or
CheckLibs(context,['goto2','pgftnrtl'],fblas_source_file) or
CheckLibs(context,['goto'],fblas_source_file) or
CheckLibs(context,['goto','pthread'],fblas_source_file) or
CheckLibs(context,['goto','gomp','pthread'],fblas_source_file) or
CheckLibs(context,['goto','gfortran'],fblas_source_file) or
CheckLibs(context,['goto','gfortran','pthread'],fblas_source_file) or
CheckLibs(context,['goto','gfortran','gomp','pthread'],fblas_source_file) or
CheckLibs(context,['goto','pgftnrtl'],fblas_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_GOTO']:
print('WARNING: Forced use of GOTO even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your GOTOBLAS version.")
print(" You should figure out what libraries you need to link with")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_GOTO']:
print()
print('Error: FORCE_GOTO, but failed compile test')
Exit(1)
return result
def CheckATLAS(context):
atlas_source_file = """
extern "C" {
#include "cblas.h"
}
int main()
{
int M=1,N=1,K=1,lda=1,ldb=1,ldc=1;
double alpha=1.,beta=1., *A=0, *B=0, *C=0;
cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,
M,N,K,alpha,A,lda,B,ldb,beta,C,ldc);
return 0;
}
"""
context.Message('Checking for ATLAS... ')
if context.TryCompile(atlas_source_file,'.cpp'):
result = (
CheckLibs(context,[],atlas_source_file) or
CheckLibs(context,['ptcblas','atlas'],atlas_source_file) or
CheckLibs(context,['ptcblas','atlas','pthread'],atlas_source_file) or
CheckLibs(context,['ptcblas','atlas','guide','pthread'],atlas_source_file) or
CheckLibs(context,['cblas','atlas'],atlas_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_ATLAS']:
print('WARNING: Forced use of ATLAS even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your ATLAS version.")
print(" You should figure out what libraries you need to link with")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_ATLAS']:
print()
print('Error: FORCE_ATLAS, but failed to find or compile with cblas.h')
Exit(1)
return result
def CheckCBLAS(context):
cblas_source_file = """
extern "C" {
#include "cblas.h"
}
int main()
{
int M=1,N=1,K=1,lda=1,ldb=1,ldc=1;
double alpha=1.,beta=1., *A=0, *B=0, *C=0;
cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,
M,N,K,alpha,A,lda,B,ldb,beta,C,ldc);
return 0;
}
"""
context.Message('Checking for CBLAS... ')
if context.TryCompile(cblas_source_file,'.cpp'):
result = (
CheckLibs(context,[],cblas_source_file) or
CheckLibs(context,['cblas'],cblas_source_file) or
CheckLibs(context,['cblas','gfortran'],cblas_source_file) or
CheckLibs(context,['cblas','pgftnrtl'],cblas_source_file) or
CheckLibs(context,['blas','gfortran'],cblas_source_file) or
CheckLibs(context,['blas','pgftnrtl'],cblas_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_CBLAS']:
print('WARNING: Forced use of CBLAS even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your BLAS version.")
print(" You should figure out what libraries you need to link with")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_CBLAS']:
print()
print('Error: FORCE_CBLAS, but failed to find or compile with cblas.h')
Exit(1)
return result
def CheckFBLAS(context):
fblas_source_file = """
extern "C" {
#include "../src/fblas.h"
}
int main()
{
char ta='N', tb='N';
int M=1,N=1,K=1,lda=1,ldb=1,ldc=1;
double alpha=1.,beta=1., *A=0, *B=0, *C=0;
dgemm_(ta,tb,M,N,K,alpha,A,lda,B,ldb,beta,C,ldc,1,1);
return 0;
}
"""
context.Message('Checking for Fortran BLAS... ')
if context.TryCompile(fblas_source_file,'.cpp'):
result = (
CheckLibs(context,[],fblas_source_file) or
CheckLibs(context,['blas'],fblas_source_file) or
CheckLibs(context,['blas','gfortran'],fblas_source_file) or
CheckLibs(context,['blas','pgftnrtl'],fblas_source_file) or
False)
context.Result(result)
if not result and context.env['FORCE_FBLAS']:
print('WARNING: Forced use of FBLAS even though link test failed.')
print(" The compiled library will not have the correct linking commands")
print(" set up for your BLAS version.")
print(" You should figure out what libraries you need to link with")
print(" and add them explicitly with the LIBS option in SCons.")
result = 1
else:
result = 0
context.Result(result)
if context.env['FORCE_FBLAS']:
print()
print('Error: FORCE_FBLAS, but failed compile test')
Exit(1)
return result
def CheckMKL_LAP(context):
mkl_lap_source_file = """