Historical forum-msg-id-133418-edit, Revision 2

Original date:2019-01-14 02:21:10 Edited by: petelomax Subject: Re: Some initial clarifications

lib9 said...
petelomax said...

OE does not do parallelism. I have done multi-threading in both C++ and phix, and found the latter significantly easier, but then again I am slightly biased.

So does multi-threading use only one core?

Multiple cores. Note however that each thread deserves its own private copy of any data it is working on. (I would recommend using serialize() and deserialize() to set things up.) Here's a simple multi-core-basher:

constant nThreads = 10 
sequence results = repeat(0,nThreads) 
constant res_cs = init_cs()             -- critical section 
 
procedure mythreads(integer id) 
--  enter_cs(res_cs) 
    atom res = 0 
    for i=1 to 40000000 do 
        res += i 
    end for 
    enter_cs(res_cs) 
    results[id] = res 
    leave_cs(res_cs) 
    exit_thread(0) 
end procedure 
 
atom t0 = time() 
sequence threads = {} 
for i=1 to nThreads do 
    atom thread = create_thread(routine_id("mythreads"),{i}) 
    threads = append(threads,thread) 
end for 
 
wait_thread(threads) 
?results 
?elapsed(time()-t0) 

On my i3-2120, which I believe has 2 real cores/4 virtual, it takes 17s and TaskManager shows 100% CPU utilisation. If I move the enter_cs() call up inside mythreads() so that only one can run at a time, the execution time jumps to 53s and TaskManager never goes above 33% CPU utilisation.

As said often, however, if phix on linux does not work for you, the above is useless.

lib9 said...

Are sequences implemented as C arrays, not as linked lists?

arrays

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu