lapack_int LAPACKE_dtprfs( int matrix_order, char uplo, char trans, char diag, lapack_int n, lapack_int nrhs, const double* ap, const double* b, lapack_int ldb, const double* x, lapack_int ldx, double* ferr, double* berr ) { lapack_int info = 0; lapack_int* iwork = NULL; double* work = NULL; if( matrix_order != LAPACK_COL_MAJOR && matrix_order != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_dtprfs", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK /* Optionally check input matrices for NaNs */ if( LAPACKE_dtp_nancheck( matrix_order, uplo, diag, n, ap ) ) { return -7; } if( LAPACKE_dge_nancheck( matrix_order, n, nrhs, b, ldb ) ) { return -8; } if( LAPACKE_dge_nancheck( matrix_order, n, nrhs, x, ldx ) ) { return -10; } #endif /* Allocate memory for working array(s) */ iwork = (lapack_int*)LAPACKE_malloc( sizeof(lapack_int) * MAX(1,n) ); if( iwork == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_0; } work = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,3*n) ); if( work == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_1; } /* Call middle-level interface */ info = LAPACKE_dtprfs_work( matrix_order, uplo, trans, diag, n, nrhs, ap, b, ldb, x, ldx, ferr, berr, work, iwork ); /* Release memory and exit */ LAPACKE_free( work ); exit_level_1: LAPACKE_free( iwork ); exit_level_0: if( info == LAPACK_WORK_MEMORY_ERROR ) { LAPACKE_xerbla( "LAPACKE_dtprfs", 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 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 */ double *ap = NULL, *ap_i = NULL; double *b = NULL, *b_i = NULL; double *x = NULL, *x_i = NULL; double *ferr = NULL, *ferr_i = NULL; double *berr = NULL, *berr_i = NULL; double *work = NULL, *work_i = NULL; lapack_int *iwork = NULL, *iwork_i = NULL; double *ferr_save = NULL; double *berr_save = NULL; double *ap_r = NULL; double *b_r = NULL; double *x_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_dtprfs( &uplo, &trans, &diag, &n, &nrhs, &ldb, &ldx ); ldb_r = nrhs+2; ldx_r = nrhs+2; uplo_i = uplo; trans_i = trans; diag_i = diag; n_i = n; nrhs_i = nrhs; ldb_i = ldb; ldx_i = ldx; /* Allocate memory for the LAPACK routine arrays */ ap = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) ); b = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) ); x = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) ); ferr = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); berr = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); work = (double *)LAPACKE_malloc( 3*n * sizeof(double) ); iwork = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) ); /* Allocate memory for the C interface function arrays */ ap_i = (double *)LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(double) ); b_i = (double *)LAPACKE_malloc( ldb*nrhs * sizeof(double) ); x_i = (double *)LAPACKE_malloc( ldx*nrhs * sizeof(double) ); ferr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); berr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); work_i = (double *)LAPACKE_malloc( 3*n * sizeof(double) ); iwork_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) ); /* Allocate memory for the backup arrays */ ferr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); berr_save = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); /* Allocate memory for the row-major arrays */ ap_r = (double *)LAPACKE_malloc( n*(n+1)/2 * sizeof(double) ); b_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) ); x_r = (double *)LAPACKE_malloc( n*(nrhs+2) * sizeof(double) ); /* Initialize input arrays */ init_ap( (n*(n+1)/2), ap ); init_b( ldb*nrhs, b ); init_x( ldx*nrhs, x ); init_ferr( nrhs, ferr ); init_berr( nrhs, berr ); init_work( 3*n, work ); init_iwork( n, iwork ); /* 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 */ dtprfs_( &uplo, &trans, &diag, &n, &nrhs, ap, b, &ldb, x, &ldx, ferr, berr, work, iwork, &info ); /* Initialize input data, call the column-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < (n*(n+1)/2); i++ ) { ap_i[i] = ap[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 < 3*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { iwork_i[i] = iwork[i]; } info_i = LAPACKE_dtprfs_work( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, ap_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i, work_i, iwork_i ); failed = compare_dtprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to dtprfs\n" ); } else { printf( "FAILED: column-major middle-level interface to dtprfs\n" ); } /* Initialize input data, call the column-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < (n*(n+1)/2); i++ ) { ap_i[i] = ap[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 < 3*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { iwork_i[i] = iwork[i]; } info_i = LAPACKE_dtprfs( LAPACK_COL_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, ap_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i ); failed = compare_dtprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to dtprfs\n" ); } else { printf( "FAILED: column-major high-level interface to dtprfs\n" ); } /* Initialize input data, call the row-major middle-level * interface to LAPACK routine and check the results */ for( i = 0; i < (n*(n+1)/2); i++ ) { ap_i[i] = ap[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 < 3*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { iwork_i[i] = iwork[i]; } LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r ); LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 ); LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 ); info_i = LAPACKE_dtprfs_work( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, ap_r, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i, work_i, iwork_i ); failed = compare_dtprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to dtprfs\n" ); } else { printf( "FAILED: row-major middle-level interface to dtprfs\n" ); } /* Initialize input data, call the row-major high-level * interface to LAPACK routine and check the results */ for( i = 0; i < (n*(n+1)/2); i++ ) { ap_i[i] = ap[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 < 3*n; i++ ) { work_i[i] = work[i]; } for( i = 0; i < n; i++ ) { iwork_i[i] = iwork[i]; } /* Init row_major arrays */ LAPACKE_dpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r ); LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 ); LAPACKE_dge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 ); info_i = LAPACKE_dtprfs( LAPACK_ROW_MAJOR, uplo_i, trans_i, diag_i, n_i, nrhs_i, ap_r, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i ); failed = compare_dtprfs( ferr, ferr_i, berr, berr_i, info, info_i, nrhs ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to dtprfs\n" ); } else { printf( "FAILED: row-major high-level interface to dtprfs\n" ); } /* Release memory */ if( ap != NULL ) { LAPACKE_free( ap ); } if( ap_i != NULL ) { LAPACKE_free( ap_i ); } if( ap_r != NULL ) { LAPACKE_free( ap_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( iwork != NULL ) { LAPACKE_free( iwork ); } if( iwork_i != NULL ) { LAPACKE_free( iwork_i ); } return 0; }