CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Parallel Fortran 95 code using Openmp

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree3Likes
  • 1 Post By sbaffini
  • 2 Post By flotus1

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 12, 2020, 16:18
Default Parallel Fortran 95 code using Openmp
  #1
New Member
 
Shivank
Join Date: May 2019
Posts: 10
Rep Power: 2
Shiv1510 is on a distinguished road
Hello everyone

Hope this is a right forum to ask for help regarding Parallelization of a serial fortran cfd code.

I have written a very basic CFD code in fortran 95 (explicit) to solve for flow over a flat plate using method of pseudo-compressibility. It has subroutines to solve continuity, x-momentum and y-momentum. I am trying to convert this code from series to parallel and have gone through some literature on Openmp present online. I still cannot make the transition. I am trying to distribute the solving of each equation(subroutine) using !$OMP SECTIONS work sharing construct to each thread, and do loops using !$OMP DO, but it does not seem to work.

Does anybody have an example or basic learning parallel cfd fortran code that they can share or even just help me out, it would be great.

Thanks in advance
Shiv1510 is offline   Reply With Quote

Old   February 13, 2020, 01:42
Default
  #2
Senior Member
 
Mehdi Baba Mehdi
Join Date: Jan 2011
Location: Germany
Posts: 153
Rep Power: 11
mb.pejvak is on a distinguished road
your question is so vague. what do you mean when you say it does not work, you mean it was not scaled well or something else.
If your code has not been scaled, As far as I know there is some rule for parallelization, does not matter for which field you want to use it. Please first read some literatures about rules in parallelization, and then start change your code. Keep it in mind, if your code is quite complicated, it would not be easy to parallelize it, and expect your code to be scaled (if it does not make some problem as well)..
I recommend the book "An Introduction to Parallel Programming" by Peter Pacheco, but it only talks about programming part not algorithms.

Last edited by mb.pejvak; February 16, 2020 at 02:06.
mb.pejvak is offline   Reply With Quote

Old   February 13, 2020, 05:35
Default
  #3
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 1,133
Blog Entries: 19
Rep Power: 26
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
I subscribe to all previous suggestions.

In general, however, that's the idea, splitting work of EVERY loop that scales with number of cells/faces/nodes/etc. The point is that you need to be very careful in how you write stuff in these loops, in order to prevent errors and facilitate actual splitting of the work.
Shiv1510 likes this.
sbaffini is offline   Reply With Quote

Old   February 13, 2020, 06:34
Default
  #4
Senior Member
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 2,295
Rep Power: 33
flotus1 will become famous soon enoughflotus1 will become famous soon enough
Copy that. Writing OpenMP parallel code that is correct is relatively easy. Making it scale, especially on NUMA systems, often requires a bit more effort.

That being said, here is a minimal example for one subroutine, as you requested:
Code:
SUBROUTINE push(f_1,f_2)
    
    use types
    use parameters
    use vars_and_data
    
    implicit none
    
    REAL(DP), DIMENSION(0:26,ncc), INTENT(IN)  :: f_1
    REAL(DP), DIMENSION(0:26,ncc), INTENT(OUT) :: f_2
    INTEGER(I4B) :: n, i
    
    !$OMP PARALLEL PRIVATE(n,i)
    !$OMP DO SCHEDULE(STATIC)
    do n=1, ncc
        
        do i=0, 26
            f_2(i,links(i,n)) = f_1(i,n)
        end do
        
    end do
    !$OMP END DO
    !$OMP END PARALLEL
    
END SUBROUTINE push
ssh123 and Shiv1510 like this.
__________________
Please do not send me CFD-related questions via PM
flotus1 is offline   Reply With Quote

Old   February 14, 2020, 12:34
Default
  #5
New Member
 
Shivank
Join Date: May 2019
Posts: 10
Rep Power: 2
Shiv1510 is on a distinguished road
Thank you Sir for the snippet, this is exactly what I was looking for.
Shiv1510 is offline   Reply With Quote

Old   February 14, 2020, 12:36
Default
  #6
New Member
 
Shivank
Join Date: May 2019
Posts: 10
Rep Power: 2
Shiv1510 is on a distinguished road
My apologies for not putting my question in a comprehensible way, I am just getting started with parallel programming for CFD. I will definitely look into more literature and the book you have recommended. Thank you again
Shiv1510 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel Fortran ho_afshar Main CFD Forum 11 November 9, 2018 04:26
Need help on checking HLL and Rusanov fortran code. pinball1997 Main CFD Forum 0 April 4, 2018 08:44
How to make code run in parallel? cwang5 OpenFOAM Programming & Development 1 May 30, 2011 05:47
fortran code - boundary layer - frank white Ed Main CFD Forum 1 February 12, 2009 18:30
Speeding my Fortran Code S Main CFD Forum 11 March 31, 2005 15:50


All times are GMT -4. The time now is 10:00.