Re: Some initial clarifications

new topic     » goto parent     » topic index » view thread      » older message » newer message
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. EDIT: on 64-bit, where the results fit in an integer, which makes it tons faster, the timings are 2.3s vs 4.6s, and trivial cases like this are precisely where I would expect C to seriously outshine OE/phix - it wouldn't surprise me in the least if some C compiler manages to replace the entire loop with a single simple algebraic expression such as 40000000*20000001.

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu