wraithx on Thu, 18 May 2023 23:29:49 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Help running parfor...


Hello,

I think I'm having trouble using parfor. I just downloaded and installed Pari64-2-15-3-pthread.exe. I'm trying to use parfor, but it seems like it is only using a single thread. I've created some test code to use 4 threads, and it seems to run the first iteration until completion, then it starts running the second iteration to completion, and so on until the last iteration until completion. I put in print statements hoping to see it randomly working on different iterations, depending on which thread executed the print statement. But it's printing each iteration in order with no sign of parallelism here.

I'm probably using the threading library/functions wrong. Can someone look at my example code below and let me know why this seems to be running single threaded on my system, and what I might need to do different to get it to run in parallel? Thanks for any help you can provide!

-David C.

get_fname(p, i) = {
  my(rstr,path = "c:/downloads");
  rstr = strprintf("%s/work%03d_%06d.txt", path, logint(p,10)+1, i);
  return(rstr);
}

parallel_g(fname, p, start, range) = {
  my(i,w=start*range);
  for(i=w,w+range-1,
    print("Working on start=",start," (",i-w+1,"/",range,") val=",i);
    write(fname,"val=",i,",n=",bitxor(p,i));
  );
}


g_parallel(num_threads, p, first_n, last_n, range) = {
  my(i,fname);
  default(nbthreads, num_threads);
  parfor(i = first_n, last_n,
    get_fname(p,i),
    fname,
    parallel_g(fname, p, i, range)
  );
}

export(get_fname, parallel_g);

g_parallel(4, 2^31-1, 1, 4, 1000)