@@ -199,7 +199,7 @@ def generate_c_file(file_prefix_in, my_id, num_functions, call_depth, extern, ut
199
199
f .close ()
200
200
201
201
# compile a .c file into a Python-usable .so file
202
- def compile_file (file_prefix , i , num_utility_files , include_dir , CC ):
202
+ def compile_file (file_prefix , num_module_files , num_utility_files , include_dir , CC ):
203
203
filename = file_prefix + '.c'
204
204
cwd = os .getcwd ()
205
205
outfile = file_prefix + '.so'
@@ -208,6 +208,9 @@ def compile_file(file_prefix, i, num_utility_files, include_dir, CC):
208
208
else :
209
209
command = '%s -g -fPIC -shared' % (CC )
210
210
if file_prefix .find ('module' ) != - 1 :
211
+ if file_prefix .find ('begin' ) != - 1 :
212
+ for i in range (num_module_files ):
213
+ command += ' -lmodule' + str (i )
211
214
command += ' -I%s' % (include_dir )
212
215
command += ' -Wl,-rpath=' + cwd + ' -L' + cwd
213
216
for i in range (num_utility_files ):
@@ -260,6 +263,7 @@ def barrier(self):
260
263
"""
261
264
f .write (text )
262
265
266
+ f .write ('import libmodulebegin\n ' )
263
267
for i in range (num_files ):
264
268
f .write ('import libmodule' + str (i ) + '\n ' )
265
269
f .write ('import libmodulefinal\n ' )
@@ -274,6 +278,7 @@ def barrier(self):
274
278
"""
275
279
f .write (text )
276
280
281
+ f .write ('libmodulebegin.begin_break_here()\n ' )
277
282
for i in range (num_files ):
278
283
f .write ('libmodule' + str (i ) + '.libmodule' + str (i ) + '_entry()\n ' )
279
284
f .write ('libmodulefinal.break_here()\n ' )
@@ -332,7 +337,7 @@ def run_so_generator(num_files, avg_num_functions, call_depth, extern, seed, see
332
337
for p ,d ,f in os .walk ('./' ):
333
338
if p == './' :
334
339
for file in f :
335
- if (file .find ('libmodule' ) != - 1 or file .find ('libutility' ) != - 1 or file .find ('pynamic.h' ) != - 1 ) and file .find ('libmodulefinal.c' ) == - 1 :
340
+ if (file .find ('libmodule' ) != - 1 or file .find ('libutility' ) != - 1 or file .find ('pynamic.h' ) != - 1 ) and file .find ('libmodulefinal.c' ) == - 1 and file . find ( 'libmodulebegin.c' ) == - 1 :
336
341
os .remove (file )
337
342
338
343
if extern :
@@ -372,6 +377,7 @@ def run_so_generator(num_files, avg_num_functions, call_depth, extern, seed, see
372
377
for i in range (num_utility_files ):
373
378
command = 'ar cru libpynamic.a %s' % (file_prefix + str (i )+ '.o' )
374
379
run_command (command )
380
+ pynamic_header_file .write ('void initlibmodulebegin();\n ' )
375
381
for i in range (num_files - num_utility_files ):
376
382
pynamic_header_file .write ('void initlibmodule%d();\n ' % (i ))
377
383
pynamic_header_file .write ('void initlibmodulefinal();\n ' )
@@ -390,6 +396,10 @@ def run_so_generator(num_files, avg_num_functions, call_depth, extern, seed, see
390
396
command = 'ranlib libpynamic.a'
391
397
run_command (command )
392
398
399
+ compile_file ("libmodulebegin" , num_files - num_utility_files , 0 , include_dir , CC )
400
+ command = 'ar cru libpynamic.a libmodulebegin.o'
401
+ run_command (command )
402
+
393
403
f = open ("pyMPI_initialize.c" , "r" )
394
404
lines = f .readlines ()
395
405
f .close ()
@@ -399,6 +409,7 @@ def run_so_generator(num_files, avg_num_functions, call_depth, extern, seed, see
399
409
if line .find ('pyMPI_Macros.h' ) != - 1 :
400
410
f .write ('#include "pynamic.h"\n ' )
401
411
if line .find ('PyImport_AppendInittab' ) != - 1 :
412
+ f .write (' PyImport_AppendInittab("libmodulebegin", initlibmodulebegin);\n ' )
402
413
for i in range (num_files - num_utility_files ):
403
414
f .write (' PyImport_AppendInittab("libmodule%d", initlibmodule%d);\n ' % (i , i ))
404
415
f .write (' PyImport_AppendInittab("libmodulefinal", initlibmodulefinal);\n ' )
0 commit comments