Topic: OpenMP and Appgraphics

Hello, when I try to do some parallel programing with OpenMP it works perfectly, until I try to do it anywhere inside a subroutine called from clicking a button from Appgraphics. The program just stops working with the respective windows message, am I doing something wrong?

I'm running version 2.39.2491 on Windows 7 Ultimate

Re: OpenMP and Appgraphics

I'm not exactly sure why your program is locking up, but I do have some suggestions.  One important fact to keep in mind is that subroutines called from button clicks are not running in your main program thread, but, rather, the graphical user interface thread.  Any long-running calculations should not be handled in that subroutine directly.  I normally suggest using the button handler to set a variable and release the main program from idle.  Once un-idled, the program will take some action based on the value of that variable.  The "Conway's Game of Life" example that comes with Simply Fortran uses this method.

Additionally, OpenMP relies on Windows threading routines internally, and it might make some assumptions about the program's current state in regards to threads. Since AppGraphics programs are already using multiple threads, there may be some sort of deadlock occurring.  I'm not positive, though, why that would occur.

I'll look into it more on my end, but I would strongly suggest keeping all OpenMP calls within the main program by using the equivalent of a message loop to handle button presses.

Jeff Armstrong
Approximatrix, LLC

Re: OpenMP and Appgraphics

Thanks Jeff! I will look forward into that.

This simple piece of code can recreate the problem when compiled with the "enable OpenMP" option enabled

program  test
    use appgraphics
    implicit none
    button = createbutton(0,0,200,200,'testbutton',testsubroutine)

    call loop()
    call closewindow(screen)
        subroutine testsubroutine()
            implicit none
            write(*,*)'Hello, world!'
        end subroutine
end program

Re: OpenMP and Appgraphics

There was a bug in our OpenMP implementation that assumed that a pointer to thread information is always initialized.  Because AppGraphics uses Windows-native threading (as opposed to OpenMP constructs), the graphical user interface thread did not have this OpenMP-related thread pointer available, causing the program to crash.

The OpenMP library was updated to initialize a new thread information pointer immediately if OpenMP requests thread information and nothing is available.  It should allow our OpenMP implementation to properly co-exist with Windows threads.

The fix will be included in Simply Fortran 2.40, due out shortly.

Jeff Armstrong
Approximatrix, LLC