Problem with loop containing OpenMP section

I have the following simple program:

    program prog
	include "omp_lib.h"
	integer, parameter:: Na=8
	integer n,i,thrNum,NaThr,k
	real(8):: A(Na),A1(Na),st_tm,end_tm,OMPtime,CPUtime
	A=0.D0; A1=0.D0;
	n=0
	thrNum=4
	do k=1,2000000
	NaThr=Na/thrNum
!$omp parallel num_threads(thrNum) shared(A) private(n,i,j)
	n=omp_get_thread_num()
	do j=n*NaThr,n*NaThr+NaThr-1
	do i=1,2
	A(j+1)=A(j+1)+dsin(3.1415D0*(j+1)*i)
	enddo
	enddo
!$omp end parallel
	if (mod(k,2000).eq.0) print *,k
	enddo
    end program prog

It starts without any warning or errors but after certain number of time steps (variable “k”) the program become terminated with an error: “CreateThread failed”.

What does this error mean and how to overcome it?

Version of PGF is 11.6, OS is WinXP x64

Hi Mike,

I thinks what’s happening is that by putting “num_threads” in the parallel directive your forcing the creation and destruction of the threads with each iteration of the loop. Eventually, you run out of thread numbers.

To fix, remove “num_threads(thrNum)” from the parallel directive and instead call “omp_set_num_threads(thrNum)” before the do loop or set the environment variable OMP_NUM_THREADS to 4 before execution.

Hope this helps,
Mat

Hi Mat,

Thank you very much!!! It works :) I so appreciate your help!