Skip to content

LAPACKE: don't allocate transposed matrix in ?lantr_work #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions LAPACKE/src/lapacke_clantr_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,46 @@ float LAPACKE_clantr_work( int matrix_layout, char norm, char uplo,
lapack_int info = 0;
float res = 0.;
if( matrix_layout == LAPACK_COL_MAJOR ) {
/* Call LAPACK function and adjust info */
/* Call LAPACK function */
res = LAPACK_clantr( &norm, &uplo, &diag, &m, &n, a, &lda, work );
} else if( matrix_layout == LAPACK_ROW_MAJOR ) {
lapack_int lda_t = MAX(1,m);
lapack_complex_float* a_t = NULL;
float* work_lapack = NULL;
char norm_lapack;
char uplo_lapack;
/* Check leading dimension(s) */
if( lda < n ) {
info = -8;
LAPACKE_xerbla( "LAPACKE_clantr_work", info );
return info;
}
/* Allocate memory for temporary array(s) */
a_t = (lapack_complex_float*)
LAPACKE_malloc( sizeof(lapack_complex_float) * lda_t * MAX(1,MAX(m,n)) );
if( a_t == NULL ) {
info = LAPACK_TRANSPOSE_MEMORY_ERROR;
goto exit_level_0;
if( LAPACKE_lsame( norm, '1' ) || LAPACKE_lsame( norm, 'o' ) ) {
norm_lapack = 'i';
} else if( LAPACKE_lsame( norm, 'i' ) ) {
norm_lapack = '1';
} else {
norm_lapack = norm;
}
if( LAPACKE_lsame( uplo, 'u' ) ) {
uplo_lapack = 'l';
} else {
uplo_lapack = 'u';
}
/* Allocate memory for work array(s) */
if( LAPACKE_lsame( norm, 'i' ) ) {
work_lapack = (float*)LAPACKE_malloc( sizeof(float) * MAX(1,m) );
if( LAPACKE_lsame( norm_lapack, 'i' ) ) {
work_lapack = (float*)LAPACKE_malloc( sizeof(float) * MAX(1,n) );
if( work_lapack == NULL ) {
info = LAPACK_WORK_MEMORY_ERROR;
goto exit_level_1;
goto exit_level_0;
}
}
/* Transpose input matrices */
LAPACKE_ctr_trans( matrix_layout, uplo, diag, MAX(m,n), a, lda, a_t, lda_t );
/* Call LAPACK function and adjust info */
res = LAPACK_clantr( &norm, &uplo, &diag, &m, &n, a_t, &lda_t, work_lapack );
/* Call LAPACK function */
res = LAPACK_clantr( &norm_lapack, &uplo_lapack, &diag, &n, &m, a, &lda, work_lapack );
/* Release memory and exit */
if( work_lapack ) {
LAPACKE_free( work_lapack );
}
exit_level_1:
LAPACKE_free( a_t );
exit_level_0:
if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
if( info == LAPACK_WORK_MEMORY_ERROR ) {
LAPACKE_xerbla( "LAPACKE_clantr_work", info );
}
} else {
Expand Down
38 changes: 20 additions & 18 deletions LAPACKE/src/lapacke_dlantr_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,46 @@ double LAPACKE_dlantr_work( int matrix_layout, char norm, char uplo,
lapack_int info = 0;
double res = 0.;
if( matrix_layout == LAPACK_COL_MAJOR ) {
/* Call LAPACK function and adjust info */
/* Call LAPACK function */
res = LAPACK_dlantr( &norm, &uplo, &diag, &m, &n, a, &lda, work );
} else if( matrix_layout == LAPACK_ROW_MAJOR ) {
lapack_int lda_t = MAX(1,m);
double* a_t = NULL;
double* work_lapack = NULL;
char norm_lapack;
char uplo_lapack;
/* Check leading dimension(s) */
if( lda < n ) {
info = -8;
LAPACKE_xerbla( "LAPACKE_dlantr_work", info );
return info;
}
/* Allocate memory for temporary array(s) */
a_t = (double*)LAPACKE_malloc( sizeof(double) * lda_t * MAX(1,MAX(m,n)) );
if( a_t == NULL ) {
info = LAPACK_TRANSPOSE_MEMORY_ERROR;
goto exit_level_0;
if( LAPACKE_lsame( norm, '1' ) || LAPACKE_lsame( norm, 'o' ) ) {
norm_lapack = 'i';
} else if( LAPACKE_lsame( norm, 'i' ) ) {
norm_lapack = '1';
} else {
norm_lapack = norm;
}
if( LAPACKE_lsame( uplo, 'u' ) ) {
uplo_lapack = 'l';
} else {
uplo_lapack = 'u';
}
/* Allocate memory for work array(s) */
if( LAPACKE_lsame( norm, 'i' ) ) {
work_lapack = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,m) );
if( LAPACKE_lsame( norm_lapack, 'i' ) ) {
work_lapack = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,n) );
if( work_lapack == NULL ) {
info = LAPACK_WORK_MEMORY_ERROR;
goto exit_level_1;
goto exit_level_0;
}
}
/* Transpose input matrices */
LAPACKE_dtr_trans( matrix_layout, uplo, diag, MAX(m,n), a, lda, a_t, lda_t );
/* Call LAPACK function and adjust info */
res = LAPACK_dlantr( &norm, &uplo, &diag, &m, &n, a_t, &lda_t, work_lapack );
/* Call LAPACK function */
res = LAPACK_dlantr( &norm_lapack, &uplo_lapack, &diag, &n, &m, a, &lda, work_lapack );
/* Release memory and exit */
if( work_lapack ) {
LAPACKE_free( work_lapack );
}
exit_level_1:
LAPACKE_free( a_t );
exit_level_0:
if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
if( info == LAPACK_WORK_MEMORY_ERROR ) {
LAPACKE_xerbla( "LAPACKE_dlantr_work", info );
}
} else {
Expand Down
38 changes: 20 additions & 18 deletions LAPACKE/src/lapacke_slantr_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,46 @@ float LAPACKE_slantr_work( int matrix_layout, char norm, char uplo,
lapack_int info = 0;
float res = 0.;
if( matrix_layout == LAPACK_COL_MAJOR ) {
/* Call LAPACK function and adjust info */
/* Call LAPACK function */
res = LAPACK_slantr( &norm, &uplo, &diag, &m, &n, a, &lda, work );
} else if( matrix_layout == LAPACK_ROW_MAJOR ) {
lapack_int lda_t = MAX(1,m);
float* a_t = NULL;
float* work_lapack = NULL;
char norm_lapack;
char uplo_lapack;
/* Check leading dimension(s) */
if( lda < n ) {
info = -8;
LAPACKE_xerbla( "LAPACKE_slantr_work", info );
return info;
}
/* Allocate memory for temporary array(s) */
a_t = (float*)LAPACKE_malloc( sizeof(float) * lda_t * MAX(1,MAX(m,n)) );
if( a_t == NULL ) {
info = LAPACK_TRANSPOSE_MEMORY_ERROR;
goto exit_level_0;
if( LAPACKE_lsame( norm, '1' ) || LAPACKE_lsame( norm, 'o' ) ) {
norm_lapack = 'i';
} else if( LAPACKE_lsame( norm, 'i' ) ) {
norm_lapack = '1';
} else {
norm_lapack = norm;
}
if( LAPACKE_lsame( uplo, 'u' ) ) {
uplo_lapack = 'l';
} else {
uplo_lapack = 'u';
}
/* Allocate memory for work array(s) */
if( LAPACKE_lsame( norm, 'i' ) ) {
work_lapack = (float*)LAPACKE_malloc( sizeof(float) * MAX(1,m) );
if( LAPACKE_lsame( norm_lapack, 'i' ) ) {
work_lapack = (float*)LAPACKE_malloc( sizeof(float) * MAX(1,n) );
if( work_lapack == NULL ) {
info = LAPACK_WORK_MEMORY_ERROR;
goto exit_level_1;
goto exit_level_0;
}
}
/* Transpose input matrices */
LAPACKE_str_trans( matrix_layout, uplo, diag, MAX(m,n), a, lda, a_t, lda_t );
/* Call LAPACK function and adjust info */
res = LAPACK_slantr( &norm, &uplo, &diag, &m, &n, a_t, &lda_t, work_lapack );
/* Call LAPACK function */
res = LAPACK_slantr( &norm_lapack, &uplo_lapack, &diag, &n, &m, a, &lda, work_lapack );
/* Release memory and exit */
if( work_lapack ) {
LAPACKE_free( work_lapack );
}
exit_level_1:
LAPACKE_free( a_t );
exit_level_0:
if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
if( info == LAPACK_WORK_MEMORY_ERROR ) {
LAPACKE_xerbla( "LAPACKE_slantr_work", info );
}
} else {
Expand Down
39 changes: 20 additions & 19 deletions LAPACKE/src/lapacke_zlantr_work.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,45 +41,46 @@ double LAPACKE_zlantr_work( int matrix_layout, char norm, char uplo,
lapack_int info = 0;
double res = 0.;
if( matrix_layout == LAPACK_COL_MAJOR ) {
/* Call LAPACK function and adjust info */
/* Call LAPACK function */
res = LAPACK_zlantr( &norm, &uplo, &diag, &m, &n, a, &lda, work );
} else if( matrix_layout == LAPACK_ROW_MAJOR ) {
lapack_int lda_t = MAX(1,m);
lapack_complex_double* a_t = NULL;
double* work_lapack = NULL;
char norm_lapack;
char uplo_lapack;
/* Check leading dimension(s) */
if( lda < n ) {
info = -8;
LAPACKE_xerbla( "LAPACKE_zlantr_work", info );
return info;
}
/* Allocate memory for temporary array(s) */
a_t = (lapack_complex_double*)
LAPACKE_malloc( sizeof(lapack_complex_double) * lda_t * MAX(1,MAX(m,n)) );
if( a_t == NULL ) {
info = LAPACK_TRANSPOSE_MEMORY_ERROR;
goto exit_level_0;
if( LAPACKE_lsame( norm, '1' ) || LAPACKE_lsame( norm, 'o' ) ) {
norm_lapack = 'i';
} else if( LAPACKE_lsame( norm, 'i' ) ) {
norm_lapack = '1';
} else {
norm_lapack = norm;
}
if( LAPACKE_lsame( uplo, 'u' ) ) {
uplo_lapack = 'l';
} else {
uplo_lapack = 'u';
}
/* Allocate memory for work array(s) */
if( LAPACKE_lsame( norm, 'i' ) ) {
work_lapack = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,m) );
if( LAPACKE_lsame( norm_lapack, 'i' ) ) {
work_lapack = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,n) );
if( work_lapack == NULL ) {
info = LAPACK_WORK_MEMORY_ERROR;
goto exit_level_1;
goto exit_level_0;
}
}
/* Transpose input matrices */
LAPACKE_ztr_trans( matrix_layout, uplo, diag, MAX(m,n), a, lda, a_t, lda_t );
/* Call LAPACK function and adjust info */
res = LAPACK_zlantr( &norm, &uplo, &diag, &m, &n, a_t, &lda_t, work_lapack );
/* Call LAPACK function */
res = LAPACK_zlantr( &norm_lapack, &uplo_lapack, &diag, &n, &m, a, &lda, work_lapack );
/* Release memory and exit */
if( work_lapack ) {
LAPACKE_free( work_lapack );
}
exit_level_1:
LAPACKE_free( a_t );
exit_level_0:
if( info == LAPACK_TRANSPOSE_MEMORY_ERROR ) {
if( info == LAPACK_WORK_MEMORY_ERROR ) {
LAPACKE_xerbla( "LAPACKE_zlantr_work", info );
}
} else {
Expand Down