lapack_int LAPACKE_ctrrfs( int matrix_order, char uplo, char trans, char diag, lapack_int n, lapack_int nrhs, const lapack_complex_float* a, lapack_int lda, const lapack_complex_float* b, lapack_int ldb, const lapack_complex_float* x, lapack_int ldx, float* ferr, float* berr ) { lapack_int info = 0; float* rwork = NULL; lapack_complex_float* work = NULL; if( matrix_order != LAPACK_COL_MAJOR && matrix_order != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_ctrrfs", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK /* Optionally check input matrices for NaNs */ if( LAPACKE_ctr_nancheck( matrix_order, uplo, diag, n, a, lda ) ) { return -7; } if( LAPACKE_cge_nancheck( matrix_order, n, nrhs, b, ldb ) ) { return -9; } if( LAPACKE_cge_nancheck( matrix_order, n, nrhs, x, ldx ) ) { return -11; } #endif /* Allocate memory for working array(s) */ rwork = (float*)LAPACKE_malloc( sizeof(float) * MAX(1,n) ); if( rwork == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_0; } work = (lapack_complex_float*) LAPACKE_malloc( sizeof(lapack_complex_float) * MAX(1,2*n) ); if( work == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_1; } /* Call middle-level interface */ info = LAPACKE_ctrrfs_work( matrix_order, uplo, trans, diag, n, nrhs, a, lda, b, ldb, x, ldx, ferr, berr, work, rwork ); /* Release memory and exit */ LAPACKE_free( work ); exit_level_1: LAPACKE_free( rwork ); exit_level_0: if( info == LAPACK_WORK_MEMORY_ERROR ) { LAPACKE_xerbla( "LAPACKE_ctrrfs", info ); } return info; }
int main(void) { /* Local scalars */ char uplo, uplo_i; char trans, trans_i; char diag, diag_i; lapack_int n, n_i; lapack_int nrhs, nrhs_i; lapack_int lda, lda_i; lapack_int lda_r; lapack_int ldb, ldb_i; lapack_int ldb_r; lapack_int ldx, ldx_i; lapack_int ldx_r; lapack_int info, info_i; lapack_int i; int failed; /* Local arrays */ lapack_complex_float *a = NULL, *a_i = NULL; lapack_complex_float *b = NULL, *b_i = NULL; lapack_complex_float *x = NULL, *x_i = NULL; float *ferr = NULL, *ferr_i = NULL; float *berr = NULL, *berr_i = NULL; lapack_complex_float *work = NULL, *work_i = NULL; float *rwork = NULL, *rwork_i = NULL; float *ferr_save = NULL; float *berr_save = NULL; lapack_complex_float *a_r = NULL; lapack_complex_float *b_r = NULL; lapack_complex_float *x_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_ctrrfs( &uplo, &trans, &diag, &n, &nrhs, &lda, &ldb, &ldx ); lda_r = n+2; ldb_r = nrhs+2; ldx_r = nrhs+2; uplo_i = uplo; trans_i = trans; diag_i = diag; n_i = n; nrhs_i = nrhs; lda_i = lda; ldb_i = ldb; ldx_i = ldx; /* Allocate memory for the LAPACK routine arrays */ a = (lapack_complex_float *) LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) ); b = (lapack_complex_float *) LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) ); x = (lapack_complex_float *) LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_float) ); ferr = (float *)LAPACKE_malloc( nrhs * sizeof(float) ); berr = (float *)LAPACKE_malloc( nrhs * sizeof(float) ); work = (lapack_complex_float *) LAPACKE_malloc( 2*n * sizeof(lapack_complex_float) ); rwork = (float *)LAPACKE_malloc( n * sizeof(float) ); /* Allocate memory for the C interface function arrays */ a_i = (lapack_complex_float *) LAPACKE_malloc( lda*n * sizeof(lapack_complex_float) ); b_i = (lapack_complex_float *) LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_float) ); x_i = (lapack_complex_float *) LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_float) ); ferr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) ); berr_i = (float *)LAPACKE_malloc( nrhs * sizeof(float) ); work_i = (lapack_complex_float *) LAPACKE_malloc( 2*n * sizeof(lapack_complex_float) ); rwork_i = (float *)LAPACKE_malloc( n * sizeof(float) ); /* Allocate memory for the backup arrays */ ferr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) ); berr_save = (float *)LAPACKE_malloc( nrhs * sizeof(float) ); /* Allocate memory for the row-major arrays */ a_r = (lapack_complex_float *) LAPACKE_malloc( n*(n+2) * sizeof(lapack_complex_float) ); b_r = (lapack_complex_float *) LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) ); x_r = (lapack_complex_float *) LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_float) ); /* Initialize input arrays */ init_a( lda*n, a ); init_b( ldb*nrhs, b ); init_x( ldx*nrhs, x ); init_ferr( nrhs, ferr ); init_berr( nrhs, berr ); init_work( 2*n, work ); init_rwork( n, rwork ); /* Backup the ouptut arrays */ for( i = 0; i < nrhs; i++ ) { ferr_save[i] = ferr[i]; } for( i = 0; i < nrhs; i++ ) { berr_save[i] = berr[i]; } /* Call the LAPACK routine */ ctrrfs_( &uplo, &trans, &diag, &n, &nrhs, a, &lda, b, &ldb, x, &ldx, ferr, berr, work, rwork, &info ); /* Initialize input data, call the column-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x[i]; } for( i = 0; i < nrhs; i++ ) { ferr_i[i] = ferr_save[i]; } for( i = 0; i < nrhs; i++ ) { berr_i[i] = berr_save[i]; } for( i = 0; i < 2*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { rwork_i[i] = rwork[i]; } info_i = LAPACKE_ctrrfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, a_i, lda_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i, work_i, rwork_i ); failed = compare_ctrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to ctrrfs\n" ); } else { printf( "FAILED: column-major middle-level interface to ctrrfs\n" ); } /* Initialize input data, call the column-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x[i]; } for( i = 0; i < nrhs; i++ ) { ferr_i[i] = ferr_save[i]; } for( i = 0; i < nrhs; i++ ) { berr_i[i] = berr_save[i]; } for( i = 0; i < 2*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { rwork_i[i] = rwork[i]; } info_i = LAPACKE_ctrrfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, a_i, lda_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i ); failed = compare_ctrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to ctrrfs\n" ); } else { printf( "FAILED: column-major high-level interface to ctrrfs\n" ); } /* Initialize input data, call the row-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x[i]; } for( i = 0; i < nrhs; i++ ) { ferr_i[i] = ferr_save[i]; } for( i = 0; i < nrhs; i++ ) { berr_i[i] = berr_save[i]; } for( i = 0; i < 2*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { rwork_i[i] = rwork[i]; } LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 ); LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 ); LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 ); info_i = LAPACKE_ctrrfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, a_r, lda_r, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i, work_i, rwork_i ); failed = compare_ctrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to ctrrfs\n" ); } else { printf( "FAILED: row-major middle-level interface to ctrrfs\n" ); } /* Initialize input data, call the row-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < lda*n; i++ ) { a_i[i] = a[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x[i]; } for( i = 0; i < nrhs; i++ ) { ferr_i[i] = ferr_save[i]; } for( i = 0; i < nrhs; i++ ) { berr_i[i] = berr_save[i]; } for( i = 0; i < 2*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { rwork_i[i] = rwork[i]; } /* Init row_major arrays */ LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, n, a_i, lda, a_r, n+2 ); LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 ); LAPACKE_cge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 ); info_i = LAPACKE_ctrrfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, a_r, lda_r, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i ); failed = compare_ctrrfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to ctrrfs\n" ); } else { printf( "FAILED: row-major high-level interface to ctrrfs\n" ); } /* Release memory */ if( a != NULL ) { LAPACKE_free( a ); } if( a_i != NULL ) { LAPACKE_free( a_i ); } if( a_r != NULL ) { LAPACKE_free( a_r ); } if( b != NULL ) { LAPACKE_free( b ); } if( b_i != NULL ) { LAPACKE_free( b_i ); } if( b_r != NULL ) { LAPACKE_free( b_r ); } if( x != NULL ) { LAPACKE_free( x ); } if( x_i != NULL ) { LAPACKE_free( x_i ); } if( x_r != NULL ) { LAPACKE_free( x_r ); } if( ferr != NULL ) { LAPACKE_free( ferr ); } if( ferr_i != NULL ) { LAPACKE_free( ferr_i ); } if( ferr_save != NULL ) { LAPACKE_free( ferr_save ); } if( berr != NULL ) { LAPACKE_free( berr ); } if( berr_i != NULL ) { LAPACKE_free( berr_i ); } if( berr_save != NULL ) { LAPACKE_free( berr_save ); } if( work != NULL ) { LAPACKE_free( work ); } if( work_i != NULL ) { LAPACKE_free( work_i ); } if( rwork != NULL ) { LAPACKE_free( rwork ); } if( rwork_i != NULL ) { LAPACKE_free( rwork_i ); } return 0; }