hello everybody,
... I am new to fortran and I would like to implement a function/subroutine wich performes the direct matrix product ...
!
! The following nested do loops are used to
! calculate the direct product of two square
! matrices. This calculation is based on the following
! formula: C(i,j) = A(n,m)*B(i_prime, j_prime), with
! (n-1)*num_rows_B + 1 <= i <= n*num_rows_B = dim_2,
! (m-1)*num_columns_B + 1 <= i <= m*num_columns_B = dim_2,
! i_prime = i - (n-1)*num_rows_B + 1,
! j_prime = j - (m-1)*num_columns_B + 1,
! The resulting matrix C is build up block by block, according to the
! definition of the direct matrix product, i.e.
! the (num_rows_B x num_columns_B) block A(1,1)*B gets in the upper left corner, etc.
! The two outer do loops ( iterating n, m) thus go from one block to the next one.
! The two inner do loops ( iterating i, j) thus operate only within one block
!
DO n=1,dim_1, 1 ! dim_1 = num_rows_A = num_columns_A
DO m=1, dim_1, 1 ! dim_1 = num_rows_A = num_columns_A
row_min = (n-1)*dim_2 + 1
row_max = n*dim_2
column_min = (m-1)*dim_2 + 1
column_max = m*dim_2
DO i=row_min, row_max, 1 ! dim_1 = num_rows_B = num_columns_B
DO j=column_min, column_max, 1 ! dim_1 = num_rows_B = num_columns_B
i_prime = i - row_min + 1
j_prime = j - column_min +1
res_matrix%array(i,j) = sq_matrix_1%array(n, m) * sq_matrix_2%array(i_prime, j_prime)
ENDDO
ENDDO
ENDDO
ENDDO
!
! This forall construct is not equivalent to the do loops above ... WHY ???????
!
! FORALL ( n=1:dim_1, m=1:dim_1 )
! row_min = (n-1)*dim_2 + 1
! row_max = n*dim_2
! column_min = (m-1)*dim_2 + 1
! column_max = m*dim_2
! FORALL ( i=(n-1)*dim_2:n*dim_2, j=(m-1)*dim_2:m*dim_2 )
! i_prime = i - row_min + 1
! j_prime = j - column_min +1
! res_matrix%array(i,j) = sq_matrix_1%array(n, m) * sq_matrix_2%array(i_prime, j_prime)
! END FORALL
! END FORALL
... it seems that this statments are not equivalent ... I dont know why ...
thanks in advance
tservas
... I am new to fortran and I would like to implement a function/subroutine wich performes the direct matrix product ...
!
! The following nested do loops are used to
! calculate the direct product of two square
! matrices. This calculation is based on the following
! formula: C(i,j) = A(n,m)*B(i_prime, j_prime), with
! (n-1)*num_rows_B + 1 <= i <= n*num_rows_B = dim_2,
! (m-1)*num_columns_B + 1 <= i <= m*num_columns_B = dim_2,
! i_prime = i - (n-1)*num_rows_B + 1,
! j_prime = j - (m-1)*num_columns_B + 1,
! The resulting matrix C is build up block by block, according to the
! definition of the direct matrix product, i.e.
! the (num_rows_B x num_columns_B) block A(1,1)*B gets in the upper left corner, etc.
! The two outer do loops ( iterating n, m) thus go from one block to the next one.
! The two inner do loops ( iterating i, j) thus operate only within one block
!
DO n=1,dim_1, 1 ! dim_1 = num_rows_A = num_columns_A
DO m=1, dim_1, 1 ! dim_1 = num_rows_A = num_columns_A
row_min = (n-1)*dim_2 + 1
row_max = n*dim_2
column_min = (m-1)*dim_2 + 1
column_max = m*dim_2
DO i=row_min, row_max, 1 ! dim_1 = num_rows_B = num_columns_B
DO j=column_min, column_max, 1 ! dim_1 = num_rows_B = num_columns_B
i_prime = i - row_min + 1
j_prime = j - column_min +1
res_matrix%array(i,j) = sq_matrix_1%array(n, m) * sq_matrix_2%array(i_prime, j_prime)
ENDDO
ENDDO
ENDDO
ENDDO
!
! This forall construct is not equivalent to the do loops above ... WHY ???????
!
! FORALL ( n=1:dim_1, m=1:dim_1 )
! row_min = (n-1)*dim_2 + 1
! row_max = n*dim_2
! column_min = (m-1)*dim_2 + 1
! column_max = m*dim_2
! FORALL ( i=(n-1)*dim_2:n*dim_2, j=(m-1)*dim_2:m*dim_2 )
! i_prime = i - row_min + 1
! j_prime = j - column_min +1
! res_matrix%array(i,j) = sq_matrix_1%array(n, m) * sq_matrix_2%array(i_prime, j_prime)
! END FORALL
! END FORALL
... it seems that this statments are not equivalent ... I dont know why ...
thanks in advance
tservas