Two @spawnat runs in the same thread

The example below is from Julia 1.3 manual (with some prints added)

@everywhere function count_heads(n)
    c::Int = 0
    for i = 1:n
        c += rand(Bool)

a = @spawnat :any begin
    @async Core.println("proc id=$(myid()), thread id=$(threadid())")

b = @spawnat :any begin
    @async Core.println("proc id=$(myid()), thread id=$(threadid())")


The resulting output is this:

From worker 3:    proc id=3, thread id=1
From worker 2:    proc id=2, thread id=1

Which, I think, shows that a and b are calculated in a different process space and also shows that they are calculated by the same thread (id==1) so by the same physical core. This seems not true parallel computing. Or where is my understanding wrong?

How many threads are available? What does Threads.nthreads() say?

I have nthreads() == 4, nprocs() == 5

as I understand it;

Neither myid() nor threadid() has anything to do with the physcial or logical codes.

myid() is largely arbitary and is defined by the cluster manager, as a way to uniquely identify processes. Its not e.g. equal to the PID.

threadid() is just a consective identifier for all threads in the process.
So every process with have a threadid()=1 and if it has more threads then also threadid()=2 etc.

It doesn’t correspond to which physical core the thread runs on.
The OS can schedule any thread on any core and changes which thread is on which core when ever it feels like it.

Previous julia versions would even let you have more threads than physical cores,
so my 8 core desktop had a thread with threadid()=24 (because I had reason to believe oversubscribing would be good)

@oxinabox, thank you very much for clearing my doubt. :slight_smile: