PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

Is malloc threadsafe?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
Emma



Joined: 30 Sep 2008
Posts: 16

PostPosted: Thu Sep 03, 2009 8:43 am    Post subject: Is malloc threadsafe? Reply with quote

I'm attempting to covert some already working code to use multiple threads. I'm using the #pragma for statement to do this. Sometime after the new threads are forked malloc is getting called. I'm beginning to suspect that perhaps it is not thread safe?
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6639
Location: The Portland Group Inc.

PostPosted: Thu Sep 03, 2009 10:25 am    Post subject: Reply with quote

Hi Emma,

Malloc is thread safe. What I suspect is going on is that you haven't privatized these variables and that each thread is trying to malloc the same variable. Try using malloc outside of the parallel region or privatizing these variables.

Hope this helps,
Mat
Back to top
View user's profile
Emma



Joined: 30 Sep 2008
Posts: 16

PostPosted: Thu Sep 03, 2009 10:51 am    Post subject: Reply with quote

What if the variables in question are declared and malloced in a function called by the parallel region? I would have thought that would make them private.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6639
Location: The Portland Group Inc.

PostPosted: Thu Sep 03, 2009 12:14 pm    Post subject: Reply with quote

Hi Emma,

If they are local variables, then yes each thread would have their own private copy.

Have to tried using the PGI debugger, PGDBG, to determine the cause of the seg fault?

- Mat
Back to top
View user's profile
Emma



Joined: 30 Sep 2008
Posts: 16

PostPosted: Thu Sep 03, 2009 12:26 pm    Post subject: Reply with quote

Yeah, it seems to stop at the top of a for loop inside the called function. I can't see anything wrong with any of the variables in the call. I'm not sure I've quite got the hang of debugging with multiple threads so maybe I'm not seeing the whole picture. Are there any tutorials on how to pin point issues inside threads?
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group