-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixVector.tex
More file actions
78 lines (64 loc) · 1.62 KB
/
MatrixVector.tex
File metadata and controls
78 lines (64 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
%%
%% MatrixVector.tex
%% Login : <hoang-trong@hoang-trong-laptop>
%% Started on Thu Oct 1 13:03:35 2009 Hoang-Trong Minh Tuan
%% $Id$
%%
%% Copyright (C) 2009 Hoang-Trong Minh Tuan
%%
\chapter{Matrix and Vector operations}
\label{chap:matr-vect-oper}
\section{Matrix-Matrix}
\label{sec:matrix-matrix}
\subsection{M-M multiplication}
\label{sec:m-m-multiplication}
\subsubsection{DO loop}
\label{sec:do-loop}
You use 3 DO loops.
\begin{lstlisting}
REAL, DIMENSION(*,*), ALLOCATABLE:: A, C, B
INTEGER, INTENT(IN) :: rA, cA, rB, cB
INTEGER, INTENT(INOUT) :: rC, cC
rC = rA
cC = cB
DO i = 1, rC
DO j = 1, cC
C(i, j) = 0.
DO k = 1, cA
C(i, j) = C(i, j) + A(i, k)*B(k, j)
ENDDO
ENDDO
ENDDO
\end{lstlisting}
\subsubsection{matmul }
\label{sec:matmul-}
MATMUL is an intrinsic subroutine whose detail implementation is
compiler-dependent. So, different compiler may give different
performance when with a program that use MATMUL.
\begin{lstlisting}
REAL(KIND=kr8), DIMENSION(:,:), ALLOCATABLE:: A, B, C
CALL CPU_TIME(start)
C = MATMUL(A, B)
CALL CPU_TIME(finish)
\end{lstlisting}
\subsubsection{BLAS level 1, 2}
\label{sec:blas-level-1}
BLAS use DGEMM or SGEMM for matrix-matrix multiplication.
\begin{lstlisting}
alpha = 1.0d0
beta = 0.0d0
rC = rA
cC = cB
IF (ALLOCATED(C)) THEN
DEALLOCATE(C)
END IF
ALLOCATE(C(rC, cC))
CALL CPU_TIME(start)
CALL dgemm('N', 'N', rA, cB, cA, alpha, A, rA, B, &
rB, beta, C, rA)
CALL CPU_TIME(finish)
\end{lstlisting}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "gpucomputing"
%%% End: