This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validate.py
267 lines (212 loc) · 8.65 KB
/
validate.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
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
#
# This script works only with Python 3
#
import os
import re
#import sys
#import time
#import random
import argparse
from zipfile import ZipFile
import create_initial_conditions
import Test
#import AnswerDatabase
#import __main__
#MaxParticlesInSequentialUpscalingStudies = 2000
MaxParticlesInSequentialUpscalingStudies = 200
#MaxParticlesInSequentialUpscalingStudies = 200
def step1(zip):
f = zip.open("step-1.cpp")
content = f.read()
f = open('step-1.cpp', 'wb')
f.write(content)
f.close()
print( "========" )
print( " Step 1" )
print( "========" )
print( "Extracted step-1.cpp ... ok" )
test = Test.Test( "step-1.cpp" )
arguments = "icpc --std=c++0x"
result = test.compile( arguments )
if result==1:
print( "Compiled source code with " + arguments + " ... ok" )
else:
print( "Compiled source code with " + arguments + " ... failed: " + test.last_output )
arguments = create_initial_conditions.create_no_noise_grid_setup( 0, 1, 0.0001, 0.1, 0.1, [2,1,1] )
print( "Run code with " + arguments )
result = test.run( arguments )
if result==1:
print( "Run terminated successfully ... ok" )
else:
print( "Run failed: " + test.last_output )
search_pattern = "([-+]?\d*\.\d+|\d+), *([-+]?\d*\.\d+|\d+), *([-+]?\d*\.\d+|\d+)"
result = test.search_for_pattern_in_output(search_pattern)
if result!="":
print( "Got " + result + " as last output which I interprete to be a particle position ... ok (though that does not mean that the data is correct; that's something I don't validate here)" )
else:
print( "Last line of output should still be the one I used in the template ... failed" )
def step2(zip):
f = zip.open("step-2.cpp")
content = f.read()
f = open('step-2.cpp', 'wb')
f.write(content)
f.close()
print( "========" )
print( " Step 2" )
print( "========" )
print( "Extracted step-2.cpp ... ok" )
test = Test.Test( "step-2.cpp" )
arguments = "icpc --std=c++0x -no-vec"
result = test.compile( arguments )
if result==1:
print( "Compiled source code with " + arguments + " ... ok" )
else:
print( "Compiled source code with " + arguments + " ... failed: " + test.last_output )
particles_counts = [11,11,11]
arguments = create_initial_conditions.create_random_grid_setup( 0, 10, 0.0001, 0.1, 0.01, particles_counts )
print( "Run code with " + str(particles_counts[0]*particles_counts[1]*particles_counts[2]) + " particles" )
result = test.run( arguments )
if result==1:
print( "Run terminated successfully ... ok" )
else:
print( "Run failed: " + test.last_output )
no_vec_time = test.runtime
arguments = "icpc -O3 -xhost -fopenmp --std=c++0x"
result = test.compile( arguments )
if result==1:
print( "Compiled source code with " + arguments + " ... ok" )
else:
print( "Compiled source code with " + arguments + " ... failed: " + test.last_output )
particles_counts = [11,11,11]
arguments = create_initial_conditions.create_random_grid_setup( 0, 10, 0.0001, 0.1, 0.01, particles_counts )
print( "Run code with " + str(particles_counts[0]*particles_counts[1]*particles_counts[2]) + " particles" )
result = test.run( arguments )
if result==1:
print( "Run terminated successfully ... ok" )
else:
print( "Run failed: " + test.last_output )
with_vec_time = test.runtime
if no_vec_time<=with_vec_time:
print( "Code is slower with vectorisation, so you might want to tune it ... check" )
else:
print( "Code is already faster by a factor of " + str(no_vec_time/with_vec_time) + " through vectorisation but you might want to tune it further ... ok" )
def step3(zip):
f = zip.open("step-3.cpp")
content = f.read()
f = open('step-3.cpp', 'wb')
f.write(content)
f.close()
print( "========" )
print( " Step 3" )
print( "========" )
print( "Extracted step-3.cpp ... ok" )
test = Test.Test( "step-3.cpp" )
arguments = "icpc -O3 -xhost -fopenmp --std=c++0x"
result = test.compile( arguments )
if result==1:
print( "Compiled source code with " + arguments + " ... ok" )
else:
print( "Compiled source code with " + arguments + " ... failed: " + test.last_output )
arguments = create_initial_conditions.create_no_noise_grid_setup( 0, 1, 0.0001, 0.1, 0.1, [2,1,1] )
print( "Run code with " + arguments )
result = test.run( arguments )
if result==1:
print( "Run terminated successfully ... ok (but this does not mean that the outcome is correct)" )
else:
print( "Run failed: " + test.last_output )
def step4(zip):
f = zip.open("step-4.cpp")
content = f.read()
f = open('step-4.cpp', 'wb')
f.write(content)
f.close()
print( "========" )
print( " Step 4" )
print( "========" )
print( "Extracted step-4.cpp ... ok" )
test = Test.Test( "step-4.cpp" )
arguments = "icpc -O3 -xhost --std=c++0x -fopenmp"
result = test.compile( arguments )
if result==1:
print( "Compiled source code with " + arguments + " ... ok" )
else:
print( "Compiled source code with " + arguments + " ... failed: " + test.last_output )
particles_counts = [11,11,11]
arguments = create_initial_conditions.create_random_grid_setup( 0, 10, 0.0001, 0.1, 0.01, particles_counts )
print( "Run code with " + str(particles_counts[0]*particles_counts[1]*particles_counts[2]) + " particles" )
print( "Test for one core" )
result = test.run( arguments, {"OMP_NUM_THREADS": "1"} )
if result==1:
print( "Run terminated successfully after " + str(test.runtime) + "s ... ok" )
else:
print( "Run failed: " + test.last_output )
serial_runtime = test.runtime
for p in range(2,28,2):
print( "Test for " + str(p) + " cores" )
result = test.run( arguments, {"OMP_NUM_THREADS": str(p)} )
speedup = serial_runtime/test.runtime
if result==1 and speedup>1:
print( "Run terminated successfully after " + str(test.runtime) + "s, i.e. with speedup of " + str(speedup) + " ... ok (but you might want to tune it further)" )
elif result==1:
print( "Run terminated successfully after " + str(test.runtime) + "s, i.e. with deterioriated speedup ... check (but check runtimes)" )
else:
print( "Run failed: " + test.last_output )
def step5(zip):
f = zip.open("report.pdf")
content = f.read()
f = open('report.pdf', 'wb')
f.write(content)
f.close()
print( "========" )
print( " Step 5" )
print( "========" )
print( "Extracted report.pdf ... ok" )
if __name__=="__main__":
parser = argparse.ArgumentParser(description="""Parallel Scientific Programming I -
This is a small Python script to validate that the format of a submission
is valid. It does not check for any correctness (though it gives some clues
on the performance). If you use the script on Hamilton - which is the type of
machine
I plan to use to assess the submissions - you have to load appropriate modules.
I use python/3.6.8 and then need an Intel compiler. The environment has recently
been updated, so use the latest Intel compiler to get best performance:
module load python/3.6.8 intel/2020.4;
As always, I recommend to use a compute node rather than the login nodes. To do
this, you have to call something like
salloc -N 1 -p test.q python3 validate.py test.zip;
""")
parser.add_argument("--validate", dest="validation_run", action="store_true", help="Validate whether submission is valid", default=True )
parser.add_argument("zipfile", help="zip archive" )
args = parser.parse_args()
try:
with ZipFile(args.zipfile, 'r') as zip:
#
#
#
print( "Open zip file " + args.zipfile )
submitted_number_of_zip_files = len(zip.infolist())
correct_number_of_zip_files = 5
if submitted_number_of_zip_files==correct_number_of_zip_files:
print( "Number of archived files: " + str(submitted_number_of_zip_files) + " ... ok" )
else:
print( "Number of archived files: " + str(submitted_number_of_zip_files) + " ... wrong. Should be exactly " + str(correct_number_of_zip_files ) )
step1(zip)
step2(zip)
step3(zip)
step4(zip)
step5(zip)
print( """
Disclaimer: This is a sole sanity check, i.e. I'll run further tests on correctness and scalability
when I mark the coursework. But the script ensures that your submission is formally correct plus it
also does some very basic checks.
""")
arguments = "-fopenmp -O3 -xhost --std=c++0x"
#
# Clean-up
#
output_files = [ f for f in os.listdir(".") if "extracted" in f or ".cpp" in f]
for f in output_files:
os.remove(f)
print( "Cleaned up all extracted files ... ok" )
except Exception as e:
print( "Sorry, could not validate/read input file: " + str(e) )