- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have an error by executing a combination Fortran/C program with OpenMP pragma.
C source code:
Fortran source code:
The source code was compiled with the flags "-g -O2 -mcpu=itanium2-p9000 -mtune=itanium2-p9000 -openmp" and the compiler "INTEL C/C++ Compiler Version 10.1 Build 015" and "INTEL Fortran Compiler Version 10.1 Build 015".
Running the program end in a segfault.
I ruled out all usual suspects.
Any help would be appreciated.
Thanks in advance,
Jens
C source code:
#include
#include
extern void fentry_( int * );
int main(){
int level=4, num;
num = omp_get_max_threads();
printf("omp threads = %d ",num);
fflush(stderr);
fflush(stdout);
fentry_( &level );
return 0;
}
Fortran source code:
module fe
use omp_lib
implicit none
type matrixStruct
real(kind=8), dimension(:,:), allocatable :: matrix
end type matrixStruct
contains
subroutine f1(level)
integer(kind=4) :: level, i, j, m
type(matrixStruct), dimension(:), allocatable :: struct
allocate( struct(1:level) )
do i=1, level
m = ((2**i)+1)**2
allocate( struct(i)%matrix(1:m,1:m) )
write(*,*) "matrix ", i, " befor, size=", size(struct(i)%matrix(:,1)), size(struct(i)%matrix(1,:))
do j=1, m
write(*,*) struct(i)%matrix(:,j)
end do
!$omp parallel do shared(m, struct) private(i, j)
do j=1, m
struct(i)%matrix(:,j) = 0
end do
end do
do i=1, level
m = ((2**i)+1)**2
write(*,*) "matrix ", i, " after, size=", size(struct(i)%matrix(:,1)), size(struct(i)%matrix(1,:))
do j=1, m
write(*,*) struct(i)%matrix(:,j)
end do
end do
do i=1, level
deallocate( struct(i)%matrix )
end do
deallocate( struct )
end subroutine f1
end module fe
subroutine fentry(level)
use fe
integer(kind=4) :: level
call f1(level)
end subroutine fentry
The source code was compiled with the flags "-g -O2 -mcpu=itanium2-p9000 -mtune=itanium2-p9000 -openmp" and the compiler "INTEL C/C++ Compiler Version 10.1 Build 015" and "INTEL Fortran Compiler Version 10.1 Build 015".
Running the program end in a segfault.
I ruled out all usual suspects.
Any help would be appreciated.
Thanks in advance,
Jens
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I can't get a properly formatted copy of your source code to try it.
As I would take your comment about having tried all evident solutions to include such measures as setting thread stack size by kmp_stacksize (environment variable or function call), it seems you have excluded anyone from commenting.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have added an attachment with the source code, copy the 2 parts in the .txt file to a .c file and a .f90 file.
Yes, I have tried to set KMP_STACKSIZE and also to compile with "-heap-arrays 0", but no changes.
The program ends after printing the first matrix in the first loop.
Yes, I have tried to set KMP_STACKSIZE and also to compile with "-heap-arrays 0", but no changes.
The program ends after printing the first matrix in the first loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jens,
OpenMP in FORTRAN require an !$OMP END xxx at the end of parallel regions. In this case you are missing
!$omp end parallel do
after the statement that ends the do loop that was parallized
!$omp parallel do shared(m, struct) private(i, j)
do j=1, m
struct(i)%matrix(:,j) = 0
end do
!$omp end parallel do
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think, I have the solution.
The privat(i) is wrong, firstprivate(i) seems to be correct, else i has not the value like befor the omp pragma.
The privat(i) is wrong, firstprivate(i) seems to be correct, else i has not the value like befor the omp pragma.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sonicato,
In looking at your parallelloop you want shared(i)
The parallel loop is inside the do loop iterating on i. i must be passed into the parallel region (and not modified in there).
Jim Dempsey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page