wscript 5.47 KB
Newer Older
1
2
#!/usr/bin/env python
# encoding: utf-8
3
4
import sys
sys.path.insert(0, './waf_tools')
5

6
7
VERSION = '0.0.1'
APPNAME = 'limbo'
8
9
10
11

srcdir = '.'
blddir = 'build'

12
import glob
13
14
import os
import subprocess
15
import limbo
16
from waflib.Build import BuildContext
17

Federico Allocati's avatar
Federico Allocati committed
18
19
import inspect

20

21
22
23
24
25
def options(opt):
        opt.load('compiler_cxx boost waf_unit_test')
        opt.load('compiler_c')
        opt.load('eigen')
        opt.load('tbb')
26
        opt.load('mkl')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
27
        opt.load('sferes')
28
        opt.load('limbo')
29
        opt.load('openmp')
30
        opt.load('nlopt')
31
32
        opt.load('libcmaes')

33
        opt.add_option('--exp', type='string', help='exp(s) to build, separate by comma', dest='exp')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
34
35
        opt.add_option('--qsub', type='string', help='config file (json) to submit to torque', dest='qsub')
        opt.add_option('--oar', type='string', help='config file (json) to submit to oar', dest='oar')
36
        opt.add_option('--experimental', action='store_true', help='specify to compile the experimental examples', dest='experimental')
37
        opt.add_option('--nb_replicates', type='int', help='number of replicates performed during the benchmark', dest='nb_rep')
38
	# tests
39
        opt.add_option('--tests', action='store_true', help='compile tests or not', dest='tests')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
40
        opt.load('xcode')
41
        for i in glob.glob('exp/*'):
Federico Allocati's avatar
Federico Allocati committed
42
43
                if os.path.isdir(i):
                    opt.recurse(i)
44

45
46
47
	opt.recurse('src/benchmarks')
		

48

49
def configure(conf):
50
        conf.load('compiler_cxx boost waf_unit_test')
51
52
53
        conf.load('compiler_c')
        conf.load('eigen')
        conf.load('tbb')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
54
        conf.load('sferes')
55
        conf.load('openmp')
56
        conf.load('mkl')
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
57
        conf.load('xcode')
58
        conf.load('nlopt')
59
        conf.load('libcmaes')
60

61
62
63
        if conf.env.CXX_NAME in ["icc", "icpc"]:
            common_flags = "-Wall -std=c++11"
            opt_flags = " -O3 -xHost  -march=native -mtune=native -unroll -fma -g"
64
        else:
65
            if conf.env.CXX_NAME in ["gcc", "g++"] and int(conf.env['CC_VERSION'][0]+conf.env['CC_VERSION'][1]) < 47:
66
67
68
                common_flags = "-Wall -std=c++0x"
            else:
                common_flags = "-Wall -std=c++11"
69
70
            if conf.env.CXX_NAME in ["clang", "llvm"]:
                common_flags += " -fdiagnostics-color"
71
            opt_flags = " -O3 -march=native -g"
72

73
        conf.check_boost(lib='serialization filesystem \
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
74
            system unit_test_framework program_options \
75
            graph thread', min_version='1.39')
76
77
        conf.check_eigen()
        conf.check_tbb()
78
        conf.check_sferes()
79
80
        conf.check_openmp()
        conf.check_mkl()
81
        conf.check_nlopt()
82
        conf.check_libcmaes()
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
83

Federico Allocati's avatar
Federico Allocati committed
84
85
        conf.env.INCLUDES_LIMBO = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/src"

86
87
        all_flags = common_flags + opt_flags
        conf.env['CXXFLAGS'] = conf.env['CXXFLAGS'] + all_flags.split(' ')
88
89
        print conf.env['CXXFLAGS']

Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
90
91
92
93
        if conf.options.exp:
                for i in conf.options.exp.split(','):
                        print 'configuring for exp: ' + i
                        conf.recurse('exp/' + i)
94
	conf.recurse('src/benchmarks')
Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
95

96
def build(bld):
97
98
99
100
101
    bld.recurse('src/')
    if bld.options.exp:
        for i in bld.options.exp.split(','):
            print 'Building exp: ' + i
            bld.recurse('exp/' + i)
102
    bld.add_post_fun(limbo.summary)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
103

104

105
def build_extensive_tests(ctx):
106
    ctx.recurse('src/')
107
108
    ctx.recurse('src/tests')

109
110
111
112
113
114
115
def run_extensive_tests(ctx):
    for fullname in glob.glob('build/src/tests/combinations/*'):
        if os.path.isfile(fullname) and os.access(fullname, os.X_OK):
            fpath, fname = os.path.split(fullname)
            print "Running: " + fname
            s = "cd " + fpath + "; ./" + fname
            retcode = subprocess.call(s, shell=True, env=None)
116

117
118
119
120
def submit_extensive_tests(ctx):
    for fullname in glob.glob('build/src/tests/combinations/*'):
        if os.path.isfile(fullname) and os.access(fullname, os.X_OK):
            fpath, fname = os.path.split(fullname)
121
            s = "cd " + fpath + ";oarsub -l /nodes=1/core=2,walltime=00:15:00 -n " + fname + " -O " + fname + ".stdout.%jobid%.log -E " + fname + ".stderr.%jobid%.log ./" + fname
122
123
124
            retcode = subprocess.call(s, shell=True, env=None)
            print "oarsub returned:" + str(retcode)

125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
def run_benchmark(ctx):
	HEADER='\033[95m'
	NC='\033[0m'
	res_dir=os.getcwd()+"/benchmark_results/"
	try:
                    os.makedirs(res_dir)
	except:
                    print "WARNING, dir:" + res_dir + " not be created"
	for fullname in glob.glob('build/src/benchmarks/*'):
		if os.path.isfile(fullname) and os.access(fullname, os.X_OK):
			fpath, fname = os.path.split(fullname)
			directory = res_dir + "/" + fname 
			try:
				os.makedirs(directory)
			except:
140
				print "WARNING, dir:" + directory + " not be created, the new results will be concatenated to the old ones"
141
142
			s = "cp " + fullname + " " + directory
			retcode = subprocess.call(s, shell=True, env=None)
143
144
145
146
147
			if ctx.options.nb_rep:
				nb_rep = ctx.options.nb_rep
			else:
				nb_rep = 10
			for i in range(0,nb_rep):
148
149
150
151
152
				print HEADER+" Running: " + fname + " for the "+str(i)+"th time"+NC
				s="cd " + directory +";./" + fname
				retcode = subprocess.call(s, shell=True, env=None)
			
			
153

154
def shutdown(ctx):
155
156
    if ctx.options.qsub:
        limbo.qsub(ctx.options.qsub)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
157
158
    if ctx.options.oar:
        limbo.oar(ctx.options.oar)
159
160
161
162
163


class BuildExtensiveTestsContext(BuildContext):
    cmd = 'build_extensive_tests'
    fun = 'build_extensive_tests'