Giter Club home page Giter Club logo

ntustcfdlab's Issues

Data race in solver parallelised reduction

In the file solver.f90 at lines 81 and 125 appears this block:

!$OMP PARALLEL DO 
do i=1,n; norm=norm+r(i)*r(i); end do
!$OMP END PARALLEL DO

There is a data race here as threads handling different iterations of the reduction loop are trying to update the same variable concurrently. In order to restore correctness, the OpenMP reduction clause can be used, it will ensure that each thread sum its r(i)*r(i) increments into a thread-local temporary variable. At the end of the loop, OpenMP will make those threads sum the final value of their thread-local temporary variable back into the original norm variable, taking care of potential data races in the process. The corrected block would look as follows:

!$OMP PARALLEL DO REDUCTION(+:norm)
do i=1,n; norm=norm+r(i)*r(i); end do
!$OMP END PARALLEL DO

There might be other blocks in a similar situation, for which the same fix applies, such as the one at line 113 in the same file solver.f90:

!$OMP PARALLEL DO 
do i=1,n; x(i)=x(i)+alpha*p(i)+omega*ss(i); end do
!$OMP END PARALLEL DO

You can refer to https://rookiehpc.github.io/openmp/docs/reduction/index.html for more information.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.