Why Pmap() skipping a combination in the function arguments

Hi! I am new to Julia and wondering about a simple implementation of the julia pmap function. Here is the sample code

using Distributed; addprocs(6)  #adding workers

io = open("myfile.txt", "w"); write(io, "This is a test!\n"); close(io);

@everywhere function writing_test(a,b)
    io = open("myfile.txt", "a");
    r=string(a,"\t",b,"\n")
    write(io,r);
    close(io);
end

pmap(writing_test,20:30,220:230) #Calling the Function through pmap
for i in workers(); rmprocs(i); end #Removing Workers

And here is the output of myfile.txt

This is a test!
22	222
24	224
26	226
27	227
28	228
29	229
30	230
20	220

I am wondering why 21 221 combination is missing. Is it random that one of the combination is missing from such implementation?

Possibly a race condition where multiple processes try to write to the same file at the same time. I would try to lock the file around the write operation. See https://docs.julialang.org/en/v1/base/multi-threading/#Base.Threads.SpinLock

1 Like