Parallelization using OpenMP

Forums General questions about Fortran programming Parallelization using OpenMP

This topic contains 3 replies, has 2 voices, and was last updated by Fabian Kindermann August 18, 2019 at 10:07 am.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1650

    DM Chun
    User

    Hi. I’m learning Fortran and OpenMP at the same time because I’ve recognized that parallelization of the code is really important to reduce computational time. I’ve succeeded in writing a parallel code for solving standard optimal growth model using value function iteration with grid search method in one main program. And now I’m struggling to do that with interpolation method. As a example, in prog08_05.f90, I’ve tried to modify the code to parallelize the part ! calculate optimal decision for every gridpoint such that,

           !$OMP PARALLEL DO PRIVATE( ia )
            do ia = 1, NA
    
                ! initialize starting value and communicate resources
                x_in = a(ia) - c(ia)
                ia_com = ia
    
                call fminsearch(x_in, fret, 0d0, a(ia), utility)
    
                ! get optimal consumption and value function
                c(ia) = a(ia) - x_in
                V_new(ia) = -fret
    
            enddo
            !$OMP END PARALLEL DO

    .

    However the distance between V_new(:) and V(:) does not converge, and adding x_in, ia_com into the list of PRIVATE clause or !$OMP threadprivate(ia_com) into prog08_05m.f90 cannot fix the problem. I think I have to make some more variables PRIVATE in each thread but got stuck. Would you please give me some advice?

    Thanks.

    Dongmin

    #1655

    Fabian Kindermann
    Moderator

    Dear Dongmin,

    it seems that at least ia_com, x_in and fret need to be declared as private in your code, as they are given different values in each iteration of the loop and would get messed up in a parallel loop. fminsearch should work in parallel mode. At least, I haven’t encountered any problems with it, yet.

    Try to set these three into the PRIVATE statement and see what happens. It would be great, if you could let men know whether it worked.

    Best,
    Fabian

    #1657

    DM Chun
    User

    Dear Fabian,

    Including ia_com, x_in and fret into the PRIVATE cannot fix the problem. The distance between V_new(:) and V(:) still does not converge. Should I modify external function in prog08_05m.f90?

    #1686

    Fabian Kindermann
    Moderator

    Dear Dongmin,

    are you changing any global variables within the function utility. This might also cause a problem.

    Best,
    Fabian

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.