Parallel numerical integration (summation) in OpenMP

I recently started learning about parallel coding, I am still at the beginning, so I wanted to try a very simple coding. Since I'm interested in doing parallel numerical integration, I started with a simple Fortran transformation code:

program par_hello_world

use omp_lib

implicit none

integer, parameter:: bign = 1000000000
integer:: i

double precision:: start, finish, start1, finish1, a

a = 0

call cpu_time(start)

!$OMP PARALLEL num_threads(8)

  !$OMP DO REDUCTION(+:a)

    do i = 1,bign


      a = a + sqrt(1.0**5)

    end do

  !$OMP END DO

!$OMP END PARALLEL

call cpu_time(finish)

print*, 'parallel result:'

print*, a

print*, (finish-start)


a=0

call cpu_time(start1)

do i = 1,bign

  a = a + sqrt(1.0**5)

end do

call cpu_time(finish1)

print*, 'sequential result:'

print*, a

print*, (finish1-start1)

end program

      

The code basically simulates summation, I used a weird expression sqrt(1.0**5)

to measure the computational time, if I only used it 1

, the computation time was so small that I could not compare the serial code against parallel. I tried to avoid the race condition using a suggestion REDUCTION

.

However, I am getting very strange results time

:

  • If I increase the number of threads from 2 to 16, I don't get a reduction in computational time, but somehow I even get an increase.
  • It seems incredibly that sequential code is affected by the choice of thread number (I really don't understand why!), In particular, it goes up if I raise the number of threads.
  • I am getting the correct result for the variable a

I think I am doing something very bad, but I do not know about it ...

0
performance multithreading parallel-processing fortran numeric


source to share


No one has answered this question yet

See similar questions:

3
OpenMP Summation

or similar:

2847
Improve SQLite performance per second per second?
1406
Why does changing 0.1f to 0 slow down performance by 10x?
1250
Replacing 32-bit loop counter with 64-bit values ​​leads to crazy performance deviations
950
What is the difference between concurrency and concurrency?
870
Swift Beta: Sorting Arrays
854
How to allow only numeric (0-9) in HTML input field using jQuery?
757
How to check if String is numeric in Java
4
Parallel acceleration with OpenMP
1
Java 8 parallel thread reduction - thread count vs. speedup
1
parallelizing C ++ code with OpenMP does not improve performance



All Articles
Loading...
X
Show
Funny
Dev
Pics