mersenneforum.org  

Go Back   mersenneforum.org > Factoring Projects > GMP-ECM

Reply
 
Thread Tools
Old 2009-02-27, 23:34   #1
frmky
 
frmky's Avatar
 
Jul 2003
So Cal

1000001000102 Posts
Default Is libecm thread-safe?

I'm trying to extend Paul Zimmermann's aliq2.c from http://www.loria.fr/~zimmerma/records/aliquot.html to run the ECM on multiple threads. I've done this:

Code:
#pragma omp parallel for 
          for (i=0;i<nt;i++) { 
            //printf("Thread: %d\n",i);
            ress[i] = ecm_factor(ps[i], ns[i], B1, NULL); 
          }
where nt is the number of threads running, and ps and ns are arrays of mpz's. If I compile this with openmp and choose only 1 thread at runtime, all works correctly. Selecting more than one thread, however, leads to a lockup, segfault, or trying to free() something already free()'ed. Is ecm_factor() not thread-safe? If not, would it be difficult to make it so?

Thanks,
Greg
frmky is online now   Reply With Quote
Old 2009-02-28, 03:20   #2
jasonp
Tribal Bullet
 
jasonp's Avatar
 
Oct 2004

24·13·17 Posts
Default

Are you sure OpenMP spawn multiple threads, so that each function call gets its own stack? Maybe you also need an array of ecm_params entries, initialized before running the loop in parallel?
jasonp is offline   Reply With Quote
Old 2009-02-28, 03:24   #3
frmky
 
frmky's Avatar
 
Jul 2003
So Cal

2·3·347 Posts
Default

Quote:
Originally Posted by jasonp View Post
Are you sure OpenMP spawn multiple threads, so that each function call gets its own stack?
It uses pthreads to spawn the threads.

Quote:
Originally Posted by jasonp View Post
Maybe you also need an array of ecm_params entries, initialized before running the loop in parallel?
I'll figure out how to do that in a few days. I also sometime plan to see if I can figure out how to use libmsieve as well.

Greg
frmky is online now   Reply With Quote
Old 2009-02-28, 07:10   #4
fivemack
(loop (#_fork))
 
fivemack's Avatar
 
Feb 2006
Cambridge, England

13×491 Posts
Default

Quote:
Originally Posted by frmky View Post
Is ecm_factor() not thread-safe? If not, would it be difficult to make it so?
It is not thread-safe - there is a single global prime-generating object which is not protected by locks (so your multiple-frees come when thread 1 has deleted the sieving array while thread 2 is trying to read from it), and if you add locks you get the obvious problem that thread 1 picks up some primes and thread 2 others when computing the first product of primes. I'm not sure how fiddly it is to fix, but fiddlier than I'd first thought.
fivemack is offline   Reply With Quote
Old 2009-02-28, 14:57   #5
jasonp
Tribal Bullet
 
jasonp's Avatar
 
Oct 2004

24·13·17 Posts
Default

Quote:
Originally Posted by frmky View Post
I'll figure out how to do that in a few days. I also sometime plan to see if I can figure out how to use libmsieve as well.
libmsieve should be completely thread safe, if you write to different log files and data files with each instance. The library has no writeable globals.
jasonp is offline   Reply With Quote
Old 2009-02-28, 16:08   #6
akruppa
 
akruppa's Avatar
 
"Nancy"
Aug 2002
Alexandria

2,467 Posts
Default

Most of GMP-ECM has been written without thread-safeness (or indeed a library) in mind, so I'm not surprised it isn't... the prime sieve's state in static variables is obviously a problem, but I think there are some other static variables, too. (Never mind the brilliant idea of putting temp space in the mpmod struct, or mixing mpz/mpmod for temp data... half of the code should be rewritten from scratch. )

Alex
akruppa is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
SAFE MODE.... petrw1 Hardware 14 2009-03-25 13:17
using libecm from python yqiang GMP-ECM 2 2007-04-22 00:14
Can't bind libecm.a with C++ files poire GMP-ECM 2 2006-03-21 14:41
Safe Mode Unregistered Software 12 2004-07-16 01:06
Safe Mode JuanTutors Hardware 6 2004-06-24 10:15

All times are UTC. The time now is 04:29.

Wed Apr 14 04:29:12 UTC 2021 up 5 days, 23:10, 0 users, load averages: 1.98, 2.37, 2.42

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.