lapack_int LAPACKE_zhprfs( int matrix_layout, char uplo, lapack_int n, lapack_int nrhs, const lapack_complex_double* ap, const lapack_complex_double* afp, const lapack_int* ipiv, const lapack_complex_double* b, lapack_int ldb, lapack_complex_double* x, lapack_int ldx, double* ferr, double* berr ) { lapack_int info = 0; double* rwork = NULL; lapack_complex_double* work = NULL; if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_zhprfs", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK /* Optionally check input matrices for NaNs */ if( LAPACKE_zhp_nancheck( n, afp ) ) { return -6; } if( LAPACKE_zhp_nancheck( n, ap ) ) { return -5; } if( LAPACKE_zge_nancheck( matrix_layout, n, nrhs, b, ldb ) ) { return -8; } if( LAPACKE_zge_nancheck( matrix_layout, n, nrhs, x, ldx ) ) { return -10; } #endif /* Allocate memory for working array(s) */ rwork = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,n) ); if( rwork == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_0; } work = (lapack_complex_double*) LAPACKE_malloc( sizeof(lapack_complex_double) * MAX(1,2*n) ); if( work == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_1; } /* Call middle-level interface */ info = LAPACKE_zhprfs_work( matrix_layout, uplo, n, nrhs, ap, afp, ipiv, 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_zhprfs", info ); } return info; }
int main(void) { /* Local scalars */ char uplo, uplo_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 */ lapack_complex_double *ap = NULL, *ap_i = NULL; lapack_complex_double *afp = NULL, *afp_i = NULL; lapack_int *ipiv = NULL, *ipiv_i = NULL; lapack_complex_double *b = NULL, *b_i = NULL; lapack_complex_double *x = NULL, *x_i = NULL; double *ferr = NULL, *ferr_i = NULL; double *berr = NULL, *berr_i = NULL; lapack_complex_double *work = NULL, *work_i = NULL; double *rwork = NULL, *rwork_i = NULL; lapack_complex_double *x_save = NULL; double *ferr_save = NULL; double *berr_save = NULL; lapack_complex_double *ap_r = NULL; lapack_complex_double *afp_r = NULL; lapack_complex_double *b_r = NULL; lapack_complex_double *x_r = NULL; /* Iniitialize the scalar parameters */ init_scalars_zhprfs( &uplo, &n, &nrhs, &ldb, &ldx ); ldb_r = nrhs+2; ldx_r = nrhs+2; uplo_i = uplo; n_i = n; nrhs_i = nrhs; ldb_i = ldb; ldx_i = ldx; /* Allocate memory for the LAPACK routine arrays */ ap = (lapack_complex_double *) LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) ); afp = (lapack_complex_double *) LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) ); ipiv = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) ); b = (lapack_complex_double *) LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) ); x = (lapack_complex_double *) LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_double) ); ferr = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); berr = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); work = (lapack_complex_double *) LAPACKE_malloc( 2*n * sizeof(lapack_complex_double) ); rwork = (double *)LAPACKE_malloc( n * sizeof(double) ); /* Allocate memory for the C interface function arrays */ ap_i = (lapack_complex_double *) LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) ); afp_i = (lapack_complex_double *) LAPACKE_malloc( ((n*(n+1)/2)) * sizeof(lapack_complex_double) ); ipiv_i = (lapack_int *)LAPACKE_malloc( n * sizeof(lapack_int) ); b_i = (lapack_complex_double *) LAPACKE_malloc( ldb*nrhs * sizeof(lapack_complex_double) ); x_i = (lapack_complex_double *) LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_double) ); ferr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); berr_i = (double *)LAPACKE_malloc( nrhs * sizeof(double) ); work_i = (lapack_complex_double *) LAPACKE_malloc( 2*n * sizeof(lapack_complex_double) ); rwork_i = (double *)LAPACKE_malloc( n * sizeof(double) ); /* Allocate memory for the backup arrays */ x_save = (lapack_complex_double *) LAPACKE_malloc( ldx*nrhs * sizeof(lapack_complex_double) ); 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 = (lapack_complex_double *) LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) ); afp_r = (lapack_complex_double *) LAPACKE_malloc( n*(n+1)/2 * sizeof(lapack_complex_double) ); b_r = (lapack_complex_double *) LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) ); x_r = (lapack_complex_double *) LAPACKE_malloc( n*(nrhs+2) * sizeof(lapack_complex_double) ); /* Initialize input arrays */ init_ap( (n*(n+1)/2), ap ); init_afp( (n*(n+1)/2), afp ); init_ipiv( n, ipiv ); 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 < ldx*nrhs; i++ ) { x_save[i] = x[i]; } 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 */ zhprfs_( &uplo, &n, &nrhs, ap, afp, ipiv, 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 < (n*(n+1)/2); i++ ) { ap_i[i] = ap[i]; } for( i = 0; i < (n*(n+1)/2); i++ ) { afp_i[i] = afp[i]; } for( i = 0; i < n; i++ ) { ipiv_i[i] = ipiv[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x_save[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_zhprfs_work( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i, afp_i, ipiv_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i, work_i, rwork_i ); failed = compare_zhprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i, ldx, nrhs ); if( failed == 0 ) { printf( "PASSED: column-major middle-level interface to zhprfs\n" ); } else { printf( "FAILED: column-major middle-level interface to zhprfs\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 < (n*(n+1)/2); i++ ) { afp_i[i] = afp[i]; } for( i = 0; i < n; i++ ) { ipiv_i[i] = ipiv[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x_save[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_zhprfs( LAPACK_COL_MAJOR, uplo_i, n_i, nrhs_i, ap_i, afp_i, ipiv_i, b_i, ldb_i, x_i, ldx_i, ferr_i, berr_i ); failed = compare_zhprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i, ldx, nrhs ); if( failed == 0 ) { printf( "PASSED: column-major high-level interface to zhprfs\n" ); } else { printf( "FAILED: column-major high-level interface to zhprfs\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 < (n*(n+1)/2); i++ ) { afp_i[i] = afp[i]; } for( i = 0; i < n; i++ ) { ipiv_i[i] = ipiv[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x_save[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_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r ); LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, afp_i, afp_r ); LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 ); LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 ); info_i = LAPACKE_zhprfs_work( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r, afp_r, ipiv_i, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i, work_i, rwork_i ); LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, x_r, nrhs+2, x_i, ldx ); failed = compare_zhprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i, ldx, nrhs ); if( failed == 0 ) { printf( "PASSED: row-major middle-level interface to zhprfs\n" ); } else { printf( "FAILED: row-major middle-level interface to zhprfs\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 < (n*(n+1)/2); i++ ) { afp_i[i] = afp[i]; } for( i = 0; i < n; i++ ) { ipiv_i[i] = ipiv[i]; } for( i = 0; i < ldb*nrhs; i++ ) { b_i[i] = b[i]; } for( i = 0; i < ldx*nrhs; i++ ) { x_i[i] = x_save[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_zpp_trans( LAPACK_COL_MAJOR, uplo, n, ap_i, ap_r ); LAPACKE_zpp_trans( LAPACK_COL_MAJOR, uplo, n, afp_i, afp_r ); LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, b_i, ldb, b_r, nrhs+2 ); LAPACKE_zge_trans( LAPACK_COL_MAJOR, n, nrhs, x_i, ldx, x_r, nrhs+2 ); info_i = LAPACKE_zhprfs( LAPACK_ROW_MAJOR, uplo_i, n_i, nrhs_i, ap_r, afp_r, ipiv_i, b_r, ldb_r, x_r, ldx_r, ferr_i, berr_i ); LAPACKE_zge_trans( LAPACK_ROW_MAJOR, n, nrhs, x_r, nrhs+2, x_i, ldx ); failed = compare_zhprfs( x, x_i, ferr, ferr_i, berr, berr_i, info, info_i, ldx, nrhs ); if( failed == 0 ) { printf( "PASSED: row-major high-level interface to zhprfs\n" ); } else { printf( "FAILED: row-major high-level interface to zhprfs\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( afp != NULL ) { LAPACKE_free( afp ); } if( afp_i != NULL ) { LAPACKE_free( afp_i ); } if( afp_r != NULL ) { LAPACKE_free( afp_r ); } if( ipiv != NULL ) { LAPACKE_free( ipiv ); } if( ipiv_i != NULL ) { LAPACKE_free( ipiv_i ); } 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( x_save != NULL ) { LAPACKE_free( x_save ); } 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; }