Reformatted some code in 3 more files, used f-strings to make code better.

这个提交包含在:
Sai Suraj
2023-04-16 11:03:47 +05:30
父节点 1dd4f17850
当前提交 e41449a923
共有 3 个文件被更改,包括 54 次插入44 次删除

查看文件

@@ -55,8 +55,9 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = tuple(int(x) for x in singlecmds[cmd].split())
if len(tmp) != 1:
logger.exception(cmd + ' requires exactly one parameter to specify ' +
'the number of CPU OpenMP threads to use')
logger.exception(
f'{cmd} requires exactly one parameter to specify the number of CPU OpenMP threads to use'
)
raise ValueError
omp_threads = OMPThreads(n=tmp[0])
@@ -66,7 +67,7 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = [float(x) for x in singlecmds[cmd].split()]
if len(tmp) != 3:
logger.exception(cmd + ' requires exactly three parameters')
logger.exception(f'{cmd} requires exactly three parameters')
raise ValueError
dl = (tmp[0], tmp[1], tmp[2])
@@ -77,7 +78,7 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = [float(x) for x in singlecmds[cmd].split()]
if len(tmp) != 3:
logger.exception(cmd + ' requires exactly three parameters')
logger.exception(f'{cmd} requires exactly three parameters')
raise ValueError
p1 = (tmp[0], tmp[1], tmp[2])
@@ -94,8 +95,9 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split()
if len(tmp) != 1:
logger.exception(cmd + ' requires exactly one parameter to specify ' +
'the time window. Either in seconds or number of iterations.')
logger.exception(
f'{cmd} requires exactly one parameter to specify the time window. Either in seconds or number of iterations.'
)
raise ValueError
tmp = tmp[0].lower()
@@ -113,8 +115,8 @@ def process_singlecmds(singlecmds):
cmd = '#pml_cells'
if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split()
if len(tmp) != 1 and len(tmp) != 6:
logger.exception(cmd + ' requires either one or six parameter(s)')
if len(tmp) not in [1, 6]:
logger.exception(f'{cmd} requires either one or six parameter(s)')
raise ValueError
if len(tmp) == 1:
pml_cells = PMLProps(thickness=int(tmp[0]))
@@ -132,7 +134,7 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split()
if len(tmp) != 3:
logger.exception(cmd + ' requires exactly three parameters')
logger.exception(f'{cmd} requires exactly three parameters')
raise ValueError
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
@@ -143,7 +145,7 @@ def process_singlecmds(singlecmds):
if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split()
if len(tmp) != 3:
logger.exception(cmd + ' requires exactly three parameters')
logger.exception(f'{cmd} requires exactly three parameters')
raise ValueError
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
@@ -154,8 +156,8 @@ def process_singlecmds(singlecmds):
cmd = '#excitation_file'
if singlecmds[cmd] is not None:
tmp = singlecmds[cmd].split()
if len(tmp) != 1 and len(tmp) != 3:
logger.exception(cmd + ' requires either one or three parameter(s)')
if len(tmp) not in [1, 3]:
logger.exception(f'{cmd} requires either one or three parameter(s)')
raise ValueError
if len(tmp) > 1:

查看文件

@@ -220,26 +220,26 @@ class MPIExecutor(object):
def join(self):
"""Joins the workers."""
if self.is_master():
if not self.is_master():
return
logger.debug(f'({self.comm.name}) - Terminating. Sending sentinel to all workers.')
# Send sentinel to all workers
for worker in self.workers:
self.comm.send(None, dest=worker, tag=Tags.EXIT)
logger.debug(f'({self.comm.name}) - Terminating. Sending sentinel to all workers.')
# Send sentinel to all workers
for worker in self.workers:
self.comm.send(None, dest=worker, tag=Tags.EXIT)
logger.debug(f'({self.comm.name}) - Waiting for all workers to terminate.')
logger.debug(f'({self.comm.name}) - Waiting for all workers to terminate.')
down = [False] * len(self.workers)
while True:
for i, worker in enumerate(self.workers):
if self.comm.Iprobe(source=worker, tag=Tags.EXIT):
self.comm.recv(source=worker, tag=Tags.EXIT)
down[i] = True
if all(down):
break
down = [False] * len(self.workers)
while True:
for i, worker in enumerate(self.workers):
if self.comm.Iprobe(source=worker, tag=Tags.EXIT):
self.comm.recv(source=worker, tag=Tags.EXIT)
down[i] = True
if all(down):
break
self._up = False
logger.debug(f'({self.comm.name}) - All workers terminated.')
self._up = False
logger.debug(f'({self.comm.name}) - All workers terminated.')
def submit(self, jobs, sleep=0.0):
"""Submits a list of jobs to the workers and returns the results.

查看文件

@@ -378,7 +378,7 @@ class CUDAUpdates:
for pml in self.grid.pmls['slabs']:
pml.htod_field_arrays()
pml.set_blocks_per_grid()
knl_name = 'order' + str(len(pml.CFS)) + '_' + pml.direction
knl_name = f'order{len(pml.CFS)}_{pml.direction}'
self.subs_name_args['FUNC'] = knl_name
knl_electric = getattr(knl_pml_updates_electric, knl_name)
@@ -880,23 +880,31 @@ class OpenCLUpdates:
for pml in self.grid.pmls['slabs']:
pml.set_queue(self.queue)
pml.htod_field_arrays()
knl_name = 'order' + str(len(pml.CFS)) + '_' + pml.direction
knl_name = f'order{len(pml.CFS)}_{pml.direction}'
knl_electric_name = getattr(knl_pml_updates_electric, knl_name)
knl_magnetic_name = getattr(knl_pml_updates_magnetic, knl_name)
pml.update_electric_dev = self.elwise(self.ctx,
knl_electric_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}),
knl_electric_name['func'].substitute(subs),
'pml_updates_electric_' + knl_name,
preamble=self.knl_common,
options=config.sim_config.devices['compiler_opts'])
pml.update_magnetic_dev = self.elwise(self.ctx,
knl_magnetic_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}),
knl_magnetic_name['func'].substitute(subs),
'pml_updates_magnetic_' + knl_name,
preamble=self.knl_common,
options=config.sim_config.devices['compiler_opts'])
pml.update_electric_dev = self.elwise(
self.ctx,
knl_electric_name['args_opencl'].substitute(
{'REAL': config.sim_config.dtypes['C_float_or_double']}
),
knl_electric_name['func'].substitute(subs),
f'pml_updates_electric_{knl_name}',
preamble=self.knl_common,
options=config.sim_config.devices['compiler_opts'],
)
pml.update_magnetic_dev = self.elwise(
self.ctx,
knl_magnetic_name['args_opencl'].substitute(
{'REAL': config.sim_config.dtypes['C_float_or_double']}
),
knl_magnetic_name['func'].substitute(subs),
f'pml_updates_magnetic_{knl_name}',
preamble=self.knl_common,
options=config.sim_config.devices['compiler_opts'],
)
def _set_rx_knl(self):
"""Receivers - initialises arrays on compute device, prepares kernel and