!******************************** !* rozdzial.f !********************************
program rozdzial_iteracji parameter (N=100) integer tab(N), i, moj_num, licz_wtk, porcja, pocz, kon external omp_get_thread_num, omp_get_num_threads integer omp_get_thread_num, omp_get_num_threads ! !$omp parallel private (moj_num, licz_wtk, porcja, pocz, kon, i) ! Obliczenie poczatku i konca wycinka tablicy, na ktorej bedzie ! dzialal dany watek licz_wtk = omp_get_num_threads() !zwraca liczbe watkow moj_num = omp_get_thread_num() !zwraca numer watka porcja = (N+licz_wtk-1)/licz_wtk pocz = moj_num*porcja+1 kon = min ( (moj_num+1)*porcja, N ) do i = pocz, kon tab(i) = i+i enddo !$omp end parallel do i = 1,N print *, 'tab(',i,')= ', tab(i) enddo stop end
!******************************** !* witam.f !********************************
program witam external omp_get_thread_num integer omp_get_thread_num ! print *, 'Witam! Tu watek glowny nr ', omp_get_thread_num() !$omp parallel print *, 'Tu watek nr ', omp_get_thread_num() !$omp end parallel print *, 'Witam ponownie! Watek glowny nr ', omp_get_thread_num() stop end
|
!******************************** !* witam2.f !******************************* program witam2 external omp_get_thread_num integer omp_get_thread_num, i ! !$omp parallel do i = 1,12 print *, 'Iteracja nr ', i, ' Watek nr ', omp_get_thread_num() enddo !$omp end parallel stop end
!******************************** !* witam3.f !********************************
program witam3 external omp_get_thread_num integer omp_get_thread_num ! !$omp parallel print *, 'Tu watek nr ', omp_get_thread_num() !$omp end parallel print *, 'Watki sie skonczyly, dziala tylko watek glowny ' !$omp parallel print *, 'Tu ponownie powolany watek nr ', omp_get_thread_num() !$omp end parallel stop end
!******************************** !* witamproc.f !********************************
program witamproc ! !$omp parallel call witam ! zakres statyczny - tylko ta instrukcja !$omp end parallel stop end ! ! subroutine witam ! w calosci wchodzi w zakres dynamiczny external omp_get_thread_num integer omp_get_thread_num ! print *, 'Tu watek nr ', omp_get_thread_num() return end
|
!******************************** !* saxpy.f !******************************** program saxpy integer n, i, num(50) real a, y, z(50), x(50) external omp_get_thread_num integer omp_get_thread_num ! n = 16 do i = 1, n x(i) = i enddo y = 30.0 a = 2.0 !$omp parallel do do i = 1, n z(i) = a*x(i) + y print *, omp_get_thread_num() enddo !$omp end parallel do do i = 1, n print *, 'z(',i,') = ', z(i) enddo ! stop end !******************************** !* testdith.f !******************************** program testdith integer n, i, m, j, istart, iend, mywidth, mythread real x, y, depth(20,20), dith(20,20) external omp_get_thread_num integer omp_get_thread_num ! n = 6 m = 6 !$omp parallel !$omp& private(i,j,x,y) !$omp& private(mywidth,mythread,istart,iend) mywidth = m/2 mythread = omp_get_thread_num() istart = 1 + mythread*mywidth iend = istart + mywidth - 1 do i = istart, iend do j = 1, n x = i/real(m) y = j/real(n) depth(j,i) = x + y enddo enddo do i = istart, iend do j = 2, n dith(j,i) = 10.0*depth(j-1,i) enddo enddo !$omp end parallel do i = 1, m do j = 1, n print *, 'dith(',i,j,') = ', dith(i,j) enddo enddo ! stop end
|
!******************************** !* testsax.f !******************************** program testsax integer n, i, num(50) real z(50), a, x(50), y external omp_get_thread_num integer omp_get_thread_num ! n = 10 do i = 1, n x(i) = i enddo y = 30.0 a = 2.0 !$omp parallel do schedule (static) do i = 1, n z(i) = a*x(i) + y num(i) = omp_get_thread_num() enddo !$omp end parallel do do i = 1, n print *, 'z(',i,') = ', z(i), ' watek nr ', num(i) enddo ! stop end ********************* !* witam1.f !******************************** program witam1 external omp_get_thread_num integer omp_get_thread_num, i ! !$omp parallel do do i = 1,12 print *, 'Iteracja nr ', i, ' Watek nr ', omp_get_thread_num() enddo !$omp end parallel do stop end
!******************************** !* wywolanie.f !******************************** program wywolanie real a(8), sum external omp_get_thread_num integer i, omp_get_thread_num c !$omp parallel do private (sum) do i = 1,8 ! a - wspolne ! sum - prywatne a(i) = i + i ! dla ilustracji roznicy z tablica b sum = 0.0 call proc(sum) print *, 'Iteracja nr ',i,' Watek nr ',omp_get_thread_num(), & ' Suma = ',sum enddo !$omp end parallel do stop end
subroutine proc(s) real b(4), s integer i, omp_get_thread_num external omp_get_thread_num c do i = 1,4 ! b i s sa lokalne w procedurze, a wiec prywatne b(i) = i*omp_get_thread_num() s = s + b(i) enddo return end |
!******************************** program nest1 integer n, i, m, j real x, y, depth(20,20) n = 4 m = 12 !$omp parallel do private(j,x,y) do i = 1, m do j = 1, n x = i/real(m) y = j/real(n) depth(j,i) = x + y enddo enddo !$omp end parallel do do i = 1, m do j = 1, n print *, 'depth(',j,',',i,') = ', depth(j,i) enddo enddo stop end !******************************** program nest2 integer n, i, m, j real x, y, depth(20,20), sum n = 4 m = 12 sum = 0.0 !$omp parallel do private(j,x,y) do i = 1, m do j = 1, n x = i/real(m) y = j/real(n) depth(j,i) = x + y !$omp critical sum = sum + depth(j,i) !$omp end critical enddo enddo !$omp end parallel do do i = 1, m do j = 1, n print *, 'depth(',j,',',i,') = ', depth(j,i) enddo enddo print *, 'suma =', sum stop end !******************************** program nest3 integer n, i, m, j real x, y, depth(20,20), sum n = 4 m = 12 sum = 0.0 !$omp parallel do private(j,x,y) !$omp& reduction(+: sum) do i = 1, m do j = 1, n x = i/real(m) y = j/real(n) depth(j,i) = x + y sum = sum + depth(j,i) enddo enddo !$omp end parallel do do i = 1, m do j = 1, n print *, 'depth(',j,',',i,') = ', depth(j,i) enddo enddo print *, 'suma =', sum ! stop end |
!******************************** !* privy.f !********************************
program privy integer n, i real a, y, z(50), x(50), yy(50) ! n = 16 do i = 1, n x(i) = i enddo y = 30.0 a = 2.0 !$omp parallel do do i = 1, n y = y + i z(i) = a*x(i) + y yy(i) = y enddo !$omp end parallel do do i = 1, n print *, ' y w iteracji ', i, ' : ', yy(i) enddo print *,'Koncowa wartosc y : ',y stop end !******************************** !* redmax.f !********************************
program redmax integer a(20), k, i do i = 1,20 a(i) = mod(30,i) enddo k = a(1) !$omp parallel do reduction (max : k) do i = 2,20 k = max(k,a(i)) enddo !$omp end parallel do print *, 'Maksymalny element : ',k stop end !******************************** !* redsum.f !******************************** program redsum real a(20), sum integer i do i = 1,20 a(i) = i/3.0 enddo sum = 0.0 !$omp parallel do reduction (+ : sum) do i = 1,20 sum = sum + a(i) enddo !$omp end parallel do print *, 'Suma = ',sum stop end |
!******************************** !* dep1.f !********************************
program dep1 real a(20) integer i do i = 1,20 a(i) = i enddo !$omp parallel do do i = 2,20 a(i) = a(i) + a(i-1) enddo !$omp end parallel do do i = 1,20 print *,'a(',i,')= ',a(i) enddo stop end
!******************************** !* dep2.f !********************************
program dep2 real a(20),b(20),c(20),x integer i do i = 1,20 a(i) = i b(i) = i c(i) = i enddo !$omp parallel do do i = 1,19 x = (b(i)+c(i))/2 a(i) = a(i+1) + x enddo !$omp end parallel do do i = 1,20 print *,'a(',i,')= ',a(i) enddo stop end
!******************************** !* dep2rem.f !********************************
program dep2rem real a(20),b(20),c(20),x,a2(20) integer i do i = 1,20 a(i) = i b(i) = i c(i) = i enddo !$omp parallel do do i = 1,19 a2(i) = a(i+1) enddo !$omp end parallel do !$omp parallel do private(x) do i = 1,19 x = (b(i)+c(i))/2 a(i) = a2(i) + x enddo !$omp end parallel do do i = 1,20 print *,'a(',i,')= ',a(i) enddo stop end
!******************************** !* dep5rem.f !********************************
program dep5rem real a(20), b(20) integer i do i = 1,20 a(i) = i enddo b(1) = 1.0 do i = 2,20 a(i) = a(i) + a(i-1) enddo !$omp parallel do do i = 2,20 b(i) = a(i) - 10.0 enddo !$omp end parallel do do i = 1,20 print *,'a(',i,')= ',a(i),' b(',i,')= ',b(i) enddo stop end
!******************************** program dep6 real a(20),b(20),c(20),y integer i do i = 1,20 a(i) = i b(i) = i c(i) = i enddo y = 10.0 !$omp parallel do do i = 1,20 y = y + a(i) b(i) = (b(i) + c(i)) * y enddo !$omp end parallel do do i = 1,20 print *,'b(',i,')= ',b(i) enddo print *, 'y =', y stop end !******************************** program dep6rem real a(20),b(20),c(20),y,y2(20) integer i do i = 1,20 a(i) = i b(i) = i c(i) = i enddo y = 10.0 y2(1) = y + a(1) do i = 2,20 y2(i) = y2(i-1) + a(i) enddo y = y2(20) !$omp parallel do do i = 1,20 b(i) = (b(i) + c(i)) * y2(i) enddo !$omp end parallel do do i = 1,20 print *,'b(',i,')= ',b(i) enddo print *, 'y =', y stop end
|
!******************************** !* dep4.f !********************************
program dep4 real a(20),b(20),c(20) integer i do i = 1,20 a(i) = i b(i) = i c(i) = i enddo !$omp parallel do do i = 2,20 b(i) = b(i) + a(i-1) a(i) = a(i) + c(i) enddo !$omp end parallel do do i = 1,20 print *,'b(',i,')= ',b(i) enddo stop end
!******************************** !* dep4rem.f !********************************
program dep4rem real a(20),b(20),c(20) integer i do i = 1,20 a(i) = i b(i) = i c(i) = i enddo b(2) = b(2) + a(1) !$omp parallel do do i = 2,19 a(i) = a(i) + c(i) b(i+1) = b(i+1) + a(i) enddo !$omp end parallel do a(20) = a(20) + c(20) do i = 1,20 print *,'b(',i,')= ',b(i) enddo stop end
!******************************** !* dep5.f !********************************
program dep5 real a(20), b(20) integer i do i = 1,20 a(i) = i enddo b(1) = 1.0 !$omp parallel do do i = 2,20 a(i) = a(i) + a(i-1) b(i) = a(i) - 10.0 enddo !$omp end parallel do do i = 1,20 print *,'a(',i,')= ',a(i),' b(',i,')= ',b(i) enddo stop end
!******************************** program dep7 real a(8,8) integer i do i = 1,8 do j = 1,8 a(i,j) = i+j enddo enddo !$omp parallel do do i = 2,8 do j = 1,8 a(i,j) = a(i,j) + a(i-1,j) enddo enddo !$omp end parallel do do i = 1,8 do j = 1,8 print *,'a(',i,',',j,')= ', a(i,j) enddo enddo stop end !******************************** program dep7inter real a(8,8) integer i do i = 1,8 do j = 1,8 a(i,j) = i+j enddo enddo !$omp parallel do do j = 1,8 do i = 2,8 a(i,j) = a(i,j) + a(i-1,j) enddo enddo !$omp end parallel do do i = 1,8 do j = 1,8 print *,'a(',i,',',j,')= ', a(i,j) enddo enddo stop end !******************************** program dep7rem real a(8,8) integer i do i = 1,8 do j = 1,8 a(i,j) = i+j enddo enddo do i = 2,8 !$omp parallel do do j = 1,8 a(i,j) = a(i,j) + a(i-1,j) enddo !$omp end parallel do enddo do i = 1,8 do j = 1,8 print *,'a(',i,',',j,')= ', a(i,j) enddo enddo stop end
|
!******************************** !* pi.f !******************************** program compute_pi integer n, i double precision w, x, sum, pi ! print *, 'Enter number of intervals: ' read *, n w = 1.d0/n sum = 0.0d0 !$omp parallel do private(x) !$omp& reduction(+: sum) do i = 1, n x = w * (i - 0.5d0) sum = sum + f(x) enddo pi = w * sum print *, 'computed pi = ', pi stop end
double precision function f(a) double precision a f = 4.d0 / (1.d0 + a*a) return end !******************************** !* sched.f !********************************
program sched integer n, i real a, y, z(500), x(500) external omp_get_thread_num integer omp_get_thread_num ! n = 128 do i = 1, n x(i) = i enddo y = 30.0 a = 2.0 !$omp parallel do schedule(static) do i = 1, n x(i) = x(i) + y z(i) = a*x(i) !$omp critical print *,'iteracja nr ',i, & ' watek nr ', omp_get_thread_num(), & ' z(', i, ')= ', z(i) !$omp end critical enddo !$omp end parallel do stop end
|
!******************************** !* sekcje.f !******************************** program sekcje parameter (N=20) integer tab1(N), tab2(N), tab3(N), tab4(N), i external omp_get_thread_num integer omp_get_thread_num ! !$omp parallel sections !$omp section do i = 1,N tab1(i) = i+10 enddo print *, 'Watek nr ', omp_get_thread_num(), ' wypelnil tab1' !$omp section do i = 1,N tab2(i) = i+20 enddo print *, 'Watek nr ', omp_get_thread_num(), ' wypelnil tab2' !$omp section do i = 1,N tab3(i) = i+30 enddo print *, 'Watek nr ', omp_get_thread_num(), ' wypelnil tab3' !$omp section do i = 1,N tab4(i) = i+40 enddo print *, 'Watek nr ', omp_get_thread_num(), ' wypelnil tab4' !$omp end parallel sections do i = 1,N print *, 'tab1(',i,') = ', tab1(i) enddo do i = 1,N print *, 'tab2(',i,') = ', tab2(i) enddo do i = 1,N print *, 'tab3(',i,') = ', tab3(i) enddo do i = 1,N print *, 'tab4(',i,') = ', tab4(i) enddo stop end
!******************************** !* single.f !********************************
program single external omp_get_thread_num integer omp_get_thread_num, i, k ! !$omp parallel !$omp critical do i = 1,12 print *, 'Iteracja nr ', i, ' Watek nr ', omp_get_thread_num() enddo !$omp end critical !$omp single k = omp_get_thread_num() print *, ' Watek nr ', k print *, ' melduje zakonczenie swojej petli' !$omp end single no wait !$omp critical if ( omp_get_thread_num() .ne. k ) then print *, ' Watek nr ', omp_get_thread_num() print *, ' nie meldowal sie i ruszyl dalej' endif !$omp end critical !$omp end parallel stop end
|
1