Guest User

Untitled

a guest
Aug 27th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program main
  2.   integer*4, parameter          :: n=600, l=600, m=600
  3.   real*8                        :: A(l,m), B(m,n), C(l,n)
  4.  
  5.   write (*,*) size(A,1)
  6.   call init(A)
  7.   call init(B)
  8.   call mtx_mul(A,B,C)
  9.   ! call prt(C)
  10. contains
  11.   subroutine init(mtx)
  12.     real*8, intent(out)        :: mtx(:,:)
  13.     integer*4                  :: i,j
  14.  
  15.     do i = 1,ubound(mtx, 1)
  16.       do j = 1,ubound(mtx, 2)
  17.         mtx(i,j) = (i-1)*(j-1) + 0.6 * (j-1) + 3.4;
  18.       enddo
  19.     enddo
  20.   end subroutine init
  21.  
  22.   subroutine prt(mtx)
  23.     real*8, intent(in)        :: mtx(:,:)
  24.     integer*4                  :: i,j
  25.  
  26.     do i = 1,ubound(mtx, 1)
  27.       do j = 1,(ubound(mtx, 2) -1)
  28.         write (*,"(F10.1)",advance="no")  mtx(i,j)
  29.       enddo
  30.       write (*,"(F10.1)") mtx(i,ubound(mtx, 2))
  31.     enddo
  32.   end subroutine prt
  33.  
  34.   subroutine mtx_mul(A, B, C)
  35.     real*8, intent(in)       :: A(:,:), B(:,:)
  36.     real*8, intent(out)      :: C(:,:)
  37.     integer*4                :: i, j, k
  38.  
  39.     C = 0d0;
  40.  
  41.     do k = 1,ubound(C,2)
  42.       do i = 1,ubound(C,1)
  43.         do j = 1,ubound(A,2)
  44.           C(i,k) = C(i,k) + A(i,j) * B(j,k)
  45.         enddo
  46.       enddo
  47.     enddo
  48.  
  49.   end subroutine mtx_mul
  50.  
  51. end program main
Add Comment
Please, Sign In to add comment