Original date:2019-01-14 02:46:33 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 
    results[id] = res 
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 

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

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?


Not Categorized, Please Help


Quick Links

User menu

Not signed in.

Misc Menu