An empty do loop giving seg fault with OpenMP while mexing with fortran

5 views (last 30 days)
Hello,
I have a code which uses a 'parallel do' construct. When I run the code in serial, it works w/o any problem. But when I parallelize it, it gives seg fault. I tried omitting some parts of the code out for testing purposes. At the end, I endded up with the below which still gave the seg fault error.
!$OMP PARALLEL DO DEFAULT(SHARED) PRIVATE(i,adjDist,j,k)
do i = 1,nNods
adjDist = zero
do j = 1,nDim
do k = 1,nAdj
if (nodAdj(i,k).eq.0) cycle
adjDist(k,j) = XYZ(nodAdj(i,k),j) - XYZ(nods(i),j)
enddo
enddo
enddo
!OMP END PARALLEL DO
Here 'adjDist' is a (nAdj x nDim) array and all the other variables are properly defined shared variables. Do you have any idea about what causes this to give seg fault? Before I was using the following statement;
adjDist(:,j) = XYZ(nodAdj(i,:),j) - XYZ(nods(i),j)
not to have the third do-loop with index 'k', but then I even changed it not to allocate/deallocate any memory, although I am not sure if Fortran allocates any extra memory in such a case. But in any case, apparently that is not the reason.
Thanks!
Ugur

Answers (1)

James Tursa
James Tursa on 25 Aug 2016
Why is adjDist private? This means each thread will work with its own individual copy of adjDist. Is this what you are really trying to do for this test case? How large is adjDist?
Some combinations of Fortran/OpenMP/MATLAB are not compatible. What versions are you running? Can you code up a very simple test case with one simple parallel loop and see if that runs OK?
  18 Comments
James Tursa
James Tursa on 4 Oct 2016
Off hand, the first thing I would look at is the argument list for each of those calls. Check to see that you are passing in the same stuff (same number of inputs, same sizes, same classes, etc). It could be that there is a difference that the mex routine doesn't check for.
Ugur
Ugur on 4 Oct 2016
Well, I think I checked this, and indeed, what I did is to split the m-file from the line it calls the mex function, and write the rest into the main program. So the arguments remain the same but it crashes in the former while it works in the latter case.

Sign in to comment.

Categories

Find more on Fortran with MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!