def worker(task_queue, shared_data):
    for task in iter(task_queue.get, 'DIE'):
        #The problem appears to be that shared_data is a MP.RawArray
        #We need to pass the underlying c-pointer and not to copy!
        sine_module.sine_add_2(shared_data,task)
#!/usr/bin/python
# see README file
import sine_module

################################################
#This code works exactly as hoped
import numpy
tmp = numpy.zeros(10)
for index in range(10):
    sine_module.sine_add_2(index,tmp)
print "The correct answer is"
print tmp
################################################


#This is an attempt to use fortran functions within a parallel python
#script. To share data between processes we must use a
#multiprocessing.RawArray
import multiprocessing as MP

#The entry function for each process
def worker(task_queue, shared_data):
    for task in iter(task_queue.get, 'DIE'):
        #The problem appears to be that shared_data is a MP.RawArray
        #We need to pass the underlying c-pointer and not to copy!
        sine_module.sine_add_2(shared_data,task)

#Create the queue for communication and start-up the processes
task_queue = MP.Queue()
shared_data = MP.RawArray('d', [0.]*10);
process1 = MP.Process(target=worker, args=(task_queue, shared_data))
Esempio n. 3
0
def worker(task_queue, shared_data):
    for task in iter(task_queue.get, 'DIE'):
        tmp = sine_module.sine_add_2(shared_data,task)
        shared_data[task] = tmp[task]
def worker(task_queue, shared_data):
    arr = numpy.frombuffer(shared_data, dtype=numpy.double)
    for task in iter(task_queue.get, 'DIE'):
        print task
        sine_module.sine_add_2(task, arr)
Esempio n. 5
0
def worker(task_queue, shared_data):
    for task in iter(task_queue.get, "DIE"):
        sine_module.sine_add_2(shared_data, task)  # does not work