Topic: Windows Openmp exe crashes with message of missing pthreadGC-32.dll

Hello, I am new to Simply Fortran and trying to build an openmp project. As background I will say I am not a programmer. I learned Fortran in the "before time". I think it was Fortran 66 in those days. My coding method is to hack around until it works, then refine as needed. I understand little of the jargon programmers use so I would as for patience with my dumb questions. Ultimately I want to update a simulation code to use the Openmp extensions to allow use of multi-processor Windows machines to increase speed of execution and scale of projects I can try. Thanks in advance for your help.

Right now I am working with sample program for openmp that I have played with a bit and even got it to work with MinGW compiler. In fact, now if I do the following on the command line:

gfortran workshare.f -o workshare -O2 -fopenmp

the program complies and will execute causing all 8 processors in my machine to go busy during the execution. This is good and what I want to have happen.

However, under Simply Fortran, I compile using the -fopenmp compiler option and the linker options -lgomp -lpthread options, the code compiles and links with the following:

==============================================================================
Open Watcom Make Version 1.9 (Built on May 17 2012)
Portions Copyright (c) 1988-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
    "F:\SimplyFortran\mingw-w64\bin\gfortran.exe" -c -o build\workshare.o -g -m32 -IF:/SimplyFortran/mingw-w64/include/ -O2 -fopenmp -Jmodules .\workshare.f
    "F:\SimplyFortran\mingw-w64\bin\gfortran.exe" -o f:\riod\temp\workshare.exe -static -m32 build\workshare.o -LF:/SimplyFortran/mingw-w64/lib/ -lgomp -lpthread

* Complete *

This looks normal build from what I can tell.

However, when I run the executable, a Windows pop up comes telling me the following:

"The program can't start because pthreadGC2-32.dll is missing from your computer. Try reinstalling the program to fix this problem."

The above dll is in my path and is in the bin directory of the SF install directory.

More information, the computer is a Win7 pro 64 bit system, the executable is to be 32 bit. The program I am compiling started as an example found on the web for openmp which I modified a bit make it more CPU intensive to test the SMP execution; here is the source code:

C FILE: omp_workshare1.f
C DESCRIPTION:
C   OpenMP Example - Loop Work-sharing - Fortran Version
C   In this example, the iterations of a loop are scheduled dynamically
C   across the team of threads.  A thread will perform CHUNK iterations
C   at a time before being scheduled for the next CHUNK of work.
C AUTHOR: Blaise Barney  5/99
C LAST REVISED: 01/09/04
C******************************************************************************

      PROGRAM WORKSHARE1

      INTEGER NTHREADS, TID, OMP_GET_NUM_THREADS,
     +  OMP_GET_THREAD_NUM, CHUNKSIZE, ICHNK
      integer*8 N, I
      PARAMETER (N=10000)
      PARAMETER (CHUNKSIZE=50)
      REAL*8 A(N), B(N), C(N), alp

      alp=dfloat(N)/10.0d0
!     Some initializations
      DO I = 1, N
        A(I) = dfloat(I-1)/ (2.0d0*3.141592654d0*alp)
        B(I) = dfloat(I-1)/(alp)
      ENDDO
      ICHNK = CHUNKSIZE

!$OMP PARALLEL SHARED(A,B,C,NTHREADS,ICHNK) PRIVATE(I,J,TID)

      TID = OMP_GET_THREAD_NUM()
      IF (TID .EQ. 0) THEN
        NTHREADS = OMP_GET_NUM_THREADS()
        PRINT *, 'Number of threads =', NTHREADS
      END IF
      PRINT *, 'Thread',TID,' starting...'

!$OMP DO SCHEDULE(DYNAMIC,ICHNK)
      do J=1,40000
      DO I = 1, N
        C(I) = dsqrt(dcos(A(I)) * dexp(-B(I))*dcos(A(I)))
        C(I)=C(I)*C(I)
!        WRITE(*,100) TID,I,C(I)
! 100    FORMAT(' Thread',I2,': C(',I7,')=',F10.5)
      ENDDO
      enddo
!$OMP END DO NOWAIT

      PRINT *, 'Thread',TID,' done.'

!$OMP END PARALLEL

      END

Re: Windows Openmp exe crashes with message of missing pthreadGC-32.dll

From the sounds of it, you shouldn't be experiencing any issues since the Simply Fortran mingw-w64\bin directory is on the path.  However, you clearly are having an issue.  One thing you can try is copying pthreadGC2-32.dll from the mingw-w64\bin directory to your project directory and try running the program again.  When a DLL is needed, Windows first searches the directory where the executable exists, then the path.  Hopefully the example will run if the DLL is in the same directory as the executable.

Let us know if you succeed in getting the example to work.

Jeff Armstrong
Approximatrix, LLC

Re: Windows Openmp exe crashes with message of missing pthreadGC-32.dll

Thanks for the response Jeff.

Ok, so I put a copy of the DLL in the directory I execute the program in and it does now run. I realized that I made a rookie mistake. The CMD prompts that I had open, were opened before the installation of Simply Fortran. Thus they never picked up the new path. Opening a new CMD window picks up the correct path, d'oh!

However, the above behavior disturbs me since I want to eventually create an executable that is completely self contained; without the constraint of having this DLL or not on computer that is executing the program. I want to the executable to be portable. Am I correct in my understanding that this DLL must be on the computer to run? If so, is there a way to pull the contents of the DLL into my code?

Thanks again,
Rod

Re: Windows Openmp exe crashes with message of missing pthreadGC-32.dll

Rod,

You are correct in that you'll need that DLL to be shipped with your executable to run the code on another machine.  I'll look into building a statically linked version of the library that could eliminate this issue.

Jeff Armstrong
Approximatrix, LLC

Re: Windows Openmp exe crashes with message of missing pthreadGC-32.dll

Thanks Jeff, I can live with this constraint for now since I am struggling with understanding what the openmp directives do in my simulation. I will probably open a new thread in the forum to ask questions about that. However, I need to do some more homework on this I think.

That said, I am surprised the no one else has had an issue with executable portability and the need to have that DLL on the local machine. Isn't there some way to link that DLL in the build step?

Much appreciation for the help!
Rod

Re: Windows Openmp exe crashes with message of missing pthreadGC-32.dll

Rod,

A DLL would have to be converted to a static library first to statically link the DLL into the executable.   While there are tools to convert libraries, it is significantly simpler to actually compile a static library in the first place. 

As for others not encountering the problem, it could be that those users who are working with OpenMP on Simply Fortran are doing both development and the analyses using the resultant program all on the same machine.  Also, there's a good chance that some users silently discovered and solved the problem themselves without having mentioned it on the forums.

Jeff Armstrong
Approximatrix, LLC