wscript 7.45 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
Federico Allocati's avatar
Federico Allocati committed
16
import inspect
17
from waflib.Build import BuildContext
18

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

Vaios Papaspyros's avatar
Vaios Papaspyros committed
32
        opt.add_option('--create', type='string', help='create a new exp', dest='create_exp')
33
        limbo.add_create_options(opt)
34
        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
35
36
        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')
37
        opt.add_option('--local', type='string', help='config file (json) to run local', dest='local')
38
        opt.add_option('--local_serial', type='string', help='config file (json) to run local', dest='local_serial')
39
        opt.add_option('--experimental', action='store_true', help='specify to compile the experimental examples', dest='experimental')
40
        opt.add_option('--nb_replicates', type='int', help='number of replicates performed during the benchmark', dest='nb_rep')
41
        opt.add_option('--tests', action='store_true', help='compile tests or not', dest='tests')
42
43
        opt.add_option('--write_params', type='string', help='write all the default values of parameters in a file (used by the documentation system)', dest='write_params')

44
        for i in glob.glob('exp/*'):
Federico Allocati's avatar
Federico Allocati committed
45
46
                if os.path.isdir(i):
                    opt.recurse(i)
47

48
        opt.recurse('src/benchmarks')
49

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

62
63
64
        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"
65
        else:
66
            if conf.env.CXX_NAME in ["gcc", "g++"] and int(conf.env['CC_VERSION'][0]+conf.env['CC_VERSION'][1]) < 47:
67
68
69
                common_flags = "-Wall -std=c++0x"
            else:
                common_flags = "-Wall -std=c++11"
70
71
            if conf.env.CXX_NAME in ["clang", "llvm"]:
                common_flags += " -fdiagnostics-color"
72
            opt_flags = " -O3 -march=native -g"
73

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

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

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

Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
91
92
93
94
        if conf.options.exp:
                for i in conf.options.exp.split(','):
                        print 'configuring for exp: ' + i
                        conf.recurse('exp/' + i)
95
        conf.recurse('src/benchmarks')
96
97
98
99
100
101
102
103
104
        print ''
        print 'WHAT TO DO NOW?'
        print '---------------'
        print '[users] To compile Limbo (inc. unit tests): ./waf build'
        print '[users] Read the documentation (inc. tutorials) on http://www.resibots.eu/limbo'
        print '[developpers] To compile the HTML documentation (this requires sphinx and the resibots theme): ./waf doc'
        print '[developpers] To compile the benchmarks: ./waf build_benchmarks'
        print '[developpers] To compile the extensive tests: ./waf build_extensive_tests'

Jean-Baptiste Mouret's avatar
misc    
Jean-Baptiste Mouret committed
105

106
def build(bld):
107
108
109
    if bld.options.write_params:
        limbo.write_default_params(bld.options.write_params)
        print 'default parameters written in ' + bld.options.write_params
110
111
112
113
114
    bld.recurse('src/')
    if bld.options.exp:
        for i in bld.options.exp.split(','):
            print 'Building exp: ' + i
            bld.recurse('exp/' + i)
115
            limbo.output_params('exp/'+i)
116
    bld.add_post_fun(limbo.summary)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
117

118
def build_extensive_tests(ctx):
119
    ctx.recurse('src/')
120
121
    ctx.recurse('src/tests')

122
123
124
def build_benchmark(ctx):
    ctx.recurse('src/benchmarks')

125
126
127
128
129
130
131
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)
132

133
134
135
136
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)
137
            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
138
139
140
            retcode = subprocess.call(s, shell=True, env=None)
            print "oarsub returned:" + str(retcode)

141
def run_benchmark(ctx):
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
    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:
                print "WARNING, dir:" + directory + " not be created, the new results will be concatenated to the old ones"
            s = "cp " + fullname + " " + directory
            retcode = subprocess.call(s, shell=True, env=None)
            if ctx.options.nb_rep:
                nb_rep = ctx.options.nb_rep
            else:
                nb_rep = 10
            for i in range(0,nb_rep):
                print HEADER+" Running: " + fname + " for the "+str(i)+"th time"+NC
                s="cd " + directory +";./" + fname
                retcode = subprocess.call(s, shell=True, env=None)
167

168
def shutdown(ctx):
Vaios Papaspyros's avatar
Vaios Papaspyros committed
169
    if ctx.options.create_exp:
170
        limbo.create_exp(ctx.options.create_exp, ctx.options)
171
172
    if ctx.options.qsub:
        limbo.qsub(ctx.options.qsub)
Jean-Baptiste Mouret's avatar
Jean-Baptiste Mouret committed
173
174
    if ctx.options.oar:
        limbo.oar(ctx.options.oar)
175
    if ctx.options.local:
176
177
178
        limbo.run_local(ctx.options.local, False)
    if ctx.options.local_serial:
        limbo.run_local(ctx.options.local_serial)
179

180
181
182
183
def build_docs(ctx):
    s = "cd docs; make html"
    retcode = subprocess.call(s, shell=True, env=None)

184
185
186
class BuildExtensiveTestsContext(BuildContext):
    cmd = 'build_extensive_tests'
    fun = 'build_extensive_tests'
187
188
189
190

class BuildBenchmark(BuildContext):
    cmd = 'build_benchmark'
    fun = 'build_benchmark'
191
192
193
194

class BuildDoc(BuildContext):
    cmd = 'docs'
    fun = 'build_docs'