1. Matlab parfor equivalent

I have some EU code that I would like to run in parallel on mutliple cores. I've been spoiled by things like Matlab where I can use the 'parfor' command to have a for loop run in parallel. While investigating how this might work in Euphoria, I came across this post: http://openeuphoria.org/forum/113531.wc#113531 .

Out of curiosity, I wanted to see if I could come up with a very basic fix for my situation. I wrapped some of the basic pthreads commands and have something like this for EU code:

-- Allocate data to be passed to function in thread 
atom msg1 = allocate(16), msg2 = allocate(16) 
-- Pass in which chunk of the for loop to execute along with SieveBenchmark inputs 
poke4(msg1,{1,2,8192,50_000}) 
poke4(msg2,{3,4,8192,50_000}) 
 
-- Pthread code 
pthreadCreate(0,call_back(routine_id("parallelCode")),msg1) 
pthreadCreate(1,call_back(routine_id("parallelCode")),msg2) 
pthreadJoin(0)  
pthreadJoin(1) 
 
function parallelCode(atom msg) 	 
		-- Get parameter data passed in from pthread_create 
		integer start,finish,size,iterations 
		{start, finish, size, iterations} = peek4u({msg,4})  
		 
		-- For loop I wish to turn into a parfor equivalent 
		for i = start to finish do 
			SieveBenchmark({size,iterations}) 
		end for 
return 0 
end function 

As an example, I'm running the SieveBenchmark multiple times in parallel. This does the trick nicely when translated to C; I get full usage of two cores. It fails miserably when iterpreted though with machine-level exceptions. Is something along these lines easily possible with interpreted euphoria?

Thanks,
Ira

new topic     » topic index » view message » categorize

2. Re: Matlab parfor equivalent

Jerome said...

As an example, I'm running the SieveBenchmark multiple times in parallel. This does the trick nicely when translated to C; I get full usage of two cores. It fails miserably when iterpreted though with machine-level exceptions. Is something along these lines easily possible with interpreted euphoria?

The translation process puts a lot of your data into normal C routines, where your variables end up in a stack associated with your thread. In the interpreter, this is all managed by the interpreter itself, which is far from thread safe.

Additionally, there are some operations that will not be safe even with translated code. Obviously, any access of file level data will be unsafe. But there are some runtime functions (e.g., sequence slicing) that are not re-entrant and will probably cause weird errors.

Matt

new topic     » goto parent     » topic index » view message » categorize

3. Re: Matlab parfor equivalent

Matt,

Thanks for the clarifications! I'll stick to translated code if I need things to run in parallel.

- Ira

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu