\hypertarget{kdtpgetrf_8c}{}\section{src/kdtpgetrf.c File Reference}
\label{kdtpgetrf_8c}\index{src/kdtpgetrf.\+c@{src/kdtpgetrf.\+c}}


L\+A\+Ss-\/\+D\+D\+Ss kdtpgetrf routine.  


{\ttfamily \#include \char`\"{}../include/lass.\+h\char`\"{}}\\*
Include dependency graph for kdtpgetrf.\+c\+:
\nopagebreak
\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=350pt]{kdtpgetrf_8c__incl}
\end{center}
\end{figure}
\subsection*{Functions}
\begin{DoxyCompactItemize}
\item 
enum L\+A\+S\+S\+\_\+\+R\+E\+T\+U\+RN \hyperlink{kdtpgetrf_8c_aa6fc273b5c4ac8c9875d3f398763fab9}{kdtpgetrf} (int M, int N, double $\ast$A, int L\+DA, int $\ast$I\+P\+IV)
\end{DoxyCompactItemize}


\subsection{Detailed Description}
L\+A\+Ss-\/\+D\+D\+Ss kdtpgetrf routine. 

L\+A\+Ss-\/\+D\+D\+Ss is a software package provided by\+: Barcelona Supercomputing Center -\/ Centro Nacional de Supercomputacion

\begin{DoxyAuthor}{Author}
Pedro Valero-\/\+Lara \href{mailto:pedro.valero@bsc.es}{\tt pedro.\+valero@bsc.\+es} 

Boro Sofranac \href{mailto:boro.sofranac@bsc.es}{\tt boro.\+sofranac@bsc.\+es} 
\end{DoxyAuthor}
\begin{DoxyDate}{Date}
2018-\/04-\/08   2018-\/05-\/08 
\end{DoxyDate}


\subsection{Function Documentation}
\index{kdtpgetrf.\+c@{kdtpgetrf.\+c}!kdtpgetrf@{kdtpgetrf}}
\index{kdtpgetrf@{kdtpgetrf}!kdtpgetrf.\+c@{kdtpgetrf.\+c}}
\subsubsection[{\texorpdfstring{kdtpgetrf(int M, int N, double $\ast$\+A, int L\+D\+A, int $\ast$\+I\+P\+I\+V)}{kdtpgetrf(int M, int N, double *A, int LDA, int *IPIV)}}]{\setlength{\rightskip}{0pt plus 5cm}enum L\+A\+S\+S\+\_\+\+R\+E\+T\+U\+RN kdtpgetrf (
\begin{DoxyParamCaption}
\item[{int}]{M, }
\item[{int}]{N, }
\item[{double $\ast$}]{A, }
\item[{int}]{L\+DA, }
\item[{int $\ast$}]{I\+P\+IV}
\end{DoxyParamCaption}
)}\hypertarget{kdtpgetrf_8c_aa6fc273b5c4ac8c9875d3f398763fab9}{}\label{kdtpgetrf_8c_aa6fc273b5c4ac8c9875d3f398763fab9}
Performs the LU factorization with tiled pivoting ( row interchanges ) of a general M-\/by-\/N matrix A\+: \begin{DoxyVerb}A = P * L * U
\end{DoxyVerb}


where P is a permutation matrix, L is a lower triangular ( lower trapezoidal if M $>$ N ) matrix with unit diagonal elements and U is an upper triangular ( upper trapezoidal if M $<$ N ) matrix.


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em M} & int. M specifies the number of rows of the matrix A. M $>$= 0.\\
\hline
\mbox{\tt in}  & {\em N} & int. N specifies the number of columns of the matrix A. N $>$= 0.\\
\hline
\mbox{\tt in,out}  & {\em A} & double $\ast$. A is a pointer to a regular matrix of dimension M-\/by-\/N. On exit, if return value is Success, the matrix A is overwriten by the factors L and U. The unit diagonal elements of L are not stored.\\
\hline
\mbox{\tt in}  & {\em L\+DA} & int. L\+DA specifies the number of columns of A ( row-\/major order ). L\+DA must be at least max( 1, N ).\\
\hline
\mbox{\tt out}  & {\em I\+P\+IV} & int $\ast$. ipiv is a pointer to an array of dimesion at least max( 1, min ( M, N ) ). ipiv( i ) = j, 1 $<$= i $<$= min( M, N ) implies that rows i and j have been interchanged.\\
\hline
\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
{\em Success} & successful exit \\
\hline
{\em No\+Success} & unsuccessful exit\\
\hline
\end{DoxyRetVals}
\begin{DoxySeeAlso}{See also}
ddss\+\_\+tile 

ddss\+\_\+flat2tiled 

ddss\+\_\+tiled2flat 
\end{DoxySeeAlso}


Definition at line 80 of file kdtpgetrf.\+c.



References ddss\+\_\+dflat2tiled(), ddss\+\_\+dtiled2flat(), and ddss\+\_\+tile\+\_\+size().



Referenced by ddss\+\_\+dtpgetrf().


\begin{DoxyCode}
81 \{
82 
83     \textcolor{comment}{// Local variables}
84     \textcolor{keywordtype}{int} i;
85     \textcolor{keywordtype}{int} mt, nt;
86     \textcolor{keywordtype}{int} mi, mmi, ki, ni;
87     \textcolor{keywordtype}{int} tile\_size\_m;
88     \textcolor{keywordtype}{int} tile\_size\_mm;
89     \textcolor{keywordtype}{int} tile\_size\_n;
90     \textcolor{keywordtype}{int} tile\_size\_km;
91     \textcolor{keywordtype}{int} tile\_size\_kn;
92     \textcolor{keywordtype}{int} local\_ipiv\_size;
93     \textcolor{keywordtype}{int} current\_position;
94     \textcolor{keyword}{enum} LASS\_RETURN ret;
95     \textcolor{keywordtype}{int} *ipiv\_local;
96 
97     \textcolor{comment}{// Number of tiles}
98     \textcolor{keywordflow}{if} ( M % TILE\_SIZE == 0 )
99     \{
100         mt = M / TILE\_SIZE;
101     \}
102     \textcolor{keywordflow}{else}
103     \{
104         mt = ( M / TILE\_SIZE ) + 1;
105     \}
106 
107     \textcolor{keywordflow}{if} ( N % TILE\_SIZE == 0 )
108     \{
109         nt = N / TILE\_SIZE;
110     \}
111     \textcolor{keywordflow}{else}
112     \{
113         nt = ( N / TILE\_SIZE ) + 1;
114     \}
115 
116     \textcolor{comment}{/***************************}
117 \textcolor{comment}{    --Tile A matrix allocation--}
118 \textcolor{comment}{    ***************************/}
119         
120     double ( *TILE\_A )[nt][TILE\_SIZE * TILE\_SIZE] = malloc ( mt * nt * 
121         TILE\_SIZE * TILE\_SIZE * \textcolor{keyword}{sizeof}( \textcolor{keywordtype}{double} ) );
122     
123     \textcolor{keywordflow}{if} ( TILE\_A == NULL )
124     \{
125         fprintf( stderr, \textcolor{stringliteral}{"Failure in kdnpgetrf for matrix TILE\_A\(\backslash\)n"} );
126         \textcolor{keywordflow}{return} NoSuccess;
127     \}
128 
129     ipiv\_local = ( \textcolor{keywordtype}{int}* ) malloc( MIN( M, N ) * \textcolor{keyword}{sizeof}( int ) );
130     
131     \textcolor{keywordflow}{if} ( ipiv\_local == NULL )
132     \{
133         fprintf( stderr, \textcolor{stringliteral}{"Failure in kdnpgetrf for ipiv\_local\(\backslash\)n"} );
134         \textcolor{keywordflow}{return} NoSuccess;
135     \}
136 
137     \textcolor{comment}{/************************************************}
138 \textcolor{comment}{    // --From flat data layout to tiled data layout--   }
139 \textcolor{comment}{    ************************************************/}
140     
141     \hyperlink{ddss__flat2tiled_8c_ab411e9b05a203c7905f0285ef4200a9e}{ddss\_dflat2tiled}( M, N, A, LDA, mt, nt, TILE\_A );
142 
143     \textcolor{comment}{/****************}
144 \textcolor{comment}{    --DGETRF tile--}
145 \textcolor{comment}{    ****************/}   
146     
147     current\_position = 0;
148     i = 0;
149     \textcolor{keywordflow}{for} ( ki = 0; ki < MIN( mt, nt ); ki++ )
150     \{
151         tile\_size\_km = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( M, ki );
152         tile\_size\_kn = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ki );
153         
154 \textcolor{preprocessor}{        #pragma oss task inout( TILE\_A[ki][ki] ) \(\backslash\)}
155 \textcolor{preprocessor}{            inout( ipiv\_local ) \(\backslash\)}
156 \textcolor{preprocessor}{            inout( current\_position ) \(\backslash\)}
157 \textcolor{preprocessor}{            out( local\_ipiv\_size ) \(\backslash\)}
158 \textcolor{preprocessor}{            shared( TILE\_A ) \(\backslash\)}
159 \textcolor{preprocessor}{            firstprivate( ki, i ) \(\backslash\)}
160 \textcolor{preprocessor}{            label( dgetrf )}
161         \{
162             LAPACKE\_dgetrf( CblasRowMajor,
163                             tile\_size\_km, tile\_size\_kn, 
164                             TILE\_A[ki][ki], tile\_size\_kn,
165                             ipiv\_local + current\_position );
166             
167             \textcolor{comment}{// Update the global ipiv array}
168             local\_ipiv\_size = MIN( tile\_size\_km, tile\_size\_kn );
169             \textcolor{keywordflow}{for} ( i = 0; i < local\_ipiv\_size; i++ )
170             \{
171                 ( IPIV + current\_position )[i] =
172                         ( ipiv\_local + current\_position )[i] + current\_position;
173             \}
174             current\_position += local\_ipiv\_size;
175         \}
176         \textcolor{keywordflow}{for} ( mi = ki + 1; mi < mt; mi++ )
177         \{
178             tile\_size\_m = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( M, mi );
179 
180 \textcolor{preprocessor}{            #pragma oss task in( TILE\_A[ki][ki] ) \(\backslash\)}
181 \textcolor{preprocessor}{                inout( TILE\_A[mi][ki] ) \(\backslash\)}
182 \textcolor{preprocessor}{                shared( TILE\_A ) \(\backslash\)}
183 \textcolor{preprocessor}{                firstprivate( mi, ki ) \(\backslash\)}
184 \textcolor{preprocessor}{                label( dtrsm\_below )}
185             cblas\_dtrsm( CblasRowMajor, 
186                          ( CBLAS\_SIDE ) Right, ( CBLAS\_UPLO ) Upper, 
187                          ( CBLAS\_TRANSPOSE ) NoTrans, ( CBLAS\_DIAG ) NonUnit, 
188                          tile\_size\_m, tile\_size\_kn, 
189                          1.0, TILE\_A[ki][ki], tile\_size\_kn, 
190                               TILE\_A[mi][ki], tile\_size\_kn );
191         \}
192         \textcolor{keywordflow}{for} ( ni = 0; ni < ki; ni++ )
193         \{       
194             tile\_size\_n = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ni );
195             \textcolor{comment}{// Swap the tiles to the left of A[ki][ki]}
196 \textcolor{preprocessor}{            #pragma oss task in( ipiv\_local ) \(\backslash\)}
197 \textcolor{preprocessor}{                in( current\_position ) \(\backslash\)}
198 \textcolor{preprocessor}{                in( local\_ipiv\_size ) \(\backslash\)}
199 \textcolor{preprocessor}{                inout( TILE\_A[ki][ni] ) \(\backslash\)}
200 \textcolor{preprocessor}{                shared( TILE\_A ) \(\backslash\)}
201 \textcolor{preprocessor}{                firstprivate( ki, ni ) \(\backslash\)}
202 \textcolor{preprocessor}{                label( dlaswp\_left )}
203             LAPACKE\_dlaswp( CblasRowMajor,
204                             tile\_size\_n, TILE\_A[ki][ni], tile\_size\_n,
205                             1, local\_ipiv\_size,
206                             ipiv\_local + current\_position - local\_ipiv\_size, 
207                             1 );
208             
209         \}
210         \textcolor{keywordflow}{for} ( ni = ki + 1; ni < nt; ni++ )
211         \{
212             tile\_size\_n = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ni );
213             \textcolor{comment}{// Swap the tiles to the right of A[ki][ki]}
214 \textcolor{preprocessor}{            #pragma oss task in( ipiv\_local ) \(\backslash\)}
215 \textcolor{preprocessor}{                in( current\_position ) \(\backslash\)}
216 \textcolor{preprocessor}{                in( local\_ipiv\_size ) \(\backslash\)}
217 \textcolor{preprocessor}{                inout( TILE\_A[ki][ni] ) \(\backslash\)}
218 \textcolor{preprocessor}{                shared( TILE\_A ) \(\backslash\)}
219 \textcolor{preprocessor}{                firstprivate( ki, ni ) \(\backslash\)}
220 \textcolor{preprocessor}{                label( dlaswp\_right )}
221             LAPACKE\_dlaswp( CblasRowMajor,
222                             tile\_size\_n, TILE\_A[ki][ni], tile\_size\_n,
223                             1, local\_ipiv\_size,
224                             ipiv\_local + current\_position - local\_ipiv\_size, 
225                             1 );
226 
227 \textcolor{preprocessor}{            #pragma oss task in( TILE\_A[ki][ki] ) \(\backslash\)}
228 \textcolor{preprocessor}{                inout( TILE\_A[ki][ni] ) \(\backslash\)}
229 \textcolor{preprocessor}{                shared( TILE\_A ) \(\backslash\)}
230 \textcolor{preprocessor}{                firstprivate( ni, ki ) \(\backslash\)}
231 \textcolor{preprocessor}{                label( dtrsm\_right )}
232             cblas\_dtrsm( CblasRowMajor, 
233                          ( CBLAS\_SIDE ) Left, ( CBLAS\_UPLO ) Lower, 
234                          ( CBLAS\_TRANSPOSE ) NoTrans, ( CBLAS\_DIAG ) Unit, 
235                          tile\_size\_km, tile\_size\_n, 
236                          1.0, TILE\_A[ki][ki], tile\_size\_kn, 
237                               TILE\_A[ki][ni], tile\_size\_n );
238                 
239             \textcolor{keywordflow}{for} ( mmi = ki + 1; mmi < mt; mmi++ )
240             \{
241                 tile\_size\_mm = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( M, mmi );
242         
243 \textcolor{preprocessor}{                #pragma oss task in( TILE\_A[mmi][ki] ) \(\backslash\)}
244 \textcolor{preprocessor}{                    in( TILE\_A[ki][ni] ) \(\backslash\)}
245 \textcolor{preprocessor}{                    inout( TILE\_A[mmi][ni] ) \(\backslash\)}
246 \textcolor{preprocessor}{                    shared( TILE\_A ) \(\backslash\)}
247 \textcolor{preprocessor}{                    firstprivate( ni, mmi, ki ) \(\backslash\)}
248 \textcolor{preprocessor}{                    label( dgemm )}
249                 cblas\_dgemm( CblasRowMajor, 
250                              ( CBLAS\_TRANSPOSE ) NoTrans,
251                              ( CBLAS\_TRANSPOSE ) NoTrans,
252                              tile\_size\_mm, 
253                              tile\_size\_n, 
254                              TILE\_SIZE,
255                              -1.0, TILE\_A[mmi][ki], tile\_size\_kn,
256                                    TILE\_A[ki][ni],  tile\_size\_n,
257                               1.0, TILE\_A[mmi][ni], tile\_size\_n );          
258             \}
259         \}
260     \}
261         
262     \textcolor{comment}{// --From tile data layout to flat data layout--    }
263     \hyperlink{ddss__tiled2flat_8c_aeeb6b69c6b4db8333c660ef6824cdf6a}{ddss\_dtiled2flat}( M, N, A, LDA, mt, nt, TILE\_A );
264 
265     \textcolor{comment}{// --Free--}
266     free( TILE\_A );
267     free( ipiv\_local );
268     
269     \textcolor{keywordflow}{return} Success;
270 
271 \}
\end{DoxyCode}
