本文整理汇总了Python中multiprocessing.RawValue方法的典型用法代码示例。如果您正苦于以下问题:Python multiprocessing.RawValue方法的具体用法?Python multiprocessing.RawValue怎么用?Python multiprocessing.RawValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类multiprocessing
的用法示例。
在下文中一共展示了multiprocessing.RawValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, *, slot_bytes, slot_count):
"""Initializer.
Args:
slot_bytes: The maximum size of slots in the buffer.
slot_count: How many slots should be in the buffer.
"""
self.slot_count = slot_count
self.array = SlotArray(slot_bytes=slot_bytes, slot_count=slot_count)
self.lock = ReadersWriterLock()
# Each reading process may modify its own Pointer while the read
# lock is being held. Each reading process can also load the position
# of the writer, but not load any other readers. Each reading process
# can also load the value of the 'active' count.
self.readers = []
# The writer can load and store the Pointer of all the reader Pointers
# or the writer Pointer while the write lock is held. It can also load
# and store the value of the 'active' acount.
self.writer = Pointer(self.slot_count)
self.active = multiprocessing.RawValue(ctypes.c_uint, 0)
示例2: test_value
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def test_value(self, raw=False):
if raw:
values = [self.RawValue(code, value)
for code, value, _ in self.codes_values]
else:
values = [self.Value(code, value)
for code, value, _ in self.codes_values]
for sv, cv in zip(values, self.codes_values):
self.assertEqual(sv.value, cv[1])
proc = self.Process(target=self._test, args=(values,))
proc.daemon = True
proc.start()
proc.join()
for sv, cv in zip(values, self.codes_values):
self.assertEqual(sv.value, cv[2])
示例3: test_getobj_getlock
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def test_getobj_getlock(self):
val1 = self.Value('i', 5)
lock1 = val1.get_lock()
obj1 = val1.get_obj()
val2 = self.Value('i', 5, lock=None)
lock2 = val2.get_lock()
obj2 = val2.get_obj()
lock = self.Lock()
val3 = self.Value('i', 5, lock=lock)
lock3 = val3.get_lock()
obj3 = val3.get_obj()
self.assertEqual(lock, lock3)
arr4 = self.Value('i', 5, lock=False)
self.assertFalse(hasattr(arr4, 'get_lock'))
self.assertFalse(hasattr(arr4, 'get_obj'))
self.assertRaises(AttributeError, self.Value, 'i', 5, lock='navalue')
arr5 = self.RawValue('i', 5)
self.assertFalse(hasattr(arr5, 'get_lock'))
self.assertFalse(hasattr(arr5, 'get_obj'))
示例4: build_ctrl
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def build_ctrl(self, world_size):
"""
Builds several parallel communication mechanisms for controlling the
workflow across processes.
"""
opt_throttle = (mp.Barrier(world_size) if world_size > 1 else
None)
return AttrDict(
quit=mp.Value('b', lock=True),
quit_opt=mp.RawValue('b'),
sample_ready=[mp.Semaphore(0) for _ in range(2)], # Double buffer.
sample_copied=[mp.Semaphore(1) for _ in range(2)],
sampler_itr=mp.Value('l', lock=True),
opt_throttle=opt_throttle,
eval_time=mp.Value('d', lock=True),
)
示例5: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, ModelCls=None, model_kwargs=None, initial_model_state_dict=None):
"""
Arguments are saved but no model initialization occurs.
Args:
ModelCls: The model class to be used.
model_kwargs (optional): Any keyword arguments to pass when instantiating the model.
initial_model_state_dict (optional): Initial model parameter values.
"""
save__init__args(locals())
self.model = None # type: torch.nn.Module
self.shared_model = None
self.distribution = None
self.device = torch.device("cpu")
self._mode = None
if self.model_kwargs is None:
self.model_kwargs = dict()
# The rest only for async operations:
self._rw_lock = RWLock()
self._send_count = mp.RawValue("l", 0)
self._recv_count = 0
示例6: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, ndata, nprocs, chunk=None, schedule='guided'):
if not schedule in ['guided', 'dynamic', 'static']:
raise ValueError('unknown scheduling strategy')
self._ndata = mp.RawValue(ctypes.c_int, ndata)
self._start = mp.RawValue(ctypes.c_int, 0)
self._lock = mp.Lock()
self._schedule = schedule
self._nprocs = nprocs
if schedule == 'guided' or schedule == 'dynamic':
min_chunk = ndata // (10 * nprocs)
if chunk:
min_chunk = chunk
min_chunk = max(min_chunk, 1)
self._chunk = min_chunk
elif schedule == 'static':
min_chunk = ndata // nprocs
if chunk:
min_chunk = max(chunk, min_chunk)
min_chunk = max(min_chunk, 1)
self._chunk = min_chunk
示例7: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, params, opt_type=None, lr=0, step=0):
self.var_shapes = [
var.get_shape().as_list()
for var in params]
self.size = sum([np.prod(shape) for shape in self.var_shapes])
self.step = RawValue(ctypes.c_int, step)
if opt_type == 'adam':
self.ms = self.malloc_contiguous(self.size)
self.vs = self.malloc_contiguous(self.size)
self.lr = RawValue(ctypes.c_float, lr)
elif opt_type == 'adamax':
self.ms = self.malloc_contiguous(self.size)
self.vs = self.malloc_contiguous(self.size)
self.lr = RawValue(ctypes.c_float, lr)
elif opt_type == 'rmsprop':
self.vars = self.malloc_contiguous(self.size, np.ones(self.size, dtype=np.float))
elif opt_type == 'momentum':
self.vars = self.malloc_contiguous(self.size)
else:
self.vars = self.malloc_contiguous(self.size)
示例8: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, delta_list_queue, comp_delta_queue,
overlay_mode,
block_size=1024*1024*2):
"""
comparisons of compression algorithm
http://pokecraft.first-world.info/wiki/Quick_Benchmark:_Gzip_vs_Bzip2_vs_LZMA_vs_XZ_vs_LZ4_vs_LZO
"""
self.delta_list_queue = delta_list_queue
self.comp_delta_queue = comp_delta_queue
self.overlay_mode = overlay_mode
self.num_proc = VMOverlayCreationMode.MAX_THREAD_NUM
self.comp_type = overlay_mode.COMPRESSION_ALGORITHM_TYPE
self.comp_level = overlay_mode.COMPRESSION_ALGORITHM_SPEED
self.block_size = block_size
self.proc_list = list()
# monitor value specific to compression
self.monitor_time_first_input_recved = multiprocessing.RawValue(
ctypes.c_double, 0)
super(CompressProc, self).__init__(target=self.compress_stream)
示例9: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, remote_addr, remote_port, metadata, compdata_queue, process_controller):
self.remote_addr = remote_addr
self.remote_port = remote_port
self.metadata = metadata
self.compdata_queue = compdata_queue
self.process_controller = process_controller
# measurement
self.monitor_network_bw = multiprocessing.RawValue(ctypes.c_double, 0)
self.monitor_network_bw.value = 0.0
self.vm_resume_time_at_dest = multiprocessing.RawValue(ctypes.c_double, 0)
self.time_finish_transmission = multiprocessing.RawValue(ctypes.c_double, 0)
self.is_first_recv = False
self.time_first_recv = 0
super(StreamSynthesisClient, self).__init__(target=self.transfer)
示例10: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, modified_mem_queue, deltalist_queue,
basemem_meta, basemem_path, overlay_mode,
apply_free_memory=True,
free_memory_info=None):
self.modified_mem_queue = modified_mem_queue
self.deltalist_queue = deltalist_queue
self.basemem_meta = basemem_meta
self.memory_hashlist = Memory.import_hashlist(basemem_meta)
self.apply_free_memory = apply_free_memory
self.free_memory_info = free_memory_info
self.basemem_path = basemem_path
self.proc_list = list()
self.overlay_mode = overlay_mode
self.num_proc = VMOverlayCreationMode.MAX_THREAD_NUM
self.diff_algorithm = overlay_mode.MEMORY_DIFF_ALGORITHM
self.monitor_current_iteration = multiprocessing.RawValue(
ctypes.c_ulong, 0)
super(CreateMemoryDeltalist, self).__init__(
target=self.create_memory_deltalist)
示例11: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, command_queue, task_queue, mode_queue, deltalist_queue,
diff_algorithm, basedisk_path, modified_disk, chunk_size):
self.command_queue = command_queue
self.task_queue = task_queue
self.mode_queue = mode_queue
self.deltalist_queue = deltalist_queue
self.diff_algorithm = diff_algorithm
self.basedisk_path = basedisk_path
self.modified_disk = modified_disk
self.chunk_size = chunk_size
# shared variables between processes
self.child_process_time_total = multiprocessing.RawValue(
ctypes.c_double, 0)
self.child_process_block_total = multiprocessing.RawValue(
ctypes.c_double, 0)
self.child_input_size_total = multiprocessing.RawValue(
ctypes.c_ulong, 0)
self.child_output_size_total = multiprocessing.RawValue(
ctypes.c_ulong, 0)
super(DiskDiffProc, self).__init__(target=self.process_diff)
示例12: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, initval=0):
self.val = RawValue('i', initval)
self.last_step_update_target = RawValue('i', initval)
self.lock = Lock()
示例13: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, value=0):
self.initial_value = value
self.val = RawValue('i', value)
self.lock = Lock()
示例14: reset
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def reset(self):
with self.lock:
self.val = RawValue('i', self.initial_value)
示例15: __init__
# 需要导入模块: import multiprocessing [as 别名]
# 或者: from multiprocessing import RawValue [as 别名]
def __init__(self, context_size):
# use raw values because both indices have
# to manually be locked together
self._doc_id = multiprocessing.RawValue('i', 0)
self._in_doc_pos = multiprocessing.RawValue('i', context_size)
self._lock = multiprocessing.Lock()