@@ -165,6 +165,8 @@ def __init__(self, samples: list[TarSampleList], base_path: PathLike = "./", n_p
165
165
self .samples = samples
166
166
self .base_path = Path (base_path )
167
167
self .n_proc = n_proc
168
+ self .pot = None
169
+ self .rho = None
168
170
169
171
def __len__ (self ) -> int :
170
172
"""Total number of samples (including rotations)"""
@@ -292,24 +294,40 @@ def _load_samples(self, sample_lists: list[TarSampleList], i_proc: int, event: m
292
294
293
295
def _get_queue_sample (self ):
294
296
297
+ if self ._timings :
298
+ t0 = time .perf_counter ()
299
+
295
300
i_proc , sample_id_pot , sample_id_rho , pot_shape , rho_shape , lvec_pot , lvec_rho , xyzs , Zs , rots = self .q .get (timeout = 200 )
296
301
302
+ if self ._timings :
303
+ t1 = time .perf_counter ()
304
+
297
305
shm_pot = mp .shared_memory .SharedMemory (sample_id_pot )
298
306
pot = np .ndarray (pot_shape , dtype = np .float32 , buffer = shm_pot .buf )
299
- pot = HartreePotential (pot , lvec_pot )
300
- # This starts a copy to the OpenCL device. Better to start it here so that buffer preparation is instant during the simulation.
301
- pot .cl_array
307
+ if self .pot is None :
308
+ self .pot = HartreePotential (pot , lvec_pot )
309
+ else :
310
+ self .pot .update_array (pot , lvec_pot )
311
+
312
+ if self ._timings :
313
+ t2 = time .perf_counter ()
302
314
303
315
if sample_id_rho is not None :
304
316
shm_rho = mp .shared_memory .SharedMemory (sample_id_rho )
305
317
rho = np .ndarray (rho_shape , dtype = np .float32 , buffer = shm_rho .buf )
306
- rho = ElectronDensity (rho , lvec_rho )
307
- rho .cl_array
318
+ if self .rho is None :
319
+ self .rho = ElectronDensity (rho , lvec_rho )
320
+ else :
321
+ self .rho .update_array (pot , lvec_pot )
308
322
else :
309
323
shm_rho = None
310
324
rho = None
311
325
312
- return i_proc , xyzs , Zs , rots , pot , shm_pot , rho , shm_rho , sample_id_pot
326
+ if self ._timings :
327
+ t3 = time .perf_counter ()
328
+ print (f"[Main, receive data, id { sample_id_pot } ] Queue / Pot / Rho: " f"{ t1 - t0 :.5f} / { t2 - t1 :.5f} / { t3 - t2 :.5f} " )
329
+
330
+ return i_proc , xyzs , Zs , rots , self .pot , shm_pot , self .rho , shm_rho , sample_id_pot
313
331
314
332
def _yield_samples (self ):
315
333
0 commit comments