22
33import communication_helpers as ch
44
5+ logfilename = 'pyparislog.txt'
6+ def print2logandstdo (message , mode = 'a+' ):
7+ print message
8+ with open (logfilename , mode ) as fid :
9+ fid .writelines ([message + '\n ' ])
10+
11+
512class RingOfCPUs (object ):
613 def __init__ (self , sim_content , N_pieces_per_transfer = 1 , force_serial = False , comm = None ):
714
@@ -12,19 +19,18 @@ def __init__(self, sim_content, N_pieces_per_transfer=1, force_serial = False, c
1219 if hasattr (sim_content , 'N_pieces_per_transfer' ):
1320 self .N_pieces_per_transfer = sim_content .N_pieces_per_transfer
1421
15- print 'N_pieces_per_transfer = ' , self .N_pieces_per_transfer
1622
1723 self .sim_content .ring_of_CPUs = self
1824
1925 # choice of the communicator
2026 if force_serial :
21- print ' \n Single CPU forced by user! \n '
27+ comm_info = 'Single CPU forced by user. '
2228 self .comm = SingleCoreComminicator ()
2329 elif comm is not None :
24- print ' \n Multiprocessing using communicator provided as argument.\n '
30+ comm_info = 'Multiprocessing using communicator provided as argument.'
2531 self .comm = comm
2632 else :
27- print ' \n Multiprocessing via MPI.'
33+ comm_info = 'Multiprocessing via MPI.'
2834 from mpi4py import MPI
2935 self .comm = MPI .COMM_WORLD
3036
@@ -48,7 +54,16 @@ def __init__(self, sim_content, N_pieces_per_transfer=1, force_serial = False, c
4854 self .buf_int = np .array (self .N_buffer_int_size * [0 ])
4955
5056 self .sim_content .init_all ()
51-
57+
58+ if self .I_am_the_master :
59+ print2logandstdo ('PyPARIS simulation' , mode = 'w+' )
60+ print2logandstdo (comm_info )
61+ print2logandstdo ('N_pieces_per_transfer = %d' % self .N_pieces_per_transfer )
62+ import socket
63+ import sys
64+ print2logandstdo ('Running on %s' % socket .gethostname ())
65+ print2logandstdo ('Interpreter at %s' % sys .executable )
66+
5267 self .comm .Barrier () # only for stdoutp
5368
5469 if self .I_am_the_master :
@@ -70,9 +85,6 @@ def __init__(self, sim_content, N_pieces_per_transfer=1, force_serial = False, c
7085
7186 def run (self ):
7287 if self .I_am_the_master :
73- with open ('pyparislog.txt' , 'a+' ) as fid :
74- import socket
75- fid .writelines (['Running on %s\n ' % socket .gethostname ()])
7688 import time
7789 t_last_turn = time .mktime (time .localtime ())
7890 while True : #(it will be stopped with a break)
@@ -115,9 +127,7 @@ def run(self):
115127 orders_from_master += orders_to_pass
116128
117129 t_now = time .mktime (time .localtime ())
118- print 'Turn %d, %d s' % (self .i_turn ,t_now - t_last_turn )
119- with open ('pyparislog.txt' , 'a+' ) as fid :
120- fid .writelines (['Turn %d, %d s\n ' % (self .i_turn ,t_now - t_last_turn )])
130+ print2logandstdo ('Turn %d, %d s' % (self .i_turn ,t_now - t_last_turn ) )
121131 t_last_turn = t_now
122132
123133 # prepare next turn
0 commit comments