\hypertarget{kdnpgesv_8c}{}\section{src/kdnpgesv.c File Reference}
\label{kdnpgesv_8c}\index{src/kdnpgesv.\+c@{src/kdnpgesv.\+c}}


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


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


\subsection{Detailed Description}
L\+A\+Ss-\/\+D\+D\+Ss kdnpgesv 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} 
\end{DoxyAuthor}
\begin{DoxyDate}{Date}
2018-\/07-\/26   
\end{DoxyDate}


\subsection{Function Documentation}
\index{kdnpgesv.\+c@{kdnpgesv.\+c}!kdnpgesv@{kdnpgesv}}
\index{kdnpgesv@{kdnpgesv}!kdnpgesv.\+c@{kdnpgesv.\+c}}
\subsubsection[{\texorpdfstring{kdnpgesv(int N, int N\+R\+H\+S, double $\ast$\+A, int L\+D\+A, double $\ast$\+B, int L\+D\+B)}{kdnpgesv(int N, int NRHS, double *A, int LDA, double *B, int LDB)}}]{\setlength{\rightskip}{0pt plus 5cm}enum L\+A\+S\+S\+\_\+\+R\+E\+T\+U\+RN kdnpgesv (
\begin{DoxyParamCaption}
\item[{int}]{N, }
\item[{int}]{N\+R\+HS, }
\item[{double $\ast$}]{A, }
\item[{int}]{L\+DA, }
\item[{double $\ast$}]{B, }
\item[{int}]{L\+DB}
\end{DoxyParamCaption}
)}\hypertarget{kdnpgesv_8c_a4ca30528b6350dafb182059e8ef46a97}{}\label{kdnpgesv_8c_a4ca30528b6350dafb182059e8ef46a97}
Solves a system of linear equations A  X = B, where A is a N-\/by-\/N general matrix and X and B are N-\/by-\/\+N\+R\+HS matrices. The matrix A is factorized using the LU descomposition without pivoting. The matrix A is descomposed as\+: \begin{DoxyVerb}A = L * U
\end{DoxyVerb}


where L is a lower triangular matrix with unit diagonal elements and U is an upper triangular matrix.


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em N} & int. N specifies the order of the square matrix A. N $>$= 0.\\
\hline
\end{DoxyParams}
N\+R\+HS int. N\+R\+HS specifies the number of right-\/hand-\/sides (number of columns of B). N\+R\+HS $>$= 0.


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em A} & double $\ast$. A is a pointer to a regular matrix of dimension N-\/by-\/\+L\+DA. 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 in,out}  & {\em B} & double $\ast$. B is a pointer to a matrix of dimension N by N\+R\+HS, which stores the right-\/hand-\/sides of the systems of linear equations. (row-\/major order). On exit, if return value is Success, the matrix B is overwriten by the solution matrix X.\\
\hline
\mbox{\tt in}  & {\em L\+DB} & int. L\+DB specifies the number of columns of B ( row-\/major order ). L\+DB must be at least max( 1, N\+R\+H\+S ).\\
\hline
\end{DoxyParams}

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

ddss\+\_\+tile 

ddss\+\_\+flat2tiled 

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


Definition at line 86 of file kdnpgesv.\+c.



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



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


\begin{DoxyCode}
89 \{
90 
91     \textcolor{comment}{// Local variables}
92     \textcolor{keywordtype}{int} nt, nrhst;
93     \textcolor{keywordtype}{int} mi, mmi, ki, ni, nni;
94     \textcolor{keywordtype}{int} tile\_size\_m;
95     \textcolor{keywordtype}{int} tile\_size\_mm;
96     \textcolor{keywordtype}{int} tile\_size\_n;
97     \textcolor{keywordtype}{int} tile\_size\_nn;
98     \textcolor{keywordtype}{int} tile\_size\_k;
99 
100     \textcolor{comment}{// Number of tiles}
101     \textcolor{keywordflow}{if} ( N % TILE\_SIZE == 0 )
102     \{
103         nt = N / TILE\_SIZE;
104     \}
105     \textcolor{keywordflow}{else}
106     \{
107         nt = ( N / TILE\_SIZE ) + 1;
108     \}
109 
110     \textcolor{keywordflow}{if} ( NRHS % TILE\_SIZE == 0 )
111     \{
112         nrhst = NRHS / TILE\_SIZE;
113     \}
114     \textcolor{keywordflow}{else}
115     \{
116         nrhst = ( NRHS / TILE\_SIZE ) + 1;
117     \}
118 
119     \textcolor{comment}{/***************************}
120 \textcolor{comment}{    --Tile matrices allocation--}
121 \textcolor{comment}{    ***************************/}
122         
123     double (*TILE\_A)[nt][TILE\_SIZE * TILE\_SIZE] = malloc ( nt * nt * 
124         TILE\_SIZE * TILE\_SIZE * \textcolor{keyword}{sizeof}( \textcolor{keywordtype}{double} ) );
125     
126     \textcolor{keywordflow}{if} ( TILE\_A == NULL )
127     \{
128         fprintf( stderr, \textcolor{stringliteral}{"Failure in kdnpgesv for matrix TILE\_A\(\backslash\)n"} );
129         \textcolor{keywordflow}{return} NoSuccess;
130     \}
131     
132     double ( *TILE\_B )[nrhst][TILE\_SIZE * TILE\_SIZE] = malloc(
133              nt * nrhst * TILE\_SIZE * TILE\_SIZE * \textcolor{keyword}{sizeof}( \textcolor{keywordtype}{double} ) );
134 
135     \textcolor{keywordflow}{if} ( TILE\_B == NULL ) 
136     \{
137         fprintf( stderr, \textcolor{stringliteral}{"Failure in kdnpgesv for matrix TILE\_B\(\backslash\)n"} );
138         \textcolor{keywordflow}{return} NoSuccess;
139     \}
140     
141     \textcolor{comment}{/************************************************}
142 \textcolor{comment}{    // --From flat data layout to tiled data layout--   }
143 \textcolor{comment}{    ************************************************/}
144 
145     \textcolor{comment}{// From flat matrix A to tile matrix TILE\_A}
146     \hyperlink{ddss__flat2tiled_8c_ab411e9b05a203c7905f0285ef4200a9e}{ddss\_dflat2tiled}( N, N, A, LDA, nt, nt, TILE\_A );
147     
148     \textcolor{comment}{// From flat matrix B to tile matrix TILE\_B }
149     \hyperlink{ddss__flat2tiled_8c_ab411e9b05a203c7905f0285ef4200a9e}{ddss\_dflat2tiled}( N, NRHS, B, LDB, nt, nrhst, TILE\_B );
150 
151     \textcolor{comment}{/****************}
152 \textcolor{comment}{    --DNPGESV tile--}
153 \textcolor{comment}{    ****************/}   
154 
155     \textcolor{comment}{// LU descomposition without pivoting}
156     \textcolor{keywordflow}{for} ( ki = 0; ki < nt; ki++ )
157     \{
158         tile\_size\_k = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ki );
159         
160 \textcolor{preprocessor}{        #if defined(LASs\_WITH\_MKL)}
161         
162 \textcolor{preprocessor}{        #pragma oss task inout( TILE\_A[ki][ki] ) \(\backslash\)}
163 \textcolor{preprocessor}{                shared( TILE\_A ) \(\backslash\)}
164 \textcolor{preprocessor}{                firstprivate( ki ) \(\backslash\)}
165 \textcolor{preprocessor}{                label( mkl\_dgetrfnpi )}
166         LAPACKE\_mkl\_dgetrfnpi( CblasRowMajor,
167                                tile\_size\_k, tile\_size\_k,
168                                tile\_size\_k,
169                                TILE\_A[ki][ki], tile\_size\_k );
170 
171 \textcolor{preprocessor}{        #else}
172 
173 \textcolor{preprocessor}{        #pragma oss task inout( TILE\_A[ki][ki] ) \(\backslash\)}
174 \textcolor{preprocessor}{                shared( TILE\_A ) \(\backslash\)}
175 \textcolor{preprocessor}{                firstprivate( ki ) \(\backslash\)}
176 \textcolor{preprocessor}{                label( dnpgetrf )}
177         \hyperlink{dnpgetrf_8c_a90f43bdc154edb1979f7ffce22e142ff}{dnpgetrf}( tile\_size\_k, tile\_size\_k,
178                   TILE\_A[ki][ki],
179                   tile\_size\_k );
180 
181 \textcolor{preprocessor}{        #endif}
182             
183         \textcolor{keywordflow}{for} ( mi = ki + 1; mi < nt; mi++ )
184         \{
185             tile\_size\_m = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, mi );
186             
187 \textcolor{preprocessor}{            #pragma oss task in( TILE\_A[ki][ki] ) \(\backslash\)}
188 \textcolor{preprocessor}{                    inout(TILE\_A[mi][ki]) \(\backslash\)}
189 \textcolor{preprocessor}{                    shared( TILE\_A ) \(\backslash\)}
190 \textcolor{preprocessor}{                    firstprivate( mi, ki ) \(\backslash\)}
191 \textcolor{preprocessor}{                    label( dnpgetrf\_dtrsm\_below )}
192             cblas\_dtrsm( CblasRowMajor, 
193                          ( CBLAS\_SIDE ) Right, ( CBLAS\_UPLO ) Upper, 
194                          ( CBLAS\_TRANSPOSE ) NoTrans, ( CBLAS\_DIAG ) NonUnit, 
195                          tile\_size\_m, tile\_size\_k, 
196                          1.0, TILE\_A[ki][ki], tile\_size\_k, 
197                               TILE\_A[mi][ki], tile\_size\_k );
198         \}
199         \textcolor{keywordflow}{for} ( ni = ki + 1; ni < nt; ni++ )
200         \{
201             tile\_size\_n = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ni );
202             
203 \textcolor{preprocessor}{            #pragma oss task in( TILE\_A[ki][ki] ) \(\backslash\)}
204 \textcolor{preprocessor}{                    inout(TILE\_A[ki][ni]) \(\backslash\)}
205 \textcolor{preprocessor}{                    shared( TILE\_A ) \(\backslash\)}
206 \textcolor{preprocessor}{                    firstprivate( ni, ki ) \(\backslash\)}
207 \textcolor{preprocessor}{                    label( dnpgetrf\_dtrsm\_right )}
208             cblas\_dtrsm( CblasRowMajor, 
209                          ( CBLAS\_SIDE ) Left, ( CBLAS\_UPLO ) Lower, 
210                          ( CBLAS\_TRANSPOSE ) NoTrans, ( CBLAS\_DIAG ) Unit, 
211                          tile\_size\_k, tile\_size\_n, 
212                          1.0, TILE\_A[ki][ki], tile\_size\_k, 
213                               TILE\_A[ki][ni], tile\_size\_n );
214             
215             \textcolor{keywordflow}{for} ( mmi = ki + 1; mmi < nt; mmi++ )
216             \{
217                 tile\_size\_mm = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, mmi );
218                                 
219 \textcolor{preprocessor}{                #pragma oss task in( TILE\_A[mmi][ki] ) \(\backslash\)}
220 \textcolor{preprocessor}{                        in( TILE\_A[ki][ni] ) \(\backslash\)}
221 \textcolor{preprocessor}{                        inout( TILE\_A[mmi][ni] ) \(\backslash\)}
222 \textcolor{preprocessor}{                        shared( TILE\_A ) \(\backslash\)}
223 \textcolor{preprocessor}{                        firstprivate( ni, mmi, ki ) \(\backslash\)}
224 \textcolor{preprocessor}{                        label( dnpgetrf\_dgemm )}
225                 cblas\_dgemm( CblasRowMajor, 
226                              ( CBLAS\_TRANSPOSE ) NoTrans,
227                              ( CBLAS\_TRANSPOSE ) NoTrans,
228                              tile\_size\_mm, 
229                              tile\_size\_n, 
230                              TILE\_SIZE,
231                              -1.0, TILE\_A[mmi][ki], tile\_size\_k,
232                                    TILE\_A[ki][ni],  tile\_size\_n,
233                               1.0, TILE\_A[mmi][ni], tile\_size\_n );
234             \}
235         \}
236     \}
237     
238     \textcolor{comment}{/*********************************************}
239 \textcolor{comment}{    --From tiled data layout to flat data layout--  }
240 \textcolor{comment}{    *********************************************/}
241     \hyperlink{ddss__tiled2flat_8c_adb1f9312d77184467236d25bc73f21b0}{ddss\_dtiled2flat\_nb}( N, N, A, LDA, nt, nt, TILE\_A );
242 
243     \textcolor{comment}{// Triandular solve}
244     \textcolor{comment}{// --SIDE = Left & UPLO = Lower & TRANS\_A = NoTrans & Unit-- }
245     \textcolor{keywordflow}{for} ( ki = 0; ki < nt; ki++ )
246     \{
247         tile\_size\_k = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ki );
248 
249         \textcolor{keywordflow}{for} ( ni = 0; ni < nrhst; ni++ )
250         \{
251             tile\_size\_n = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( NRHS, ni );
252                         
253 \textcolor{preprocessor}{            #pragma oss task in( TILE\_A[ki][ki] ) \(\backslash\)}
254 \textcolor{preprocessor}{                inout(  TILE\_B[ki][ni] ) \(\backslash\)}
255 \textcolor{preprocessor}{                shared( TILE\_A, TILE\_B ) \(\backslash\)}
256 \textcolor{preprocessor}{                firstprivate( ki, ni ) \(\backslash\)}
257 \textcolor{preprocessor}{                label( dtrsm\_dtrsm1 )}
258             cblas\_dtrsm( CblasRowMajor,
259                          ( CBLAS\_SIDE ) Left, ( CBLAS\_UPLO ) Lower,
260                          ( CBLAS\_TRANSPOSE ) NoTrans,
261                          ( CBLAS\_DIAG ) Unit,
262                          tile\_size\_k,
263                          tile\_size\_n,
264                          1.0, TILE\_A[ki][ki], tile\_size\_k,
265                               TILE\_B[ki][ni], tile\_size\_n );
266         \}
267         \textcolor{keywordflow}{for} ( nni = 0; nni < nrhst; nni++ ) 
268         \{
269             tile\_size\_nn = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( NRHS, nni );
270                 
271             \textcolor{keywordflow}{for} ( mi = ki + 1; mi < nt; mi++ )
272             \{
273                     
274 \textcolor{preprocessor}{                #pragma oss task in( TILE\_A[mi][ki] ) \(\backslash\)}
275 \textcolor{preprocessor}{                    in( TILE\_B[ki][nni] ) \(\backslash\)}
276 \textcolor{preprocessor}{                    inout( TILE\_B[mi][nni] ) \(\backslash\)}
277 \textcolor{preprocessor}{                    shared( TILE\_A, TILE\_B ) \(\backslash\)}
278 \textcolor{preprocessor}{                    firstprivate( ki, mi, nni ) \(\backslash\)}
279 \textcolor{preprocessor}{                    label( dtrsm\_dgemm1 )}
280                 cblas\_dgemm( CblasRowMajor,
281                              CblasNoTrans, CblasNoTrans,
282                              tile\_size\_k,
283                              tile\_size\_nn,
284                              tile\_size\_k,
285                              -1.0,  TILE\_A[mi][ki],  tile\_size\_k,
286                                    TILE\_B[ki][nni], tile\_size\_nn,
287                               1.0, TILE\_B[mi][nni], tile\_size\_nn );
288             \}
289         \}
290     \}
291 
292     \textcolor{comment}{// Triandular solve}
293     \textcolor{comment}{// --SIDE = Left & UPLO = Upper & TRANS\_A = NoTrans & NonUnit--}
294     \textcolor{keywordflow}{for} ( ki = nt - 1; ki >= 0; ki-- ) 
295     \{
296         tile\_size\_k = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, ki );
297         
298         \textcolor{keywordflow}{for} ( ni = 0; ni < nrhst; ni++ ) 
299         \{
300             tile\_size\_n = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( NRHS, ni );
301 
302 \textcolor{preprocessor}{            #pragma oss task in( TILE\_A[ki][ki] ) \(\backslash\)}
303 \textcolor{preprocessor}{                inout( TILE\_B[ki][ni] ) \(\backslash\)}
304 \textcolor{preprocessor}{                shared( TILE\_A, TILE\_B ) \(\backslash\)}
305 \textcolor{preprocessor}{                firstprivate( ki, ni ) \(\backslash\)}
306 \textcolor{preprocessor}{                label( dtrsmi\_dtrsm2 )}
307             cblas\_dtrsm( CblasRowMajor,
308                          ( CBLAS\_SIDE ) Left, ( CBLAS\_UPLO ) Upper,
309                          ( CBLAS\_TRANSPOSE ) NoTrans,
310                          ( CBLAS\_DIAG ) NonUnit,
311                          tile\_size\_k, 
312                          tile\_size\_n,
313                          1.0, TILE\_A[ki][ki], tile\_size\_k,
314                               TILE\_B[ki][ni], tile\_size\_n );
315         \}
316 
317         \textcolor{keywordflow}{for} ( mi = ki - 1; mi >= 0; mi-- ) 
318         \{
319             tile\_size\_m = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( N, mi );
320             
321             \textcolor{keywordflow}{for} ( nni = 0; nni < nrhst; nni++ ) 
322             \{
323                 tile\_size\_nn = \hyperlink{ddss__tile_8c_a931442adba78807015ff9a076fb2ae49}{ddss\_tile\_size}( NRHS, nni );
324 
325 \textcolor{preprocessor}{                #pragma oss task in( TILE\_A[mi][ki] ) \(\backslash\)}
326 \textcolor{preprocessor}{                    in( TILE\_B[ki][nni] ) \(\backslash\)}
327 \textcolor{preprocessor}{                    inout( TILE\_B[mi][nni] ) \(\backslash\)}
328 \textcolor{preprocessor}{                    shared( TILE\_A, TILE\_B ) \(\backslash\)}
329 \textcolor{preprocessor}{                    firstprivate( ki, mi, nni ) \(\backslash\)}
330 \textcolor{preprocessor}{                    label( dtrsm\_dgemm2 )}
331                 cblas\_dgemm( CblasRowMajor,
332                              CblasNoTrans, CblasNoTrans,
333                              tile\_size\_m, 
334                              tile\_size\_nn, 
335                              tile\_size\_k,
336                              -1.0, TILE\_A[mi][ki],  tile\_size\_k,
337                                    TILE\_B[ki][nni], tile\_size\_nn,
338                               1.0, TILE\_B[mi][nni], tile\_size\_nn );
339             \}
340         \}
341     \}
342 
343     \textcolor{comment}{/*********************************************}
344 \textcolor{comment}{    --From tiled data layout to flat data layout--  }
345 \textcolor{comment}{    *********************************************/}
346     \hyperlink{ddss__tiled2flat_8c_aeeb6b69c6b4db8333c660ef6824cdf6a}{ddss\_dtiled2flat}( N, NRHS, B, LDB, nt, nrhst, TILE\_B );
347     
348     \textcolor{comment}{// --Tile A and B matrices free--}
349     free( TILE\_A );
350     free( TILE\_B );
351     
352     \textcolor{keywordflow}{return} Success;
353 
354 \}
\end{DoxyCode}
