Bill Allombert on Thu, 11 Jun 2020 23:08:06 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: How to use OpenMP with PARI/GP? |
On Thu, Jun 11, 2020 at 10:44:44PM +0200, Erkan Tairi wrote: > Hi Bill, > > Sorry about that, I updated my question on stackoverflow with the new > code: > https://stackoverflow.com/questions/62322277/how-to-use-openmp-with-pari-gp Thanks! You can fix it by removing the lines for (size_t i = 0; i < numthread; i++) { if (&pth[i] != NULL) pari_thread_free(&pth[i]); } I explain: each threads use its own PARI stack to store results. Calling pari_thread_free destroys the PARI stack thread and any result computed by that thread. So whatever result you want to preserve need to be moved to the main stack using gcopy before calling pari_thread_free. In fact this is why the API has pari_thread_alloc: to allow the thread stacks to survive pari_thread_close so that the main thread get the results. Cheers, Bill.