OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgomp/] [testsuite/] [libgomp.fortran/] [strassen.f90] - Blame information for rev 865

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 735 jeremybenn
! { dg-options "-O2" }
2
 
3
program strassen_matmul
4
  use omp_lib
5
  integer, parameter :: N = 1024
6
  double precision, save :: A(N,N), B(N,N), C(N,N), D(N,N)
7
  double precision :: start, end
8
 
9
  call random_seed
10
  call random_number (A)
11
  call random_number (B)
12
  start = omp_get_wtime ()
13
  C = matmul (A, B)
14
  end = omp_get_wtime ()
15
  write(*,'(a, f10.6)') ' Time for matmul      = ', end - start
16
  D = 0
17
  start = omp_get_wtime ()
18
  call strassen (A, B, D, N)
19
  end = omp_get_wtime ()
20
  write(*,'(a, f10.6)') ' Time for Strassen    = ', end - start
21
  if (sqrt (sum ((C - D) ** 2)) / N .gt. 0.1) call abort
22
  D = 0
23
  start = omp_get_wtime ()
24
!$omp parallel
25
!$omp single
26
  call strassen (A, B, D, N)
27
!$omp end single nowait
28
!$omp end parallel
29
  end = omp_get_wtime ()
30
  write(*,'(a, f10.6)') ' Time for Strassen MP = ', end - start
31
  if (sqrt (sum ((C - D) ** 2)) / N .gt. 0.1) call abort
32
 
33
contains
34
 
35
  recursive subroutine strassen (A, B, C, N)
36
    integer, intent(in) :: N
37
    double precision, intent(in) :: A(N,N), B(N,N)
38
    double precision, intent(out) :: C(N,N)
39
    double precision :: T(N/2,N/2,7)
40
    integer :: K, L
41
 
42
    if (iand (N,1) .ne. 0 .or. N < 64) then
43
      C = matmul (A, B)
44
      return
45
    end if
46
    K = N / 2
47
    L = N / 2 + 1
48
!$omp task shared (A, B, T)
49
    call strassen (A(:K,:K) + A(L:,L:), B(:K,:K) + B(L:,L:), T(:,:,1), K)
50
!$omp end task
51
!$omp task shared (A, B, T)
52
    call strassen (A(L:,:K) + A(L:,L:), B(:K,:K), T(:,:,2), K)
53
!$omp end task
54
!$omp task shared (A, B, T)
55
    call strassen (A(:K,:K), B(:K,L:) - B(L:,L:), T(:,:,3), K)
56
!$omp end task
57
!$omp task shared (A, B, T)
58
    call strassen (A(L:,L:), B(L:,:K) - B(:K,:K), T(:,:,4), K)
59
!$omp end task
60
!$omp task shared (A, B, T)
61
    call strassen (A(:K,:K) + A(:K,L:), B(L:,L:), T(:,:,5), K)
62
!$omp end task
63
!$omp task shared (A, B, T)
64
    call strassen (A(L:,:K) - A(:K,:K), B(:K,:K) + B(:K,L:), T(:,:,6), K)
65
!$omp end task
66
!$omp task shared (A, B, T)
67
    call strassen (A(:K,L:) - A(L:,L:), B(L:,:K) + B(L:,L:), T(:,:,7), K)
68
!$omp end task
69
!$omp taskwait
70
    C(:K,:K) = T(:,:,1) + T(:,:,4) - T(:,:,5) + T(:,:,7)
71
    C(L:,:K) = T(:,:,2) + T(:,:,4)
72
    C(:K,L:) = T(:,:,3) + T(:,:,5)
73
    C(L:,L:) = T(:,:,1) - T(:,:,2) + T(:,:,3) + T(:,:,6)
74
  end subroutine strassen
75
end

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.