int main ( ) /******************************************************************************/ /* Purpose: D_SAMPLE_ST tests the SUPERLU solver with a 5x5 double precision real matrix. Discussion: The general (GE) representation of the matrix is: [ 19 0 21 21 0 12 21 0 0 0 0 12 16 0 0 0 0 0 5 21 12 12 0 0 18 ] The (0-based) compressed column (CC) representation of this matrix is: I CC A -- -- -- 0 0 19 1 12 4 12 1 3 21 2 12 4 12 0 6 21 2 16 0 8 21 3 5 3 10 21 4 18 * 12 * The right hand side B and solution X are # B X -- -- ---------- 0 1 -0.03125 1 1 0.0654762 2 1 0.0133929 3 1 0.0625 4 1 0.0327381 Licensing: This code is distributed under the GNU LGPL license. Modified: 18 July 2014 Author: John Burkardt Reference: James Demmel, John Gilbert, Xiaoye Li, SuperLU Users's Guide. */ { SuperMatrix A; double *acc; double *b; double *b2; SuperMatrix B; int *ccc; int i; int *icc; int info; int j; SuperMatrix L; int m; int n; int nrhs = 1; int ncc; superlu_options_t options; int *perm_c; int permc_spec; int *perm_r; SuperLUStat_t stat; SuperMatrix U; timestamp ( ); printf ( "\n" ); printf ( "D_SAMPLE_ST:\n" ); printf ( " C version\n" ); printf ( " SUPERLU solves a double precision real linear system.\n" ); printf ( " The matrix is read from a Sparse Triplet (ST) file.\n" ); /* Read the matrix from a file associated with standard input, in sparse triplet (ST) format, into compressed column (CC) format. */ dreadtriple ( &m, &n, &ncc, &acc, &icc, &ccc ); /* Print the matrix. */ cc_print ( m, n, ncc, icc, ccc, acc, " CC Matrix:" ); /* Convert the compressed column (CC) matrix into a SuperMatrix A. */ dCreate_CompCol_Matrix ( &A, m, n, ncc, acc, icc, ccc, SLU_NC, SLU_D, SLU_GE ); /* Create the right-hand side matrix. */ b = ( double * ) malloc ( m * sizeof ( double ) ); for ( i = 0; i < m; i++ ) { b[i] = 1.0; } printf ( "\n" ); printf ( " Right hand side:\n" ); printf ( "\n" ); for ( i = 0; i < m; i++ ) { printf ( "%g\n", b[i] ); } /* Create Super Right Hand Side. */ dCreate_Dense_Matrix ( &B, m, nrhs, b, m, SLU_DN, SLU_D, SLU_GE ); /* Set space for the permutations. */ perm_r = ( int * ) malloc ( m * sizeof ( int ) ); perm_c = ( int * ) malloc ( n * sizeof ( int ) ); /* Set the input options. */ set_default_options ( &options ); options.ColPerm = NATURAL; /* Initialize the statistics variables. */ StatInit ( &stat ); /* Solve the linear system. */ dgssv ( &options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info ); dPrint_CompCol_Matrix ( ( char * ) "A", &A ); dPrint_CompCol_Matrix ( ( char * ) "U", &U ); dPrint_SuperNode_Matrix ( ( char * ) "L", &L ); print_int_vec ( ( char * ) "\nperm_r", m, perm_r ); /* By some miracle involving addresses, the solution has been put into the B vector. */ printf ( "\n" ); printf ( " Computed solution:\n" ); printf ( "\n" ); for ( i = 0; i < m; i++ ) { printf ( "%g\n", b[i] ); } /* Demonstrate that RHS is really the solution now. Multiply it by the matrix. */ b2 = cc_mv ( m, n, ncc, icc, ccc, acc, b ); printf ( "\n" ); printf ( " Product A*X:\n" ); printf ( "\n" ); for ( i = 0; i < m; i++ ) { printf ( "%g\n", b2[i] ); } /* Free memory. */ free ( b ); free ( b2 ); free ( perm_c ); free ( perm_r ); Destroy_SuperMatrix_Store ( &A ); Destroy_SuperMatrix_Store ( &B ); Destroy_SuperNode_Matrix ( &L ); Destroy_CompCol_Matrix ( &U ); StatFree ( &stat ); /* Terminate. */ printf ( "\n" ); printf ( "D_SAMPLE_ST:\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; }
void c_fortran_dgssv_(int *iopt, int *n, int *nnz, int *nrhs, double *values, int *rowind, int *colptr, double *b, int *ldb, fptr *f_factors, /* a handle containing the address pointing to the factored matrices */ int *info) { /* * This routine can be called from Fortran. * * iopt (input) int * Specifies the operation: * = 1, performs LU decomposition for the first time * = 2, performs triangular solve * = 3, free all the storage in the end * * f_factors (input/output) fptr* * If iopt == 1, it is an output and contains the pointer pointing to * the structure of the factored matrices. * Otherwise, it it an input. * */ SuperMatrix A, AC, B; SuperMatrix *L, *U; int *perm_r; /* row permutations from partial pivoting */ int *perm_c; /* column permutation vector */ int *etree; /* column elimination tree */ SCformat *Lstore; NCformat *Ustore; int i, panel_size, permc_spec, relax; trans_t trans; double drop_tol = 0.0; mem_usage_t mem_usage; superlu_options_t options; SuperLUStat_t stat; factors_t *LUfactors; trans = NOTRANS; if ( *iopt == 1 ) { /* LU decomposition */ /* Set the default input options. */ set_default_options(&options); /* Initialize the statistics variables. */ StatInit(&stat); /* Adjust to 0-based indexing */ for (i = 0; i < *nnz; ++i) --rowind[i]; for (i = 0; i <= *n; ++i) --colptr[i]; dCreate_CompCol_Matrix(&A, *n, *n, *nnz, values, rowind, colptr, SLU_NC, SLU_D, SLU_GE); L = (SuperMatrix *) SUPERLU_MALLOC( sizeof(SuperMatrix) ); U = (SuperMatrix *) SUPERLU_MALLOC( sizeof(SuperMatrix) ); if ( !(perm_r = intMalloc(*n)) ) ABORT("Malloc fails for perm_r[]."); if ( !(perm_c = intMalloc(*n)) ) ABORT("Malloc fails for perm_c[]."); if ( !(etree = intMalloc(*n)) ) ABORT("Malloc fails for etree[]."); /* * Get column permutation vector perm_c[], according to permc_spec: * permc_spec = 0: natural ordering * permc_spec = 1: minimum degree on structure of A'*A * permc_spec = 2: minimum degree on structure of A'+A * permc_spec = 3: approximate minimum degree for unsymmetric matrices */ permc_spec = options.ColPerm; get_perm_c(permc_spec, &A, perm_c); sp_preorder(&options, &A, perm_c, etree, &AC); panel_size = sp_ienv(1); relax = sp_ienv(2); dgstrf(&options, &AC, drop_tol, relax, panel_size, etree, NULL, 0, perm_c, perm_r, L, U, &stat, info); if ( *info == 0 ) { Lstore = (SCformat *) L->Store; Ustore = (NCformat *) U->Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz); dQuerySpace(L, U, &mem_usage); printf("L\\U MB %.3f\ttotal MB needed %.3f\texpansions %d\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6, mem_usage.expansions); } else { printf("dgstrf() error returns INFO= %d\n", *info); if ( *info <= *n ) { /* factorization completes */ dQuerySpace(L, U, &mem_usage); printf("L\\U MB %.3f\ttotal MB needed %.3f\texpansions %d\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6, mem_usage.expansions); } } /* Restore to 1-based indexing */ for (i = 0; i < *nnz; ++i) ++rowind[i]; for (i = 0; i <= *n; ++i) ++colptr[i]; /* Save the LU factors in the factors handle */ LUfactors = (factors_t*) SUPERLU_MALLOC(sizeof(factors_t)); LUfactors->L = L; LUfactors->U = U; LUfactors->perm_c = perm_c; LUfactors->perm_r = perm_r; *f_factors = (fptr) LUfactors; /* Free un-wanted storage */ SUPERLU_FREE(etree); Destroy_SuperMatrix_Store(&A); Destroy_CompCol_Permuted(&AC); StatFree(&stat); } else if ( *iopt == 2 ) { /* Triangular solve */ /* Initialize the statistics variables. */ StatInit(&stat); /* Extract the LU factors in the factors handle */ LUfactors = (factors_t*) *f_factors; L = LUfactors->L; U = LUfactors->U; perm_c = LUfactors->perm_c; perm_r = LUfactors->perm_r; dCreate_Dense_Matrix(&B, *n, *nrhs, b, *ldb, SLU_DN, SLU_D, SLU_GE); /* Solve the system A*X=B, overwriting B with X. */ dgstrs (trans, L, U, perm_c, perm_r, &B, &stat, info); Destroy_SuperMatrix_Store(&B); StatFree(&stat); } else if ( *iopt == 3 ) { /* Free storage */ /* Free the LU factors in the factors handle */ LUfactors = (factors_t*) *f_factors; SUPERLU_FREE (LUfactors->perm_r); SUPERLU_FREE (LUfactors->perm_c); Destroy_SuperNode_Matrix(LUfactors->L); Destroy_CompCol_Matrix(LUfactors->U); SUPERLU_FREE (LUfactors->L); SUPERLU_FREE (LUfactors->U); SUPERLU_FREE (LUfactors); } else { fprintf(stderr,"Invalid iopt=%d passed to c_fortran_dgssv()\n",*iopt); exit(-1); } }
int main(void) { plan(60); /* lowercase */ char test[100]; ok(lc(NULL) == NULL, "lc(NULL)"); strcpy(test, "Yes"); like(lc(test), "yes", "lc(yes)"); strcpy(test, "YES"); like(lc(test), "yes", "lc(YES)"); strcpy(test, "yeS"); like(lc(test), "yes", "lc(yeS)"); /* trim */ strcpy(test, " text "); like(ltrim(test), "text ", "ltrim()"); strcpy(test, " text "); like(rtrim(test), " text", "rtrim()"); strcpy(test, " text "); like(trim(test), "text", "trim()"); char *test2; test2 = strdup(" text "); like(trim(test2), "text", "trim()"); free(test2); /* parse_yes_or_no */ ok(parse_yes_or_no(NULL, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 1"); ok(parse_yes_or_no(NULL, GM_DISABLED) == GM_DISABLED, "parse_yes_or_no 2"); strcpy(test, ""); ok(parse_yes_or_no(test, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 3"); strcpy(test, ""); ok(parse_yes_or_no(test, GM_DISABLED) == GM_DISABLED, "parse_yes_or_no 4"); strcpy(test, "yes"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 5"); strcpy(test, "true"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 6"); strcpy(test, "Yes"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 7"); strcpy(test, "1"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 8"); strcpy(test, "On"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_ENABLED, "parse_yes_or_no 9"); strcpy(test, "Off"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_DISABLED, "parse_yes_or_no 10"); strcpy(test, "false"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_DISABLED, "parse_yes_or_no 11"); strcpy(test, "no"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_DISABLED, "parse_yes_or_no 12"); strcpy(test, "0"); ok(parse_yes_or_no(test, GM_ENABLED) == GM_DISABLED, "parse_yes_or_no 13"); /* trim */ ok(trim(NULL) == NULL, "trim(NULL)"); strcpy(test, " test "); like(trim(test), "^test$", "trim(' test ')"); strcpy(test, "\ntest\n"); like(trim(test), "^test$", "trim('\\ntest\\n')"); /* reading keys */ mod_gm_opt_t *mod_gm_opt; mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); int rc = set_default_options(mod_gm_opt); ok(rc == 0, "setting default options"); mod_gm_opt->keyfile = strdup("t/data/test1.key"); read_keyfile(mod_gm_opt); //printf_hex(mod_gm_opt->crypt_key, 32); test[0]='\x0'; int i = 0; char hex[4]; for(i=0; i<32; i++) { hex[0] = '\x0'; snprintf(hex, 4, "%02x", mod_gm_opt->crypt_key[i]); strncat(test, hex, 4); } like(test, "3131313131313131313131313131313131313131313131313131313131310000", "read keyfile t/data/test1.key"); free(mod_gm_opt->keyfile); mod_gm_opt->keyfile = strdup("t/data/test2.key"); read_keyfile(mod_gm_opt); like(mod_gm_opt->crypt_key, "abcdef", "reading keyfile t/data/test2.key"); free(mod_gm_opt->keyfile); mod_gm_opt->keyfile = strdup("t/data/test3.key"); read_keyfile(mod_gm_opt); //printf_hex(mod_gm_opt->crypt_key, 32); like(mod_gm_opt->crypt_key, "11111111111111111111111111111111", "reading keyfile t/data/test3.key"); ok(strlen(mod_gm_opt->crypt_key) == 32, "key size for t/data/test3.key"); /* encrypt */ char * key = "test1234"; char * encrypted = malloc(GM_BUFFERSIZE); char * text = "test message"; char * base = "a7HqhQEE8TQBde9uknpPYQ=="; mod_gm_crypt_init(key); int len; len = mod_gm_encrypt(&encrypted, text, GM_ENCODE_AND_ENCRYPT); ok(len == 24, "length of encrypted only"); like(encrypted, base, "encrypted string"); /* decrypt */ char * decrypted = malloc(GM_BUFFERSIZE); mod_gm_decrypt(&decrypted, encrypted, GM_ENCODE_AND_ENCRYPT); like(decrypted, text, "decrypted text"); free(decrypted); free(encrypted); /* base 64 */ char * base64 = malloc(GM_BUFFERSIZE); len = mod_gm_encrypt(&base64, text, GM_ENCODE_ONLY); ok(len == 16, "length of encode only"); like(base64, "dGVzdCBtZXNzYWdl", "base64 only string"); /* debase 64 */ char * debase64 = malloc(GM_BUFFERSIZE); mod_gm_decrypt(&debase64, base64, GM_ENCODE_ONLY); like(debase64, text, "debase64 text"); free(debase64); free(base64); /* file_exists */ ok(file_exists("01_utils") == 1, "file_exists('01_utils')"); ok(file_exists("non-exist") == 0, "file_exists('non-exist')"); /* nr2signal */ char * signame1 = nr2signal(9); like(signame1, "SIGKILL", "get SIGKILL for 9"); free(signame1); char * signame2 = nr2signal(15); like(signame2, "SIGTERM", "get SIGTERM for 15"); free(signame2); /* string2timeval */ struct timeval t; string2timeval("100.50", &t); ok(t.tv_sec == 100, "string2timeval 1"); ok(t.tv_usec == 50, "string2timeval 2"); string2timeval("100", &t); ok(t.tv_sec == 100, "string2timeval 3"); ok(t.tv_usec == 0, "string2timeval 4"); string2timeval("", &t); ok(t.tv_sec == 0, "string2timeval 5"); ok(t.tv_usec == 0, "string2timeval 6"); string2timeval(NULL, &t); ok(t.tv_sec == 0, "string2timeval 7"); ok(t.tv_usec == 0, "string2timeval 8"); /* command line parsing */ mod_gm_free_opt(mod_gm_opt); mod_gm_opt = renew_opts(); strcpy(test, "server=host:4730"); parse_args_line(mod_gm_opt, test, 0); like(mod_gm_opt->server_list[0], "host:4730", "server=host:4730"); ok(mod_gm_opt->server_num == 1, "server_number = %d", mod_gm_opt->server_num); mod_gm_free_opt(mod_gm_opt); mod_gm_opt = renew_opts(); strcpy(test, "server=:4730"); parse_args_line(mod_gm_opt, test, 0); like(mod_gm_opt->server_list[0], "localhost:4730", "server=:4730"); ok(mod_gm_opt->server_num == 1, "server_number = %d", mod_gm_opt->server_num); mod_gm_free_opt(mod_gm_opt); mod_gm_opt = renew_opts(); strcpy(test, "server=localhost:4730"); parse_args_line(mod_gm_opt, test, 0); strcpy(test, "server=localhost:4730"); parse_args_line(mod_gm_opt, test, 0); like(mod_gm_opt->server_list[0], "localhost:4730", "duplicate server"); ok(mod_gm_opt->server_num == 1, "server_number = %d", mod_gm_opt->server_num); mod_gm_free_opt(mod_gm_opt); mod_gm_opt = renew_opts(); strcpy(test, "server=localhost:4730,localhost:4730,:4730,host:4730,"); parse_args_line(mod_gm_opt, test, 0); like(mod_gm_opt->server_list[0], "localhost:4730", "duplicate server"); like(mod_gm_opt->server_list[1], "host:4730", "duplicate server"); ok(mod_gm_opt->server_num == 2, "server_number = %d", mod_gm_opt->server_num); /* escape newlines */ char * escaped = gm_escape_newlines(" test\n", GM_DISABLED); is(escaped, " test\\n", "untrimmed escape string"); free(escaped); escaped = gm_escape_newlines(" test\n", GM_ENABLED); is(escaped, "test", "trimmed escape string"); free(escaped); /* md5 sum */ char * sum = NULL; strcpy(test, ""); sum = md5sum(test); like(sum, "d41d8cd98f00b204e9800998ecf8427e", "md5sum()"); free(sum); strcpy(test, "The quick brown fox jumps over the lazy dog."); sum = md5sum(test); like(sum, "e4d909c290d0fb1ca068ffaddf22cbd0", "md5sum()"); free(sum); mod_gm_free_opt(mod_gm_opt); return exit_status(); }
main(int argc, char *argv[]) { SuperMatrix A; NCformat *Astore; doublecomplex *a; int *asub, *xa; int *perm_c; /* column permutation vector */ int *perm_r; /* row permutations from partial pivoting */ SuperMatrix L; /* factor L */ SCformat *Lstore; SuperMatrix U; /* factor U */ NCformat *Ustore; SuperMatrix B; int nrhs, ldx, info, m, n, nnz; doublecomplex *xact, *rhs; mem_usage_t mem_usage; superlu_options_t options; SuperLUStat_t stat; #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Enter main()"); #endif /* Set the default input options: options.Fact = DOFACT; options.Equil = YES; options.ColPerm = COLAMD; options.DiagPivotThresh = 1.0; options.Trans = NOTRANS; options.IterRefine = NOREFINE; options.SymmetricMode = NO; options.PivotGrowth = NO; options.ConditionNumber = NO; options.PrintStat = YES; */ set_default_options(&options); /* Now we modify the default options to use the symmetric mode. */ options.SymmetricMode = YES; options.ColPerm = MMD_AT_PLUS_A; options.DiagPivotThresh = 0.001; /* Read the matrix in Harwell-Boeing format. */ zreadhb(&m, &n, &nnz, &a, &asub, &xa); zCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_Z, SLU_GE); Astore = A.Store; printf("Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz); nrhs = 1; if ( !(rhs = doublecomplexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhs[]."); zCreate_Dense_Matrix(&B, m, nrhs, rhs, m, SLU_DN, SLU_Z, SLU_GE); xact = doublecomplexMalloc(n * nrhs); ldx = n; zGenXtrue(n, nrhs, xact, ldx); zFillRHS(options.Trans, nrhs, xact, ldx, &A, &B); if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[]."); if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[]."); /* Initialize the statistics variables. */ StatInit(&stat); zgssv(&options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info); if ( info == 0 ) { /* This is how you could access the solution matrix. */ doublecomplex *sol = (doublecomplex*) ((DNformat*) B.Store)->nzval; /* Compute the infinity norm of the error. */ zinf_norm_error(nrhs, &B, xact); Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); zQuerySpace(&L, &U, &mem_usage); printf("L\\U MB %.3f\ttotal MB needed %.3f\texpansions %d\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6, mem_usage.expansions); } else { printf("zgssv() error returns INFO= %d\n", info); if ( info <= n ) { /* factorization completes */ zQuerySpace(&L, &U, &mem_usage); printf("L\\U MB %.3f\ttotal MB needed %.3f\texpansions %d\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6, mem_usage.expansions); } } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); SUPERLU_FREE (rhs); SUPERLU_FREE (xact); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); Destroy_CompCol_Matrix(&A); Destroy_SuperMatrix_Store(&B); Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Exit main()"); #endif }
main(int argc, char *argv[]) { /* * Purpose * ======= * * The driver program ZLINSOLX1. * * This example illustrates how to use ZGSSVX to solve systems with the same * A but different right-hand side. * In this case, we factorize A only once in the first call to DGSSVX, * and reuse the following data structures in the subsequent call to ZGSSVX: * perm_c, perm_r, R, C, L, U. * */ char equed[1]; yes_no_t equil; trans_t trans; SuperMatrix A, L, U; SuperMatrix B, X; NCformat *Astore; NCformat *Ustore; SCformat *Lstore; doublecomplex *a; int *asub, *xa; int *perm_c; /* column permutation vector */ int *perm_r; /* row permutations from partial pivoting */ int *etree; void *work; int info, lwork, nrhs, ldx; int i, m, n, nnz; doublecomplex *rhsb, *rhsx, *xact; double *R, *C; double *ferr, *berr; double u, rpg, rcond; mem_usage_t mem_usage; superlu_options_t options; SuperLUStat_t stat; extern void parse_command_line(); #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Enter main()"); #endif /* Defaults */ lwork = 0; nrhs = 1; equil = YES; u = 1.0; trans = NOTRANS; /* Set the default values for options argument: options.Fact = DOFACT; options.Equil = YES; options.ColPerm = COLAMD; options.DiagPivotThresh = 1.0; options.Trans = NOTRANS; options.IterRefine = NOREFINE; options.SymmetricMode = NO; options.PivotGrowth = NO; options.ConditionNumber = NO; options.PrintStat = YES; */ set_default_options(&options); /* Can use command line input to modify the defaults. */ parse_command_line(argc, argv, &lwork, &u, &equil, &trans); options.Equil = equil; options.DiagPivotThresh = u; options.Trans = trans; if ( lwork > 0 ) { work = SUPERLU_MALLOC(lwork); if ( !work ) { ABORT("ZLINSOLX: cannot allocate work[]"); } } /* Read matrix A from a file in Harwell-Boeing format.*/ zreadhb(&m, &n, &nnz, &a, &asub, &xa); zCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_Z, SLU_GE); Astore = A.Store; printf("Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz); if ( !(rhsb = doublecomplexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsb[]."); if ( !(rhsx = doublecomplexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsx[]."); zCreate_Dense_Matrix(&B, m, nrhs, rhsb, m, SLU_DN, SLU_Z, SLU_GE); zCreate_Dense_Matrix(&X, m, nrhs, rhsx, m, SLU_DN, SLU_Z, SLU_GE); xact = doublecomplexMalloc(n * nrhs); ldx = n; zGenXtrue(n, nrhs, xact, ldx); zFillRHS(trans, nrhs, xact, ldx, &A, &B); if ( !(etree = intMalloc(n)) ) ABORT("Malloc fails for etree[]."); if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[]."); if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[]."); if ( !(R = (double *) SUPERLU_MALLOC(A.nrow * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for R[]."); if ( !(C = (double *) SUPERLU_MALLOC(A.ncol * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for C[]."); if ( !(ferr = (double *) SUPERLU_MALLOC(nrhs * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for ferr[]."); if ( !(berr = (double *) SUPERLU_MALLOC(nrhs * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for berr[]."); /* Initialize the statistics variables. */ StatInit(&stat); /* ONLY PERFORM THE LU DECOMPOSITION */ B.ncol = 0; /* Indicate not to solve the system */ zgssvx(&options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &mem_usage, &stat, &info); printf("LU factorization: zgssvx() returns info %d\n", info); if ( info == 0 || info == n+1 ) { if ( options.PivotGrowth ) printf("Recip. pivot growth = %e\n", rpg); if ( options.ConditionNumber ) printf("Recip. condition number = %e\n", rcond); Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); printf("FILL ratio = %.1f\n", (float)(Lstore->nnz + Ustore->nnz - n)/nnz); printf("L\\U MB %.3f\ttotal MB needed %.3f\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6); fflush(stdout); } else if ( info > 0 && lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); /* ------------------------------------------------------------ NOW WE SOLVE THE LINEAR SYSTEM USING THE FACTORED FORM OF A. ------------------------------------------------------------*/ options.Fact = FACTORED; /* Indicate the factored form of A is supplied. */ B.ncol = nrhs; /* Set the number of right-hand side */ /* Initialize the statistics variables. */ StatInit(&stat); zgssvx(&options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &mem_usage, &stat, &info); printf("Triangular solve: zgssvx() returns info %d\n", info); if ( info == 0 || info == n+1 ) { /* This is how you could access the solution matrix. */ doublecomplex *sol = (doublecomplex*) ((DNformat*) X.Store)->nzval; if ( options.IterRefine ) { printf("Iterative Refinement:\n"); printf("%8s%8s%16s%16s\n", "rhs", "Steps", "FERR", "BERR"); for (i = 0; i < nrhs; ++i) printf("%8d%8d%16e%16e\n", i+1, stat.RefineSteps, ferr[i], berr[i]); } fflush(stdout); } else if ( info > 0 && lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); SUPERLU_FREE (rhsb); SUPERLU_FREE (rhsx); SUPERLU_FREE (xact); SUPERLU_FREE (etree); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); SUPERLU_FREE (R); SUPERLU_FREE (C); SUPERLU_FREE (ferr); SUPERLU_FREE (berr); Destroy_CompCol_Matrix(&A); Destroy_SuperMatrix_Store(&B); Destroy_SuperMatrix_Store(&X); if ( lwork == 0 ) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } else if ( lwork > 0 ) { SUPERLU_FREE(work); } #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Exit main()"); #endif }
int main ( int argc, char *argv[] ) /**********************************************************************/ /* Purpose: SUPER_LU_S3 solves a sparse system read from a file using SGSSVX. Discussion: The sparse matrix is stored in a file using the Harwell-Boeing sparse matrix format. The file should be assigned to the standard input of this program. For instance, if the matrix is stored in the file "g10_rua.txt", the execution command might be: super_lu_s3 < g10_rua.txt Modified: 25 April 2004 Reference: James Demmel, John Gilbert, Xiaoye Li, SuperLU Users's Guide, Sections 1 and 2. Local parameters: SuperMatrix L, the computed L factor. int *perm_c, the column permutation vector. int *perm_r, the row permutations from partial pivoting. SuperMatrix U, the computed U factor. */ { SuperMatrix A; NCformat *Astore; float *a; int *asub; SuperMatrix B; float *berr; float *C; char equed[1]; yes_no_t equil; int *etree; float *ferr; int i; int info; SuperMatrix L; int ldx; SCformat *Lstore; int lwork; int m; mem_usage_t mem_usage; int n; int nnz; int nrhs; superlu_options_t options; int *perm_c; int *perm_r; float *R; float rcond; float *rhsb; float *rhsx; float rpg; float *sol; SuperLUStat_t stat; trans_t trans; SuperMatrix U; float u; NCformat *Ustore; void *work; SuperMatrix X; int *xa; float *xact; /* Say hello. */ printf ( "\n" ); printf ( "SUPER_LU_S3:\n" ); printf ( " Read a sparse matrix A from standard input,\n"); printf ( " stored in Harwell-Boeing Sparse Matrix format.\n" ); printf ( "\n" ); printf ( " Solve a linear system A * X = B using SGSSVX.\n" ); /* Defaults */ lwork = 0; nrhs = 1; equil = YES; u = 1.0; trans = NOTRANS; /* Set the default input options: options.Fact = DOFACT; options.Equil = YES; options.ColPerm = COLAMD; options.DiagPivotThresh = 1.0; options.Trans = NOTRANS; options.IterRefine = NOREFINE; options.SymmetricMode = NO; options.PivotGrowth = NO; options.ConditionNumber = NO; options.PrintStat = YES; */ set_default_options ( &options ); /* Can use command line input to modify the defaults. */ parse_command_line ( argc, argv, &lwork, &u, &equil, &trans ); options.Equil = equil; options.DiagPivotThresh = u; options.Trans = trans; printf ( "\n" ); printf ( " Length of work array LWORK = %d\n", lwork ); printf ( " Equilibration option EQUIL = %d\n", equil ); printf ( " Diagonal pivot threshhold value U = %f\n", u ); printf ( " Tranpose option TRANS = %d\n", trans ); /* Add more functionalities that the defaults. Compute reciprocal pivot growth */ options.PivotGrowth = YES; /* Compute reciprocal condition number */ options.ConditionNumber = YES; /* Perform single-precision refinement */ options.IterRefine = SINGLE; if ( 0 < lwork ) { work = SUPERLU_MALLOC(lwork); if ( !work ) { ABORT ( "SUPERLU_MALLOC cannot allocate work[]" ); } } /* Read matrix A from a file in Harwell-Boeing format. */ sreadhb ( &m, &n, &nnz, &a, &asub, &xa ); /* Create storage for a compressed column matrix. */ sCreate_CompCol_Matrix ( &A, m, n, nnz, a, asub, xa, SLU_NC, SLU_S, SLU_GE ); Astore = A.Store; printf ( "\n" ); printf ( " Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz ); rhsb = floatMalloc ( m * nrhs ); if ( !rhsb ) { ABORT ( "Malloc fails for rhsb[]." ); } rhsx = floatMalloc ( m * nrhs ); if ( !rhsx ) { ABORT ( "Malloc fails for rhsx[]." ); } sCreate_Dense_Matrix ( &B, m, nrhs, rhsb, m, SLU_DN, SLU_S, SLU_GE ); sCreate_Dense_Matrix ( &X, m, nrhs, rhsx, m, SLU_DN, SLU_S, SLU_GE ); xact = floatMalloc ( n * nrhs ); if ( !xact ) { ABORT ( "SUPERLU_MALLOC cannot allocate xact[]" ); } ldx = n; sGenXtrue ( n, nrhs, xact, ldx ); sFillRHS ( trans, nrhs, xact, ldx, &A, &B ); etree = intMalloc ( n ); if ( !etree ) { ABORT ( "Malloc fails for etree[]." ); } perm_c = intMalloc ( n ); if ( !perm_c ) { ABORT ( "Malloc fails for perm_c[]." ); } perm_r = intMalloc ( m ); if ( !perm_r ) { ABORT ( "Malloc fails for perm_r[]." ); } R = (float *) SUPERLU_MALLOC ( A.nrow * sizeof(float) ); if ( !R ) { ABORT ( "SUPERLU_MALLOC fails for R[]." ); } C = (float *) SUPERLU_MALLOC ( A.ncol * sizeof(float) ); if ( !C ) { ABORT ( "SUPERLU_MALLOC fails for C[]." ); } ferr = (float *) SUPERLU_MALLOC ( nrhs * sizeof(float) ); if ( !ferr ) { ABORT ( "SUPERLU_MALLOC fails for ferr[]." ); } berr = (float *) SUPERLU_MALLOC ( nrhs * sizeof(float) ); if ( !berr ) { ABORT ( "SUPERLU_MALLOC fails for berr[]." ); } /* Initialize the statistics variables. */ StatInit(&stat); /* Solve the system and compute the condition number and error bounds using SGSSVX. */ sgssvx ( &options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &mem_usage, &stat, &info ); printf ( "\n" ); printf ( " SGSSVX returns INFO = %d\n", info ); if ( info == 0 || info == n+1 ) { sol = (float*) ((DNformat*) X.Store)->nzval; if ( options.PivotGrowth == YES ) { printf ( "\n" ); printf ( " Reciprocal pivot growth = %e\n", rpg); } if ( options.ConditionNumber == YES ) { printf ( "\n" ); printf ( " Reciprocal condition number = %e\n", rcond); } if ( options.IterRefine != NOREFINE ) { printf ( "\n" ); printf ( " Iterative Refinement:\n"); printf ( "%8s%8s%16s%16s\n", "rhs", "Steps", "FERR", "BERR"); for ( i = 0; i < nrhs; i++ ) { printf ( "%8d%8d%16e%16e\n", i+1, stat.RefineSteps, ferr[i], berr[i]); } } Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf ( "\n" ); printf ( " Number of nonzeros in factor L = %d\n", Lstore->nnz ); printf ( " Number of nonzeros in factor U = %d\n", Ustore->nnz ); printf ( " Number of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n ); printf ( "\n" ); printf ( " L\\U MB %.3f\ttotal MB needed %.3f\texpansions %d\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6, mem_usage.expansions ); fflush ( stdout ); } else if ( info > 0 && lwork == -1 ) { printf ( "\n" ); printf ( " Estimated memory: %d bytes\n", info - n ); } if ( options.PrintStat ) { StatPrint ( &stat ); } StatFree ( &stat ); SUPERLU_FREE ( rhsb ); SUPERLU_FREE ( rhsx ); SUPERLU_FREE ( xact ); SUPERLU_FREE ( etree ); SUPERLU_FREE ( perm_r ); SUPERLU_FREE ( perm_c ); SUPERLU_FREE ( R ); SUPERLU_FREE ( C ); SUPERLU_FREE ( ferr ); SUPERLU_FREE ( berr ); Destroy_CompCol_Matrix ( &A ); Destroy_SuperMatrix_Store ( &B ); Destroy_SuperMatrix_Store ( &X ); if ( 0 <= lwork ) { Destroy_SuperNode_Matrix ( &L ); Destroy_CompCol_Matrix ( &U ); } /* Say goodbye. */ printf ( "\n" ); printf ( "SUPER_LU_S3:\n" ); printf ( " Normal end of execution.\n"); return 0; }
int main(int argc, char *argv[]) { char equed[1]; yes_no_t equil; trans_t trans; SuperMatrix A, L, U; SuperMatrix B, X; NCformat *Astore; NCformat *Ustore; SCformat *Lstore; doublecomplex *a; int *asub, *xa; int *perm_r; /* row permutations from partial pivoting */ int *perm_c; /* column permutation vector */ int *etree; void *work; int info, lwork, nrhs, ldx; int i, m, n, nnz; doublecomplex *rhsb, *rhsx, *xact; double *R, *C; double *ferr, *berr; double u, rpg, rcond; mem_usage_t mem_usage; superlu_options_t options; SuperLUStat_t stat; extern void parse_command_line(); #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Enter main()"); #endif /* Defaults */ lwork = 0; nrhs = 1; equil = YES; u = 1.0; trans = NOTRANS; /* Set the default input options: options.Fact = DOFACT; options.Equil = YES; options.ColPerm = COLAMD; options.DiagPivotThresh = 1.0; options.Trans = NOTRANS; options.IterRefine = NOREFINE; options.SymmetricMode = NO; options.PivotGrowth = NO; options.ConditionNumber = NO; options.PrintStat = YES; */ set_default_options(&options); /* Can use command line input to modify the defaults. */ parse_command_line(argc, argv, &lwork, &u, &equil, &trans); options.Equil = equil; options.DiagPivotThresh = u; options.Trans = trans; /* Add more functionalities that the defaults. */ options.PivotGrowth = YES; /* Compute reciprocal pivot growth */ options.ConditionNumber = YES;/* Compute reciprocal condition number */ options.IterRefine = SLU_DOUBLE; /* Perform double-precision refinement */ if ( lwork > 0 ) { work = SUPERLU_MALLOC(lwork); if ( !work ) { ABORT("ZLINSOLX: cannot allocate work[]"); } } /* Read matrix A from a file in Harwell-Boeing format.*/ zreadhb(&m, &n, &nnz, &a, &asub, &xa); zCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_Z, SLU_GE); Astore = A.Store; printf("Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz); if ( !(rhsb = doublecomplexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsb[]."); if ( !(rhsx = doublecomplexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsx[]."); zCreate_Dense_Matrix(&B, m, nrhs, rhsb, m, SLU_DN, SLU_Z, SLU_GE); zCreate_Dense_Matrix(&X, m, nrhs, rhsx, m, SLU_DN, SLU_Z, SLU_GE); xact = doublecomplexMalloc(n * nrhs); ldx = n; zGenXtrue(n, nrhs, xact, ldx); zFillRHS(trans, nrhs, xact, ldx, &A, &B); if ( !(etree = intMalloc(n)) ) ABORT("Malloc fails for etree[]."); if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[]."); if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[]."); if ( !(R = (double *) SUPERLU_MALLOC(A.nrow * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for R[]."); if ( !(C = (double *) SUPERLU_MALLOC(A.ncol * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for C[]."); if ( !(ferr = (double *) SUPERLU_MALLOC(nrhs * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for ferr[]."); if ( !(berr = (double *) SUPERLU_MALLOC(nrhs * sizeof(double))) ) ABORT("SUPERLU_MALLOC fails for berr[]."); /* Initialize the statistics variables. */ StatInit(&stat); /* Solve the system and compute the condition number and error bounds using dgssvx. */ zgssvx(&options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &mem_usage, &stat, &info); printf("zgssvx(): info %d\n", info); if ( info == 0 || info == n+1 ) { /* This is how you could access the solution matrix. */ doublecomplex *sol = (doublecomplex*) ((DNformat*) X.Store)->nzval; if ( options.PivotGrowth == YES ) printf("Recip. pivot growth = %e\n", rpg); if ( options.ConditionNumber == YES ) printf("Recip. condition number = %e\n", rcond); if ( options.IterRefine != NOREFINE ) { printf("Iterative Refinement:\n"); printf("%8s%8s%16s%16s\n", "rhs", "Steps", "FERR", "BERR"); for (i = 0; i < nrhs; ++i) printf("%8d%8d%16e%16e\n", i+1, stat.RefineSteps, ferr[i], berr[i]); } Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); printf("FILL ratio = %.1f\n", (float)(Lstore->nnz + Ustore->nnz - n)/nnz); printf("L\\U MB %.3f\ttotal MB needed %.3f\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6); fflush(stdout); } else if ( info > 0 && lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); SUPERLU_FREE (rhsb); SUPERLU_FREE (rhsx); SUPERLU_FREE (xact); SUPERLU_FREE (etree); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); SUPERLU_FREE (R); SUPERLU_FREE (C); SUPERLU_FREE (ferr); SUPERLU_FREE (berr); Destroy_CompCol_Matrix(&A); Destroy_SuperMatrix_Store(&B); Destroy_SuperMatrix_Store(&X); if ( lwork == 0 ) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } else if ( lwork > 0 ) { SUPERLU_FREE(work); } #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Exit main()"); #endif }
SolveSuperLU (const MatriceMorse<R> &AA, int strategy, double ttgv, double epsilon, double pivot, double pivot_sym, string ¶m_char, KN<long> pperm_r, KN<long> pperm_c): eps(epsilon), epsr(0), tgv(ttgv), etree(0), string_option(param_char), perm_r(pperm_r), perm_c(pperm_c), RR(0), CC(0), tol_pivot_sym(pivot_sym), tol_pivot(pivot) { SuperMatrix B, X; SuperLUStat_t stat; void *work = 0; int info, lwork = 0/*, nrhs = 1*/; int i; double ferr[1]; double berr[1]; double rpg, rcond; R *bb; R *xx; A.Store = 0; B.Store = 0; X.Store = 0; L.Store = 0; U.Store = 0; int status; n = AA.n; m = AA.m; nnz = AA.nbcoef; arow = AA.a; asubrow = AA.cl; xarow = AA.lg; /* FreeFem++ use Morse Format */ // FFCS - "this->" required by g++ 4.7 this->CompRow_to_CompCol(m, n, nnz, arow, asubrow, xarow, &a, &asub, &xa); /* Defaults */ lwork = 0; // nrhs = 0; /* Set the default values for options argument: * options.Fact = DOFACT; * options.Equil = YES; * options.ColPerm = COLAMD; * options.DiagPivotThresh = 1.0; * options.Trans = NOTRANS; * options.IterRefine = NOREFINE; * options.SymmetricMode = NO; * options.PivotGrowth = NO; * options.ConditionNumber = NO; * options.PrintStat = YES; */ set_default_options(&options); printf(".. default options:\n"); printf("\tFact\t %8d\n", options.Fact); printf("\tEquil\t %8d\n", options.Equil); printf("\tColPerm\t %8d\n", options.ColPerm); printf("\tDiagPivotThresh %8.4f\n", options.DiagPivotThresh); printf("\tTrans\t %8d\n", options.Trans); printf("\tIterRefine\t%4d\n", options.IterRefine); printf("\tSymmetricMode\t%4d\n", options.SymmetricMode); printf("\tPivotGrowth\t%4d\n", options.PivotGrowth); printf("\tConditionNumber\t%4d\n", options.ConditionNumber); printf("..\n"); if (!string_option.empty()) {read_options_freefem(string_option, &options);} printf(".. options:\n"); printf("\tFact\t %8d\n", options.Fact); printf("\tEquil\t %8d\n", options.Equil); printf("\tColPerm\t %8d\n", options.ColPerm); printf("\tDiagPivotThresh %8.4f\n", options.DiagPivotThresh); printf("\tTrans\t %8d\n", options.Trans); printf("\tIterRefine\t%4d\n", options.IterRefine); printf("\tSymmetricMode\t%4d\n", options.SymmetricMode); printf("\tPivotGrowth\t%4d\n", options.PivotGrowth); printf("\tConditionNumber\t%4d\n", options.ConditionNumber); printf("..\n"); Dtype_t R_SLU = SuperLUDriver<R>::R_SLU_T(); // FFCS - "this->" required by g++ 4.7 this->Create_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, R_SLU, SLU_GE); this->Create_Dense_Matrix(&B, m, 0, (R *)0, m, SLU_DN, R_SLU, SLU_GE); this->Create_Dense_Matrix(&X, m, 0, (R *)0, m, SLU_DN, R_SLU, SLU_GE); if (etree.size() == 0) {etree.resize(n);} if (perm_r.size() == 0) {perm_r.resize(n);} if (perm_c.size() == 0) {perm_c.resize(n);} if (!(RR = new double[n])) { ABORT("SUPERLU_MALLOC fails for R[]."); } for (int ii = 0; ii < n; ii++) { RR[ii] = 1.; } if (!(CC = new double[m])) { ABORT("SUPERLU_MALLOC fails for C[]."); } for (int ii = 0; ii < n; ii++) { CC[ii] = 1.; } ferr[0] = 0; berr[0] = 0; /* Initialize the statistics variables. */ StatInit(&stat); /* ONLY PERFORM THE LU DECOMPOSITION */ B.ncol = 0; /* Indicate not to solve the system */ SuperLUDriver<R>::gssvx(&options, &A, perm_c, perm_r, etree, equed, RR, CC, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &Glu, &mem_usage, &stat, &info); if (verbosity > 2) { printf("LU factorization: dgssvx() returns info %d\n", info); } if (verbosity > 3) { if (info == 0 || info == n + 1) { if (options.PivotGrowth) {printf("Recip. pivot growth = %e\n", rpg);} if (options.ConditionNumber) { printf("Recip. condition number = %e\n", rcond); } Lstore = (SCformat *)L.Store; Ustore = (NCformat *)U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); printf("L\\U MB %.3f\ttotal MB needed %.3f\texpansions %d\n", mem_usage.for_lu / 1e6, mem_usage.total_needed / 1e6, stat.expansions ); fflush(stdout); } else if (info > 0 && lwork == -1) { printf("** Estimated memory: %d bytes\n", info - n); } } if (verbosity > 5) {StatPrint(&stat);} StatFree(&stat); if (B.Store) {Destroy_SuperMatrix_Store(&B);} if (X.Store) {Destroy_SuperMatrix_Store(&X);} options.Fact = FACTORED;/* Indicate the factored form of A is supplied. */ }
/* parse command line arguments */ int parse_arguments(int argc, char **argv) { int i; int errors = 0; int verify; mod_gm_opt_t * mod_gm_new_opt; mod_gm_new_opt = gm_malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_new_opt); for(i=1;i<argc;i++) { char * arg = gm_strdup( argv[i] ); char * arg_c = arg; if ( !strcmp( arg, "version" ) || !strcmp( arg, "--version" ) || !strcmp( arg, "-V" ) ) { print_version(); } if ( !strcmp( arg, "help" ) || !strcmp( arg, "--help" ) || !strcmp( arg, "-h" ) ) { print_usage(); } if(parse_args_line(mod_gm_new_opt, arg, 0) != GM_OK) { errors++; free(arg_c); break; } free(arg_c); } /* set identifier to hostname unless specified */ if(mod_gm_new_opt->identifier == NULL) { gethostname(hostname, GM_BUFFERSIZE-1); mod_gm_new_opt->identifier = gm_strdup(hostname); } /* close old logfile */ if(mod_gm_opt->logfile_fp != NULL) { fclose(mod_gm_opt->logfile_fp); mod_gm_opt->logfile_fp = NULL; } /* verify options */ verify = verify_options(mod_gm_new_opt); /* set new options */ if(errors == 0 && verify == GM_OK) { mod_gm_free_opt(mod_gm_opt); mod_gm_opt = mod_gm_new_opt; } /* open new logfile */ if ( mod_gm_new_opt->logmode == GM_LOG_MODE_AUTO && mod_gm_new_opt->logfile ) { mod_gm_opt->logmode = GM_LOG_MODE_FILE; } if(mod_gm_new_opt->logmode == GM_LOG_MODE_FILE && mod_gm_opt->logfile && mod_gm_opt->debug_level < GM_LOG_STDOUT) { mod_gm_opt->logfile_fp = fopen(mod_gm_opt->logfile, "a+"); if(mod_gm_opt->logfile_fp == NULL) { perror(mod_gm_opt->logfile); errors++; } } /* read keyfile */ if(mod_gm_opt->keyfile != NULL && read_keyfile(mod_gm_opt) != GM_OK) { errors++; } if(verify != GM_OK || errors > 0 || mod_gm_new_opt->debug_level >= GM_LOG_DEBUG) { int old_debug = mod_gm_opt->debug_level; mod_gm_opt->debug_level = GM_LOG_DEBUG; dumpconfig(mod_gm_new_opt, GM_WORKER_MODE); mod_gm_opt->debug_level = old_debug; } if(errors > 0 || verify != GM_OK) { mod_gm_free_opt(mod_gm_new_opt); return(GM_ERROR); } return(GM_OK); }
int main (int argc, char **argv, char **env) { argc = argc; argv = argv; env = env; int rc, rrc; char *result, *error; char cmd[120]; char hostname[GM_BUFFERSIZE]; plan(56); /* set hostname */ gethostname(hostname, GM_BUFFERSIZE-1); /* create options structure and set debug level */ mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); mod_gm_opt->debug_level = 0; #ifdef EMBEDDEDPERL char p1[150]; snprintf(p1, 150, "--p1_file=worker/mod_gearman_p1.pl"); parse_args_line(mod_gm_opt, p1, 0); init_embedded_perl(env); #endif /***************************************** * arg parsing test 1 */ char *args[MAX_CMD_ARGS]; strcpy(cmd, "/bin/hostname"); parse_command_line(cmd, args); like(args[0], cmd, "parsing args cmd 1"); /***************************************** * arg parsing test 2 */ strcpy(cmd, "/bin/cmd blah blub foo"); parse_command_line(cmd,args); like(args[0], "/bin/cmd", "parsing args cmd 2"); like(args[1], "blah", "parsing args cmd 2"); like(args[2], "blub", "parsing args cmd 2"); like(args[3], "foo", "parsing args cmd 2"); /***************************************** * send_gearman */ strcpy(cmd, "./send_gearman --server=blah --key=testtest --host=test --service=test --message=test --returncode=0"); rrc = real_exit_code(run_check(cmd, &result, &error)); //diag(result); cmp_ok(rrc, "==", 3, "cmd '%s' returned rc %d", cmd, rrc); if(atof(gearman_version()) >= 0.31) { like(result, "send_gearman UNKNOWN:", "result"); } else { like(result, "sending job to gearmand failed:", "result"); } free(result); free(error); /***************************************** * send_gearman */ //mod_gm_opt->debug_level = 4; strcpy(cmd, "./send_multi --server=blah --host=blah < t/data/send_multi.txt"); rrc = real_exit_code(run_check(cmd, &result, &error)); //diag(result); cmp_ok(rrc, "==", 3, "cmd '%s' returned rc %d", cmd, rrc); if(atof(gearman_version()) >= 0.31) { like(result, "send_multi UNKNOWN:", "result"); } else { like(result, "sending job to gearmand failed:", "result"); } free(result); free(error); /***************************************** * simple test command 1 */ strcpy(cmd, "/bin/hostname"); rc = run_check(cmd, &result, &error); cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 2 */ strcpy(cmd, "/bin/hostname 2>&1"); rc = run_check(cmd, &result, &error); cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 3 */ strcpy(cmd, "/usr/lib/nagios/plugins/check_icmp -H 127.0.0.1"); rc = run_check(cmd, &result, &error); cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 4 */ strcpy(cmd, "echo -n 'test'; exit 2"); rc = run_check(cmd, &result, &error); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 2, "cmd '%s' returned rc %d", cmd, rrc); like(result, "test", "returned result string"); free(result); free(error); gm_job_t * exec_job; exec_job = ( gm_job_t * )malloc( sizeof *exec_job ); set_default_job(exec_job, mod_gm_opt); /***************************************** * non existing command 1 */ exec_job->command_line = strdup("/bin/doesntexist"); exec_job->type = strdup("service"); exec_job->timeout = 10; int fork_on_exec = 0; execute_safe_command(exec_job, fork_on_exec, hostname); cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line); like(exec_job->output, "CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. \\(worker:", "returned result string"); free(exec_job->output); free(exec_job->error); fork_on_exec = 1; lives_ok({execute_safe_command(exec_job, fork_on_exec, hostname);}, "executing command using fork on exec");
int set_superlu_options_from_dict(superlu_options_t * options, int ilu, PyObject * option_dict, int *panel_size, int *relax) { PyObject *args; int ret; int _relax, _panel_size; static char *kwlist[] = { "Fact", "Equil", "ColPerm", "Trans", "IterRefine", "DiagPivotThresh", "PivotGrowth", "ConditionNumber", "RowPerm", "SymmetricMode", "PrintStat", "ReplaceTinyPivot", "SolveInitialized", "RefineInitialized", "ILU_Norm", "ILU_MILU", "ILU_DropTol", "ILU_FillTol", "ILU_FillFactor", "ILU_DropRule", "PanelSize", "Relax", NULL }; if (ilu) { ilu_set_default_options(options); } else { set_default_options(options); } _panel_size = sp_ienv(1); _relax = sp_ienv(2); if (option_dict == NULL) { /* Proceed with default options */ ret = 1; } else { args = PyTuple_New(0); ret = PyArg_ParseTupleAndKeywords(args, option_dict, "|O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&O&", kwlist, fact_cvt, &options->Fact, yes_no_cvt, &options->Equil, colperm_cvt, &options->ColPerm, trans_cvt, &options->Trans, iterrefine_cvt, &options->IterRefine, double_cvt, &options->DiagPivotThresh, yes_no_cvt, &options->PivotGrowth, yes_no_cvt, &options->ConditionNumber, rowperm_cvt, &options->RowPerm, yes_no_cvt, &options->SymmetricMode, yes_no_cvt, &options->PrintStat, yes_no_cvt, &options->ReplaceTinyPivot, yes_no_cvt, &options->SolveInitialized, yes_no_cvt, &options->RefineInitialized, norm_cvt, &options->ILU_Norm, milu_cvt, &options->ILU_MILU, double_cvt, &options->ILU_DropTol, double_cvt, &options->ILU_FillTol, double_cvt, &options->ILU_FillFactor, droprule_cvt, &options->ILU_DropRule, int_cvt, &_panel_size, int_cvt, &_relax); Py_DECREF(args); } if (panel_size != NULL) { *panel_size = _panel_size; } if (relax != NULL) { *relax = _relax; } return ret; }
EXTERN_C_END /*MC MATSOLVERSUPERLU = "superlu" - A solver package providing solvers LU and ILU for sequential matrices via the external package SuperLU. Use ./configure --download-superlu to have PETSc installed with SuperLU Options Database Keys: + -mat_superlu_equil <FALSE> - Equil (None) . -mat_superlu_colperm <COLAMD> - (choose one of) NATURAL MMD_ATA MMD_AT_PLUS_A COLAMD . -mat_superlu_iterrefine <NOREFINE> - (choose one of) NOREFINE SINGLE DOUBLE EXTRA . -mat_superlu_symmetricmode: <FALSE> - SymmetricMode (None) . -mat_superlu_diagpivotthresh <1> - DiagPivotThresh (None) . -mat_superlu_pivotgrowth <FALSE> - PivotGrowth (None) . -mat_superlu_conditionnumber <FALSE> - ConditionNumber (None) . -mat_superlu_rowperm <NOROWPERM> - (choose one of) NOROWPERM LargeDiag . -mat_superlu_replacetinypivot <FALSE> - ReplaceTinyPivot (None) . -mat_superlu_printstat <FALSE> - PrintStat (None) . -mat_superlu_lwork <0> - size of work array in bytes used by factorization (None) . -mat_superlu_ilu_droptol <0> - ILU_DropTol (None) . -mat_superlu_ilu_filltol <0> - ILU_FillTol (None) . -mat_superlu_ilu_fillfactor <0> - ILU_FillFactor (None) . -mat_superlu_ilu_droprull <0> - ILU_DropRule (None) . -mat_superlu_ilu_norm <0> - ILU_Norm (None) - -mat_superlu_ilu_milu <0> - ILU_MILU (None) Notes: Do not confuse this with MATSOLVERSUPERLU_DIST which is for parallel sparse solves Level: beginner .seealso: PCLU, PCILU, MATSOLVERSUPERLU_DIST, MATSOLVERMUMPS, MATSOLVERSPOOLES, PCFactorSetMatSolverPackage(), MatSolverPackage M*/ EXTERN_C_BEGIN #undef __FUNCT__ #define __FUNCT__ "MatGetFactor_seqaij_superlu" PetscErrorCode MatGetFactor_seqaij_superlu(Mat A,MatFactorType ftype,Mat *F) { Mat B; Mat_SuperLU *lu; PetscErrorCode ierr; PetscInt indx,m=A->rmap->n,n=A->cmap->n; PetscBool flg; const char *colperm[]={"NATURAL","MMD_ATA","MMD_AT_PLUS_A","COLAMD"}; /* MY_PERMC - not supported by the petsc interface yet */ const char *iterrefine[]={"NOREFINE", "SINGLE", "DOUBLE", "EXTRA"}; const char *rowperm[]={"NOROWPERM", "LargeDiag"}; /* MY_PERMC - not supported by the petsc interface yet */ PetscFunctionBegin; ierr = MatCreate(((PetscObject)A)->comm,&B);CHKERRQ(ierr); ierr = MatSetSizes(B,A->rmap->n,A->cmap->n,PETSC_DETERMINE,PETSC_DETERMINE);CHKERRQ(ierr); ierr = MatSetType(B,((PetscObject)A)->type_name);CHKERRQ(ierr); ierr = MatSeqAIJSetPreallocation(B,0,PETSC_NULL);CHKERRQ(ierr); if (ftype == MAT_FACTOR_LU || ftype == MAT_FACTOR_ILU){ B->ops->lufactorsymbolic = MatLUFactorSymbolic_SuperLU; B->ops->ilufactorsymbolic = MatLUFactorSymbolic_SuperLU; } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"Factor type not supported"); B->ops->destroy = MatDestroy_SuperLU; B->ops->view = MatView_SuperLU; B->factortype = ftype; B->assembled = PETSC_TRUE; /* required by -ksp_view */ B->preallocated = PETSC_TRUE; ierr = PetscNewLog(B,Mat_SuperLU,&lu);CHKERRQ(ierr); if (ftype == MAT_FACTOR_LU){ set_default_options(&lu->options); /* Comments from SuperLU_4.0/SRC/dgssvx.c: "Whether or not the system will be equilibrated depends on the scaling of the matrix A, but if equilibration is used, A is overwritten by diag(R)*A*diag(C) and B by diag(R)*B (if options->Trans=NOTRANS) or diag(C)*B (if options->Trans = TRANS or CONJ)." We set 'options.Equil = NO' as default because additional space is needed for it. */ lu->options.Equil = NO; } else if (ftype == MAT_FACTOR_ILU){ /* Set the default input options of ilu: */ ilu_set_default_options(&lu->options); } lu->options.PrintStat = NO; /* Initialize the statistics variables. */ StatInit(&lu->stat); lu->lwork = 0; /* allocate space internally by system malloc */ ierr = PetscOptionsBegin(((PetscObject)A)->comm,((PetscObject)A)->prefix,"SuperLU Options","Mat");CHKERRQ(ierr); ierr = PetscOptionsBool("-mat_superlu_equil","Equil","None",(PetscBool)lu->options.Equil,(PetscBool*)&lu->options.Equil,0);CHKERRQ(ierr); ierr = PetscOptionsEList("-mat_superlu_colperm","ColPerm","None",colperm,4,colperm[3],&indx,&flg);CHKERRQ(ierr); if (flg) {lu->options.ColPerm = (colperm_t)indx;} ierr = PetscOptionsEList("-mat_superlu_iterrefine","IterRefine","None",iterrefine,4,iterrefine[0],&indx,&flg);CHKERRQ(ierr); if (flg) { lu->options.IterRefine = (IterRefine_t)indx;} ierr = PetscOptionsBool("-mat_superlu_symmetricmode","SymmetricMode","None",(PetscBool)lu->options.SymmetricMode,&flg,0);CHKERRQ(ierr); if (flg) lu->options.SymmetricMode = YES; ierr = PetscOptionsReal("-mat_superlu_diagpivotthresh","DiagPivotThresh","None",lu->options.DiagPivotThresh,&lu->options.DiagPivotThresh,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsBool("-mat_superlu_pivotgrowth","PivotGrowth","None",(PetscBool)lu->options.PivotGrowth,&flg,0);CHKERRQ(ierr); if (flg) lu->options.PivotGrowth = YES; ierr = PetscOptionsBool("-mat_superlu_conditionnumber","ConditionNumber","None",(PetscBool)lu->options.ConditionNumber,&flg,0);CHKERRQ(ierr); if (flg) lu->options.ConditionNumber = YES; ierr = PetscOptionsEList("-mat_superlu_rowperm","rowperm","None",rowperm,2,rowperm[lu->options.RowPerm],&indx,&flg);CHKERRQ(ierr); if (flg) {lu->options.RowPerm = (rowperm_t)indx;} ierr = PetscOptionsBool("-mat_superlu_replacetinypivot","ReplaceTinyPivot","None",(PetscBool)lu->options.ReplaceTinyPivot,&flg,0);CHKERRQ(ierr); if (flg) lu->options.ReplaceTinyPivot = YES; ierr = PetscOptionsBool("-mat_superlu_printstat","PrintStat","None",(PetscBool)lu->options.PrintStat,&flg,0);CHKERRQ(ierr); if (flg) lu->options.PrintStat = YES; ierr = PetscOptionsInt("-mat_superlu_lwork","size of work array in bytes used by factorization","None",lu->lwork,&lu->lwork,PETSC_NULL);CHKERRQ(ierr); if (lu->lwork > 0 ){ ierr = PetscMalloc(lu->lwork,&lu->work);CHKERRQ(ierr); } else if (lu->lwork != 0 && lu->lwork != -1){ ierr = PetscPrintf(PETSC_COMM_SELF," Warning: lwork %D is not supported by SUPERLU. The default lwork=0 is used.\n",lu->lwork); lu->lwork = 0; } /* ilu options */ ierr = PetscOptionsReal("-mat_superlu_ilu_droptol","ILU_DropTol","None",lu->options.ILU_DropTol,&lu->options.ILU_DropTol,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsReal("-mat_superlu_ilu_filltol","ILU_FillTol","None",lu->options.ILU_FillTol,&lu->options.ILU_FillTol,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsReal("-mat_superlu_ilu_fillfactor","ILU_FillFactor","None",lu->options.ILU_FillFactor,&lu->options.ILU_FillFactor,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsInt("-mat_superlu_ilu_droprull","ILU_DropRule","None",lu->options.ILU_DropRule,&lu->options.ILU_DropRule,PETSC_NULL);CHKERRQ(ierr); ierr = PetscOptionsInt("-mat_superlu_ilu_norm","ILU_Norm","None",lu->options.ILU_Norm,&indx,&flg);CHKERRQ(ierr); if (flg){ lu->options.ILU_Norm = (norm_t)indx; } ierr = PetscOptionsInt("-mat_superlu_ilu_milu","ILU_MILU","None",lu->options.ILU_MILU,&indx,&flg);CHKERRQ(ierr); if (flg){ lu->options.ILU_MILU = (milu_t)indx; } PetscOptionsEnd(); if (lu->options.Equil == YES) { /* superlu overwrites input matrix and rhs when Equil is used, thus create A_dup to keep user's A unchanged */ ierr = MatDuplicate_SeqAIJ(A,MAT_COPY_VALUES,&lu->A_dup);CHKERRQ(ierr); } /* Allocate spaces (notice sizes are for the transpose) */ ierr = PetscMalloc(m*sizeof(PetscInt),&lu->etree);CHKERRQ(ierr); ierr = PetscMalloc(n*sizeof(PetscInt),&lu->perm_r);CHKERRQ(ierr); ierr = PetscMalloc(m*sizeof(PetscInt),&lu->perm_c);CHKERRQ(ierr); ierr = PetscMalloc(n*sizeof(PetscScalar),&lu->R);CHKERRQ(ierr); ierr = PetscMalloc(m*sizeof(PetscScalar),&lu->C);CHKERRQ(ierr); /* create rhs and solution x without allocate space for .Store */ #if defined(PETSC_USE_COMPLEX) zCreate_Dense_Matrix(&lu->B, m, 1, PETSC_NULL, m, SLU_DN, SLU_Z, SLU_GE); zCreate_Dense_Matrix(&lu->X, m, 1, PETSC_NULL, m, SLU_DN, SLU_Z, SLU_GE); #else dCreate_Dense_Matrix(&lu->B, m, 1, PETSC_NULL, m, SLU_DN, SLU_D, SLU_GE); dCreate_Dense_Matrix(&lu->X, m, 1, PETSC_NULL, m, SLU_DN, SLU_D, SLU_GE); #endif #ifdef SUPERLU2 ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatCreateNull","MatCreateNull_SuperLU",(void(*)(void))MatCreateNull_SuperLU);CHKERRQ(ierr); #endif ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatFactorGetSolverPackage_C","MatFactorGetSolverPackage_seqaij_superlu",MatFactorGetSolverPackage_seqaij_superlu);CHKERRQ(ierr); ierr = PetscObjectComposeFunctionDynamic((PetscObject)B,"MatSuperluSetILUDropTol_C","MatSuperluSetILUDropTol_SuperLU",MatSuperluSetILUDropTol_SuperLU);CHKERRQ(ierr); B->spptr = lu; *F = B; PetscFunctionReturn(0); }
int main(int argc, char * argv[]) { Descr qry_descr = { {0} }; Descr tgt_descr = { {0} }; clock_t CPU_time_begin, CPU_time_end; int retval, qry_done, tgt_done; int db_ctr, db_effective_ctr; int user_defined_name; FILE * qry_fptr = NULL, * tgt_fptr = NULL, * digest = NULL; // Score score; //int compare(Descr *descr1, Descr *descr2, Score * score); int compare(Descr *descr1, Descr *descr2, Score * score, Score * score_hung); int read_cmd_file(char *filename); if (argc < 3) { fprintf(stderr, "Usage: %s <db file> <qry file> [<parameter file>].\n", argv[0]); exit(1); } if (!(qry_fptr = efopen(argv[2], "r"))) return 1; if (!(tgt_fptr = efopen(argv[1], "r"))) return 1; /* set defaults: */ set_default_options(); /* change them with the cmd file, if the cmd file given */ if (argc == 4) { if (read_cmd_file(argv[3])) return 1; } /* read in the table of integral values */ /* the array int_table in struct_table.c */ if (read_integral_table(options.path)) { fprintf(stderr, "In data file %s.\n\n", options.path); exit(1); } set_up_exp_table(); user_defined_name = options.outname[0]; /*********************************/ /* loop over the query database :*/ qry_done = 0; retval = -1; db_effective_ctr = 0; CPU_time_begin = clock(); while (!qry_done) { retval = get_next_descr(qry_fptr, &qry_descr); if (retval == 1) { continue; } else if (retval == -1) { qry_done = 1; continue; } /* digest file for larger scale comparisons */ if (!digest) { if (!user_defined_name) { sprintf(options.outname, "%s.struct_out", qry_descr.name); } // ************ added by Mile // output name in postprocessing consists of query and target name retval = get_next_descr(tgt_fptr, &tgt_descr); if (options.postprocess) { sprintf(options.outname, "%s_%s.struct_out", qry_descr.name, tgt_descr.name); } // ************* end by Mile digest = efopen(options.outname, "w"); if (!digest) exit(1); if (options.print_header) { fprintf(digest, "%% columns: \n"); fprintf(digest, "%% query, target: structure names\n"); fprintf(digest, "%% geom_z: z score for the orientational match \n"); fprintf(digest, "%% <dL>: average length mismatch for matched SSEs \n"); fprintf(digest, "%% T: total score assigned to matched SSEs \n"); fprintf(digest, "%% frac: T divided by the number of matched SSEs \n"); fprintf(digest, "%% GC_rmsd: RMSD btw geometric centers of matched SSEs (before postprocessing) \n"); fprintf(digest, "%% A: (after postprocessing) the alignment score \n"); fprintf(digest, "%% aln_L: (after postprocessing) the alignment length \n\n"); fprintf(digest, "%% %6s%6s %6s %6s %6s %6s %6s %6s %6s %6s \n", "query ", "target ", "geom_z", "<dL>", " T ", "frac", "GC_rmsd", "rmsd ", "A ", "aln_L "); } } else { /* otherwise write to the same old digest file */ } /* loop over the database :*/ // Added by Mile - using FOR instead of WHILE - parallelization int tgt_counter = 0; int i; int *retval_array; Descr *tgt_descr_array; rewind(tgt_fptr); tgt_done = 0; /* * Counting number of successful targets */ while (!tgt_done) { retval = get_next_descr(tgt_fptr, &tgt_descr); if (retval == 0 || retval == 1) { tgt_counter++; } else if (retval == -1) { tgt_done = 1; } } /* * Initialization of a Descr array (array of targets) - easy parallelization */ rewind(tgt_fptr); tgt_descr_array = (Descr *) calloc(tgt_counter, sizeof(Descr)); if (tgt_descr_array == NULL) { printf("malloc return NULL!\n"); } retval_array = (int *) calloc(tgt_counter, sizeof(int)); if (retval_array == NULL) { printf("malloc return NULL!\n"); } /* * Storing targets a returning values */ for(i = 0; i < tgt_counter; ++i) { retval = get_next_descr(tgt_fptr, &tgt_descr_array[i]); retval_array[i] = retval; } // Added by Mile - end rewind(tgt_fptr); // tgt_done = 0; db_ctr = 0; db_effective_ctr = 0; if (!user_defined_name) CPU_time_begin = clock(); retval = -1; /* while ( ! tgt_done) { */ // Start of parallelization if (options.postprocess) omp_set_num_threads(1); else omp_set_num_threads(6); #pragma omp parallel // num_threads(1) { #pragma omp for for (i = 0; i < tgt_counter; ++i) { // Added by Mile int retval = retval_array[i]; /* * Two scores one for Smith Waterman, another for Hungarian in database search phase */ Score score; Score score_hung; Descr tgt_descr = tgt_descr_array[i]; /* printf("%s %d\n", tgt_descr.name, retval); */ // Descr qry_descr = qry_descr; #pragma omp atomic db_ctr++; // atomic /* retval = get_next_descr(tgt_fptr, &tgt_descr); */ if (retval == 1) { continue; } else if (retval == -1) { // tgt_done = 1; printf("Error!!!!\n"); exit(1); // added by Mile } else { /* min number of elements */ int helix_overlap = (qry_descr.no_of_helices < tgt_descr.no_of_helices) ? qry_descr.no_of_helices : tgt_descr.no_of_helices; int strand_overlap = (qry_descr.no_of_strands < tgt_descr.no_of_strands) ? qry_descr.no_of_strands : tgt_descr.no_of_strands; double fraction_assigned; int query_size = qry_descr.no_of_strands + qry_descr.no_of_helices; int target_size = tgt_descr.no_of_strands + tgt_descr.no_of_helices; if (helix_overlap + strand_overlap >= options.min_no_SSEs) { #pragma omp atomic db_effective_ctr++; // atomic /* here is the core of the operation: */ retval = compare(&tgt_descr, &qry_descr, &score, &score_hung); if (retval) { printf(" error comparing db:%s query:%s \n", tgt_descr.name, qry_descr.name); exit(retval); } /* * Output score. Can be based: * - only on SW alignment during the database search * - only on Hungarian algorithm during the database search * - on combination depending on the postprocessing score */ switch (options.score_out) { case 0: // SW if (query_size > target_size) { fraction_assigned = score.total_assigned_score / target_size; } else { fraction_assigned = score.total_assigned_score / query_size; } retval = print_score(digest, &qry_descr, &tgt_descr, &score, fraction_assigned, 1); break; case 1: // Hungarian if (query_size > target_size) { fraction_assigned = score_hung.total_assigned_score / target_size; } else { fraction_assigned = score_hung.total_assigned_score / query_size; } retval = print_score(digest, &qry_descr, &tgt_descr, &score_hung, fraction_assigned, 1); break; case 2: // either SW or Hungarian depends on score if (score.total_assigned_score > score_hung.total_assigned_score) { if (query_size > target_size) { fraction_assigned = score.total_assigned_score / target_size; } else { fraction_assigned = score.total_assigned_score / query_size; } retval = print_score(digest, &qry_descr, &tgt_descr, &score, fraction_assigned, 1); } else { if (query_size > target_size) { fraction_assigned = score_hung.total_assigned_score / target_size; } else { fraction_assigned = score_hung.total_assigned_score / query_size; } retval = print_score(digest, &qry_descr, &tgt_descr, &score_hung, fraction_assigned, 1); } break; } if (retval) { printf("error in printing to output file\n"); exit(retval); } } else if (options.report_no_sse_overlap) { retval = print_score(digest, &qry_descr, &tgt_descr, &score, fraction_assigned, 0); if (retval) { printf("error in printing to output file\n"); exit(retval); } } } /* if (options.postprocess) tgt_done = 1; // for now, we postprocess only one pair of structures (not structure against database) */ // if (options.postprocess) break; // added by Mile tricky but I think it should work even without it } } // Added by Mile // Memory cleaning for(i = 0; i < tgt_counter; ++i) { descr_shutdown ( &tgt_descr_array[i] ); } free(tgt_descr_array); free(retval_array); // End added by Mile if (!user_defined_name && db_effective_ctr) { CPU_time_end = clock(); fprintf(digest, "done CPU: %10.3lf s\n", (double) (CPU_time_end - CPU_time_begin) / CLOCKS_PER_SEC); fflush(digest); } if (!user_defined_name) { fclose(digest); digest = NULL; } /* otherwise we keep writing into the saem digest file */ if (options.postprocess) qry_done = 1; /* for now, we postprocess only one pair of structures (not structure against database) */ } if (digest) { CPU_time_end = clock(); fprintf(digest, "done CPU: %10.3lf s\n", (double) (CPU_time_end - CPU_time_begin) / CLOCKS_PER_SEC); fflush(digest); } if (options.verbose) { printf("\n\nlooked at %d db entries.\n", db_effective_ctr); printf("the output written to %s.\n\n", options.outname); } /**************************************************/ /* housekeeping, good for tracking memory leaks */ if (digest) fclose(digest); // map_consistence(0, 0, NULL, NULL, NULL, NULL, NULL); // compare(NULL, NULL, NULL); descr_shutdown(&qry_descr); descr_shutdown(&tgt_descr); fclose(qry_fptr); fclose(tgt_fptr); return 0; }
main(int argc, char *argv[]) { /* * Purpose * ======= * * ZDRIVE is the main test program for the DOUBLE COMPLEX linear * equation driver routines ZGSSV and ZGSSVX. * * The program is invoked by a shell script file -- ztest.csh. * The output from the tests are written into a file -- ztest.out. * * ===================================================================== */ doublecomplex *a, *a_save; int *asub, *asub_save; int *xa, *xa_save; SuperMatrix A, B, X, L, U; SuperMatrix ASAV, AC; mem_usage_t mem_usage; int *perm_r; /* row permutation from partial pivoting */ int *perm_c, *pc_save; /* column permutation */ int *etree; doublecomplex zero = {0.0, 0.0}; double *R, *C; double *ferr, *berr; double *rwork; doublecomplex *wwork; void *work; int info, lwork, nrhs, panel_size, relax; int m, n, nnz; doublecomplex *xact; doublecomplex *rhsb, *solx, *bsav; int ldb, ldx; double rpg, rcond; int i, j, k1; double rowcnd, colcnd, amax; int maxsuper, rowblk, colblk; int prefact, nofact, equil, iequed; int nt, nrun, nfail, nerrs, imat, fimat, nimat; int nfact, ifact, itran; int kl, ku, mode, lda; int zerot, izero, ioff; double u; double anorm, cndnum; doublecomplex *Afull; double result[NTESTS]; superlu_options_t options; fact_t fact; trans_t trans; SuperLUStat_t stat; static char matrix_type[8]; static char equed[1], path[4], sym[1], dist[1]; /* Fixed set of parameters */ int iseed[] = {1988, 1989, 1990, 1991}; static char equeds[] = {'N', 'R', 'C', 'B'}; static fact_t facts[] = {FACTORED, DOFACT, SamePattern, SamePattern_SameRowPerm}; static trans_t transs[] = {NOTRANS, TRANS, CONJ}; /* Some function prototypes */ extern int zgst01(int, int, SuperMatrix *, SuperMatrix *, SuperMatrix *, int *, int *, double *); extern int zgst02(trans_t, int, int, int, SuperMatrix *, doublecomplex *, int, doublecomplex *, int, double *resid); extern int zgst04(int, int, doublecomplex *, int, doublecomplex *, int, double rcond, double *resid); extern int zgst07(trans_t, int, int, SuperMatrix *, doublecomplex *, int, doublecomplex *, int, doublecomplex *, int, double *, double *, double *); extern int zlatb4_(char *, int *, int *, int *, char *, int *, int *, double *, int *, double *, char *); extern int zlatms_(int *, int *, char *, int *, char *, double *d, int *, double *, double *, int *, int *, char *, doublecomplex *, int *, doublecomplex *, int *); extern int sp_zconvert(int, int, doublecomplex *, int, int, int, doublecomplex *a, int *, int *, int *); /* Executable statements */ strcpy(path, "ZGE"); nrun = 0; nfail = 0; nerrs = 0; /* Defaults */ lwork = 0; n = 1; nrhs = 1; panel_size = sp_ienv(1); relax = sp_ienv(2); u = 1.0; strcpy(matrix_type, "LA"); parse_command_line(argc, argv, matrix_type, &n, &panel_size, &relax, &nrhs, &maxsuper, &rowblk, &colblk, &lwork, &u); if ( lwork > 0 ) { work = SUPERLU_MALLOC(lwork); if ( !work ) { fprintf(stderr, "expert: cannot allocate %d bytes\n", lwork); exit (-1); } } /* Set the default input options. */ set_default_options(&options); options.DiagPivotThresh = u; options.PrintStat = NO; options.PivotGrowth = YES; options.ConditionNumber = YES; options.IterRefine = DOUBLE; if ( strcmp(matrix_type, "LA") == 0 ) { /* Test LAPACK matrix suite. */ m = n; lda = SUPERLU_MAX(n, 1); nnz = n * n; /* upper bound */ fimat = 1; nimat = NTYPES; Afull = doublecomplexCalloc(lda * n); zallocateA(n, nnz, &a, &asub, &xa); } else { /* Read a sparse matrix */ fimat = nimat = 0; zreadhb(&m, &n, &nnz, &a, &asub, &xa); } zallocateA(n, nnz, &a_save, &asub_save, &xa_save); rhsb = doublecomplexMalloc(m * nrhs); bsav = doublecomplexMalloc(m * nrhs); solx = doublecomplexMalloc(n * nrhs); ldb = m; ldx = n; zCreate_Dense_Matrix(&B, m, nrhs, rhsb, ldb, SLU_DN, SLU_Z, SLU_GE); zCreate_Dense_Matrix(&X, n, nrhs, solx, ldx, SLU_DN, SLU_Z, SLU_GE); xact = doublecomplexMalloc(n * nrhs); etree = intMalloc(n); perm_r = intMalloc(n); perm_c = intMalloc(n); pc_save = intMalloc(n); R = (double *) SUPERLU_MALLOC(m*sizeof(double)); C = (double *) SUPERLU_MALLOC(n*sizeof(double)); ferr = (double *) SUPERLU_MALLOC(nrhs*sizeof(double)); berr = (double *) SUPERLU_MALLOC(nrhs*sizeof(double)); j = SUPERLU_MAX(m,n) * SUPERLU_MAX(4,nrhs); rwork = (double *) SUPERLU_MALLOC(j*sizeof(double)); for (i = 0; i < j; ++i) rwork[i] = 0.; if ( !R ) ABORT("SUPERLU_MALLOC fails for R"); if ( !C ) ABORT("SUPERLU_MALLOC fails for C"); if ( !ferr ) ABORT("SUPERLU_MALLOC fails for ferr"); if ( !berr ) ABORT("SUPERLU_MALLOC fails for berr"); if ( !rwork ) ABORT("SUPERLU_MALLOC fails for rwork"); wwork = doublecomplexCalloc( SUPERLU_MAX(m,n) * SUPERLU_MAX(4,nrhs) ); for (i = 0; i < n; ++i) perm_c[i] = pc_save[i] = i; options.ColPerm = MY_PERMC; for (imat = fimat; imat <= nimat; ++imat) { /* All matrix types */ if ( imat ) { /* Skip types 5, 6, or 7 if the matrix size is too small. */ zerot = (imat >= 5 && imat <= 7); if ( zerot && n < imat-4 ) continue; /* Set up parameters with ZLATB4 and generate a test matrix with ZLATMS. */ zlatb4_(path, &imat, &n, &n, sym, &kl, &ku, &anorm, &mode, &cndnum, dist); zlatms_(&n, &n, dist, iseed, sym, &rwork[0], &mode, &cndnum, &anorm, &kl, &ku, "No packing", Afull, &lda, &wwork[0], &info); if ( info ) { printf(FMT3, "ZLATMS", info, izero, n, nrhs, imat, nfail); continue; } /* For types 5-7, zero one or more columns of the matrix to test that INFO is returned correctly. */ if ( zerot ) { if ( imat == 5 ) izero = 1; else if ( imat == 6 ) izero = n; else izero = n / 2 + 1; ioff = (izero - 1) * lda; if ( imat < 7 ) { for (i = 0; i < n; ++i) Afull[ioff + i] = zero; } else { for (j = 0; j < n - izero + 1; ++j) for (i = 0; i < n; ++i) Afull[ioff + i + j*lda] = zero; } } else { izero = 0; } /* Convert to sparse representation. */ sp_zconvert(n, n, Afull, lda, kl, ku, a, asub, xa, &nnz); } else { izero = 0; zerot = 0; } zCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_Z, SLU_GE); /* Save a copy of matrix A in ASAV */ zCreate_CompCol_Matrix(&ASAV, m, n, nnz, a_save, asub_save, xa_save, SLU_NC, SLU_Z, SLU_GE); zCopy_CompCol_Matrix(&A, &ASAV); /* Form exact solution. */ zGenXtrue(n, nrhs, xact, ldx); StatInit(&stat); for (iequed = 0; iequed < 4; ++iequed) { *equed = equeds[iequed]; if (iequed == 0) nfact = 4; else nfact = 1; /* Only test factored, pre-equilibrated matrix */ for (ifact = 0; ifact < nfact; ++ifact) { fact = facts[ifact]; options.Fact = fact; for (equil = 0; equil < 2; ++equil) { options.Equil = equil; prefact = ( options.Fact == FACTORED || options.Fact == SamePattern_SameRowPerm ); /* Need a first factor */ nofact = (options.Fact != FACTORED); /* Not factored */ /* Restore the matrix A. */ zCopy_CompCol_Matrix(&ASAV, &A); if ( zerot ) { if ( prefact ) continue; } else if ( options.Fact == FACTORED ) { if ( equil || iequed ) { /* Compute row and column scale factors to equilibrate matrix A. */ zgsequ(&A, R, C, &rowcnd, &colcnd, &amax, &info); /* Force equilibration. */ if ( !info && n > 0 ) { if ( lsame_(equed, "R") ) { rowcnd = 0.; colcnd = 1.; } else if ( lsame_(equed, "C") ) { rowcnd = 1.; colcnd = 0.; } else if ( lsame_(equed, "B") ) { rowcnd = 0.; colcnd = 0.; } } /* Equilibrate the matrix. */ zlaqgs(&A, R, C, rowcnd, colcnd, amax, equed); } } if ( prefact ) { /* Need a factor for the first time */ /* Save Fact option. */ fact = options.Fact; options.Fact = DOFACT; /* Preorder the matrix, obtain the column etree. */ sp_preorder(&options, &A, perm_c, etree, &AC); /* Factor the matrix AC. */ zgstrf(&options, &AC, relax, panel_size, etree, work, lwork, perm_c, perm_r, &L, &U, &stat, &info); if ( info ) { printf("** First factor: info %d, equed %c\n", info, *equed); if ( lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); exit(0); } } Destroy_CompCol_Permuted(&AC); /* Restore Fact option. */ options.Fact = fact; } /* if .. first time factor */ for (itran = 0; itran < NTRAN; ++itran) { trans = transs[itran]; options.Trans = trans; /* Restore the matrix A. */ zCopy_CompCol_Matrix(&ASAV, &A); /* Set the right hand side. */ zFillRHS(trans, nrhs, xact, ldx, &A, &B); zCopy_Dense_Matrix(m, nrhs, rhsb, ldb, bsav, ldb); /*---------------- * Test zgssv *----------------*/ if ( options.Fact == DOFACT && itran == 0) { /* Not yet factored, and untransposed */ zCopy_Dense_Matrix(m, nrhs, rhsb, ldb, solx, ldx); zgssv(&options, &A, perm_c, perm_r, &L, &U, &X, &stat, &info); if ( info && info != izero ) { printf(FMT3, "zgssv", info, izero, n, nrhs, imat, nfail); } else { /* Reconstruct matrix from factors and compute residual. */ zgst01(m, n, &A, &L, &U, perm_c, perm_r, &result[0]); nt = 1; if ( izero == 0 ) { /* Compute residual of the computed solution. */ zCopy_Dense_Matrix(m, nrhs, rhsb, ldb, wwork, ldb); zgst02(trans, m, n, nrhs, &A, solx, ldx, wwork,ldb, &result[1]); nt = 2; } /* Print information about the tests that did not pass the threshold. */ for (i = 0; i < nt; ++i) { if ( result[i] >= THRESH ) { printf(FMT1, "zgssv", n, i, result[i]); ++nfail; } } nrun += nt; } /* else .. info == 0 */ /* Restore perm_c. */ for (i = 0; i < n; ++i) perm_c[i] = pc_save[i]; if (lwork == 0) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } } /* if .. end of testing zgssv */ /*---------------- * Test zgssvx *----------------*/ /* Equilibrate the matrix if fact = FACTORED and equed = 'R', 'C', or 'B'. */ if ( options.Fact == FACTORED && (equil || iequed) && n > 0 ) { zlaqgs(&A, R, C, rowcnd, colcnd, amax, equed); } /* Solve the system and compute the condition number and error bounds using zgssvx. */ zgssvx(&options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &mem_usage, &stat, &info); if ( info && info != izero ) { printf(FMT3, "zgssvx", info, izero, n, nrhs, imat, nfail); if ( lwork == -1 ) { printf("** Estimated memory: %.0f bytes\n", mem_usage.total_needed); exit(0); } } else { if ( !prefact ) { /* Reconstruct matrix from factors and compute residual. */ zgst01(m, n, &A, &L, &U, perm_c, perm_r, &result[0]); k1 = 0; } else { k1 = 1; } if ( !info ) { /* Compute residual of the computed solution.*/ zCopy_Dense_Matrix(m, nrhs, bsav, ldb, wwork, ldb); zgst02(trans, m, n, nrhs, &ASAV, solx, ldx, wwork, ldb, &result[1]); /* Check solution from generated exact solution. */ zgst04(n, nrhs, solx, ldx, xact, ldx, rcond, &result[2]); /* Check the error bounds from iterative refinement. */ zgst07(trans, n, nrhs, &ASAV, bsav, ldb, solx, ldx, xact, ldx, ferr, berr, &result[3]); /* Print information about the tests that did not pass the threshold. */ for (i = k1; i < NTESTS; ++i) { if ( result[i] >= THRESH ) { printf(FMT2, "zgssvx", options.Fact, trans, *equed, n, imat, i, result[i]); ++nfail; } } nrun += NTESTS; } /* if .. info == 0 */ } /* else .. end of testing zgssvx */ } /* for itran ... */ if ( lwork == 0 ) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } } /* for equil ... */ } /* for ifact ... */ } /* for iequed ... */ #if 0 if ( !info ) { PrintPerf(&L, &U, &mem_usage, rpg, rcond, ferr, berr, equed); } #endif } /* for imat ... */ /* Print a summary of the results. */ PrintSumm("ZGE", nfail, nrun, nerrs); SUPERLU_FREE (rhsb); SUPERLU_FREE (bsav); SUPERLU_FREE (solx); SUPERLU_FREE (xact); SUPERLU_FREE (etree); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); SUPERLU_FREE (pc_save); SUPERLU_FREE (R); SUPERLU_FREE (C); SUPERLU_FREE (ferr); SUPERLU_FREE (berr); SUPERLU_FREE (rwork); SUPERLU_FREE (wwork); Destroy_SuperMatrix_Store(&B); Destroy_SuperMatrix_Store(&X); Destroy_CompCol_Matrix(&A); Destroy_CompCol_Matrix(&ASAV); if ( lwork > 0 ) { SUPERLU_FREE (work); Destroy_SuperMatrix_Store(&L); Destroy_SuperMatrix_Store(&U); } StatFree(&stat); return 0; }
/* work starts here */ int main (int argc, char **argv) { int opt; int i; struct sigaction sact; mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); sigemptyset( &sact.sa_mask ); sact.sa_flags = 0; sact.sa_handler = catcher; sigaction( SIGALRM, &sact, NULL ); /* * and parse command line */ while((opt = getopt(argc, argv, "qvVhH:s:i:b")) != -1) { switch(opt) { case 'h': print_usage(); break; case 'v': opt_verbose++; break; case 'V': print_version(); break; case 's': case 'H': server_list[server_list_num++] = optarg; break; case 'q': opt_quiet = GM_ENABLED; break; case 'i': opt_interval = atof(optarg) * 1000000; break; case 'b': opt_batch = GM_ENABLED; break; case '?': printf("Error - No such option: `%c'\n\n", optopt); print_usage(); break; } } mod_gm_opt->debug_level = opt_verbose; mod_gm_opt->logmode = GM_LOG_MODE_TOOLS; if(server_list_num == 0) server_list[server_list_num++] = "localhost"; server_list[server_list_num] = NULL; signal(SIGINT, clean_exit); signal(SIGTERM,clean_exit); /* in batch mode, print stats once and exit */ if(opt_batch == GM_ENABLED) { if(opt_interval > 0) { while(1) { for(i=0;i<server_list_num;i++) { alarm(con_timeout); print_stats(server_list[i]); alarm(0); } usleep(opt_interval); } } else { for(i=0;i<server_list_num;i++) { alarm(con_timeout); print_stats(server_list[i]); alarm(0); } } clean_exit(0); } if(opt_interval <= 0) opt_interval = 1000000; /* init curses */ w = initscr(); cbreak(); nodelay(w, TRUE); noecho(); /* print stats in a loop */ while(1) { if(getch() == 'q') clean_exit(0); if(opt_batch == GM_DISABLED) erase(); /* clear screen */ for(i=0;i<server_list_num;i++) { alarm(con_timeout); print_stats(server_list[i]); alarm(0); } usleep(opt_interval); } clean_exit(0); }
int main (int argc, char **argv, char **env) { struct stat stat_buf; #else int main (int argc, char **argv) { #endif int sid, x; #ifdef EMBEDDEDPERL start_env=env; #endif last_time_increased = 0; /* store the original command line for later reloads */ store_original_comandline(argc, argv); /* * allocate options structure * and parse command line */ mod_gm_opt = gm_malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); if(parse_arguments(argc, argv) != GM_OK) { exit( EXIT_FAILURE ); } #ifdef EMBEDDEDPERL /* make sure the P1 file exists... */ if(p1_file==NULL){ gm_log(GM_LOG_ERROR,"Error: p1.pl file required for embedded Perl interpreter is not set!\n"); exit( EXIT_FAILURE ); } if(stat(p1_file,&stat_buf)!=0){ gm_log(GM_LOG_ERROR,"Error: p1.pl file required for embedded Perl interpreter is missing!\n"); perror("stat"); exit( EXIT_FAILURE ); } #endif /* fork into daemon mode? */ if(mod_gm_opt->daemon_mode == GM_ENABLED) { pid_t pid = fork(); /* an error occurred while trying to fork */ if(pid == -1) { perror("fork"); exit( EXIT_FAILURE ); } /* we are the child process */ else if(pid == 0) { gm_log( GM_LOG_INFO, "mod_gearman worker daemon started with pid %d\n", getpid()); /* Create a new SID for the child process */ sid = setsid(); if ( sid < 0 ) { mod_gm_free_opt(mod_gm_opt); exit( EXIT_FAILURE ); } /* Close out the standard file descriptors */ if(mod_gm_opt->debug_level <= 1) { close(STDIN_FILENO); close(STDOUT_FILENO); close(STDERR_FILENO); } } /* we are the parent. So forking into daemon mode worked */ else { mod_gm_free_opt(mod_gm_opt); exit( EXIT_SUCCESS ); } } else { gm_log( GM_LOG_INFO, "mod_gearman worker started with pid %d\n", getpid()); } /* print some version information */ gm_log( GM_LOG_DEBUG, "Version %s\n", GM_VERSION ); gm_log( GM_LOG_DEBUG, "running on libgearman %s\n", gearman_version() ); /* set signal handlers for a clean exit */ signal(SIGINT, clean_exit); signal(SIGTERM,clean_exit); signal(SIGHUP, reload_config); signal(SIGPIPE, SIG_IGN); /* check and write pid file */ if(write_pid_file() != GM_OK) { exit(EXIT_FAILURE); } /* init crypto functions */ if(mod_gm_opt->encryption == GM_ENABLED) { mod_gm_crypt_init(mod_gm_opt->crypt_key); } else { mod_gm_opt->transportmode = GM_ENCODE_ONLY; } gm_log( GM_LOG_DEBUG, "main process started\n"); /* start a single non forked standalone worker */ if(mod_gm_opt->debug_level >= 10) { gm_log( GM_LOG_TRACE, "starting standalone worker\n"); #ifdef EMBEDDEDPERL worker_client(GM_WORKER_STANDALONE, 1, shmid, start_env); #else worker_client(GM_WORKER_STANDALONE, 1, shmid); #endif exit(EXIT_SUCCESS); } /* setup shared memory */ setup_child_communicator(); /* start status worker */ make_new_child(GM_WORKER_STATUS); /* setup children */ for(x=0; x < mod_gm_opt->min_worker; x++) { make_new_child(GM_WORKER_MULTI); } /* maintain worker population */ monitor_loop(); gm_log( GM_LOG_ERROR, "worker exited from main loop\n"); clean_exit(15); exit( EXIT_SUCCESS ); }
int main(void) { int rc, rrc; char *result, *error; char cmd[120]; char hostname[GM_BUFFERSIZE]; plan(54); /* set hostname */ gethostname(hostname, GM_BUFFERSIZE-1); /* create options structure and set debug level */ mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); mod_gm_opt->debug_level = 0; /***************************************** * arg parsing test 1 */ char *argv[MAX_CMD_ARGS]; strcpy(cmd, "/bin/true"); parse_command_line(cmd, argv); like(argv[0], cmd, "parsing args cmd 1"); /***************************************** * arg parsing test 2 */ strcpy(cmd, "/bin/cmd blah blub foo"); parse_command_line(cmd,argv); like(argv[0], "/bin/cmd", "parsing args cmd 2"); like(argv[1], "blah", "parsing args cmd 2"); like(argv[2], "blub", "parsing args cmd 2"); like(argv[3], "foo", "parsing args cmd 2"); /***************************************** * send_gearman */ strcpy(cmd, "./send_gearman --server=blah --key=testtest --host=test --service=test --message=test --returncode=0"); rrc = real_exit_code(run_check(cmd, &result, &error)); diag(result); cmp_ok(rrc, "==", 3, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * send_gearman */ //mod_gm_opt->debug_level = 4; strcpy(cmd, "./send_multi --server=blah --host=blah < t/data/send_multi.txt"); rrc = real_exit_code(run_check(cmd, &result, &error)); diag(result); cmp_ok(rrc, "==", 3, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 1 */ strcpy(cmd, "/bin/true"); rc = run_check(cmd, &result, &error); cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 2 */ strcpy(cmd, "/bin/true 2>&1"); rc = run_check(cmd, &result, &error); cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 3 */ strcpy(cmd, "/usr/lib/nagios/plugins/check_icmp -H 127.0.0.1"); rc = run_check(cmd, &result, &error); cmp_ok(rc, "==", 0, "pclose for cmd '%s' returned rc %d", cmd, rc); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); free(result); free(error); /***************************************** * simple test command 4 */ strcpy(cmd, "echo -n 'test'; exit 2"); rc = run_check(cmd, &result, &error); rrc = real_exit_code(rc); cmp_ok(rrc, "==", 2, "cmd '%s' returned rc %d", cmd, rrc); like(result, "test", "returned result string"); free(result); free(error); gm_job_t * exec_job; exec_job = ( gm_job_t * )malloc( sizeof *exec_job ); set_default_job(exec_job, mod_gm_opt); /***************************************** * non existing command 1 */ exec_job->command_line = strdup("/bin/doesntexist"); exec_job->type = strdup("service"); exec_job->timeout = 10; int fork_on_exec = 0; execute_safe_command(exec_job, fork_on_exec, hostname); cmp_ok(exec_job->return_code, "==", 2, "cmd '%s' returns rc 2", exec_job->command_line); like(exec_job->output, "CRITICAL: Return code of 127 is out of bounds. Make sure the plugin you're trying to run actually exists. \\(worker:", "returned result string"); free(exec_job->output); free(exec_job->error); fork_on_exec = 1; lives_ok({execute_safe_command(exec_job, fork_on_exec, hostname);}, "executing command using fork on exec");
/*--------------------------------------------------------------------------------------------- * (function: get_options) *-------------------------------------------------------------------------*/ void get_options(int argc, char **argv) { /* Set up the global arguments to their default. */ set_default_options(); /* Parse the command line options. */ const char *optString = "hc:V:WREh:o:a:B:b:N:f:s:S:p:g:t:T:L:H:GA3"; int opt = getopt(argc, argv, optString); while(opt != -1) { switch(opt) { /* arch file */ case 'a': global_args.arch_file = optarg; configuration.arch_file = optarg; break; /* config file */ case 'c': global_args.config_file = optarg; break; case 'V': global_args.verilog_file = optarg; break; case 'o': global_args.output_file = optarg; break; #ifdef VPR5 case 'B': global_args.activation_blif_file = optarg; break; case 'N': global_args.activation_netlist_file = optarg; break; #endif case 'b': global_args.blif_file = optarg; break; case 'f': #ifdef VPR5 global_args.high_level_block = optarg; #endif #ifdef VPR6 warning_message(0, -1, 0, "Option -f: VPR 6.0 doesn't have this feature yet. You'll need to deal with the output_blif.c differences wrapped by \"if (global_args.high_level_block != NULL)\"\n"); #endif break; case 'h': print_usage(); exit(-1); break; case 'g': global_args.sim_num_test_vectors = atoi(optarg); break; case '3': global_args.sim_generate_three_valued_logic = 1; break; case 'L': global_args.sim_hold_low = optarg; break; case 'H': global_args.sim_hold_high = optarg; break; case 't': global_args.sim_vector_input_file = optarg; break; case 'T': global_args.sim_vector_output_file = optarg; break; case 'p': global_args.sim_additional_pins = optarg; break; case 'G': configuration.output_netlist_graphs = 1; break; case 'A': configuration.output_ast_graphs = 1; break; case 'W': global_args.all_warnings = 1; break; case 'E': global_args.sim_output_both_edges = 1; break; case 'R': global_args.sim_output_rising_edge = 1; break; default : print_usage(); error_message(-1, 0, -1, "Invalid arguments.\n"); break; } opt = getopt(argc, argv, optString); } if ( !global_args.config_file && !global_args.blif_file && !global_args.verilog_file && ((!global_args.activation_blif_file) || (!global_args.activation_netlist_file))) { print_usage(); error_message(-1,0,-1,"Must include either " #ifdef VPR5 "a activation blif and netlist file, " #endif "a config file, a blif netlist, or a verilog file\n"); } else if ((global_args.config_file && global_args.verilog_file) || global_args.activation_blif_file) { warning_message(-1,0,-1, "Using command line options for verilog input file!!!\n"); } }
/* main tests */ int main (int argc, char **argv, char **env) { argc = argc; argv = argv; env = env; int status, chld, rc; int tests = 125; int rrc; char cmd[150]; char *result, *error, *message, *output; plan(tests); mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); #ifdef EMBEDDEDPERL char p1[150]; snprintf(p1, 150, "--p1_file=worker/mod_gearman_p1.pl"); parse_args_line(mod_gm_opt, p1, 0); init_embedded_perl(env); #endif char options[150]; snprintf(options, 150, "--server=127.0.0.1:%d", GEARMAND_TEST_PORT); ok(parse_args_line(mod_gm_opt, options, 0) == 0, "parse_args_line()"); mod_gm_opt->debug_level = GM_LOG_ERROR; worker_logfile = my_tmpfile(); if(!ok(worker_logfile != NULL, "created temp logile: %s", worker_logfile)) { diag("could not create temp logfile"); exit( EXIT_FAILURE ); } /* first fire up a gearmand server and one worker */ start_gearmand((void*)NULL); sleep(2); start_worker((void*)NULL); sleep(2); /* wait one second and catch died procs */ while((chld = waitpid(-1, &status, WNOHANG)) != -1 && chld > 0) { diag( "waitpid() %d exited with %d\n", chld, status); status = 0; } if(!ok(gearmand_pid > 0, "'gearmand started with port %d and pid: %d", GEARMAND_TEST_PORT, gearmand_pid)) { diag("make sure gearmand is in your PATH. Common locations are /usr/sbin or /usr/local/sbin"); exit( EXIT_FAILURE ); } if(!ok(pid_alive(gearmand_pid) == TRUE, "gearmand alive")) { check_logfile("/tmp/gearmand.log", 3); kill(gearmand_pid, SIGTERM); kill(worker_pid, SIGTERM); exit( EXIT_FAILURE ); } if(!ok(worker_pid > 0, "worker started with pid: %d", worker_pid)) diag("could not start worker"); if(!ok(pid_alive(worker_pid) == TRUE, "worker alive")) { check_logfile(worker_logfile, 3); kill(gearmand_pid, SIGTERM); kill(worker_pid, SIGTERM); exit( EXIT_FAILURE ); } skip(gearmand_pid <= 0 || worker_pid <= 0, tests-3, /* Number of tests to skip */ "Skipping all tests, no need to go on without gearmand or worker"); /* create server / clients */ mod_gm_opt->transportmode = GM_ENCODE_ONLY; create_modules(); /* send big job */ send_big_jobs(GM_ENCODE_ONLY); //diag_queues(); wait_for_empty_queue("eventhandler", 20); wait_for_empty_queue("service", 20); //diag_queues(); do_result_work(1); //diag_queues(); wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5); /***************************************** * test check */ //diag_queues(); test_servicecheck(GM_ENCODE_ONLY, "./t/crit.pl"); //diag_queues(); wait_for_empty_queue("eventhandler", 20); wait_for_empty_queue("service", 5); //diag_queues(); do_result_work(1); //diag_queues(); wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5); //diag_queues(); like(last_result, "test plugin CRITICAL", "stdout output from ./t/crit.pl"); like(last_result, "some errors on stderr", "stderr output from ./t/crit.pl"); /***************************************** * test check2 */ //diag_queues(); test_servicecheck(GM_ENCODE_ONLY, "./t/both"); //diag_queues(); wait_for_empty_queue("eventhandler", 20); wait_for_empty_queue("service", 5); //diag_queues(); do_result_work(1); //diag_queues(); wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5); like(last_result, "stdout output", "stdout output from ./t/both"); like(last_result, "stderr output", "stderr output from ./t/both"); /* try to send some data with base64 only */ //diag_queues(); test_eventhandler(GM_ENCODE_ONLY); //diag_queues(); test_servicecheck(GM_ENCODE_ONLY, NULL); //diag_queues(); wait_for_empty_queue("eventhandler", 20); wait_for_empty_queue("service", 5); //diag_queues(); do_result_work(1); //diag_queues(); wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5); sleep(1); kill(worker_pid, SIGTERM); waitpid(worker_pid, &status, 0); ok(status == 0, "worker (%d) exited with exit code %d", worker_pid, real_exit_code(status)); status = 0; check_no_worker_running(worker_logfile); check_logfile(worker_logfile, 0); char * test_keys[] = { "12345", "test", "test key 123", "me make you loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong key" }; /* ignore some signals for now */ signal(SIGTERM, SIG_IGN); int i; for(i=0;i<4;i++) { mod_gm_opt->transportmode = GM_ENCODE_AND_ENCRYPT; start_worker((void *)test_keys[i]); mod_gm_crypt_init( test_keys[i] ); ok(1, "initialized with key: %s", test_keys[i]); test_eventhandler(GM_ENCODE_AND_ENCRYPT); test_servicecheck(GM_ENCODE_AND_ENCRYPT, NULL); wait_for_empty_queue("eventhandler", 20); wait_for_empty_queue("service", 5); do_result_work(1); wait_for_empty_queue(GM_DEFAULT_RESULT_QUEUE, 5); sleep(1); kill(worker_pid, SIGTERM); waitpid(worker_pid, &status, 0); ok(status == 0, "worker (%d) exited with exit code %d", worker_pid, real_exit_code(status)); status = 0; check_no_worker_running(worker_logfile); check_logfile(worker_logfile, 0); } /***************************************** * send_gearman */ snprintf(cmd, 150, "./send_gearman --server=127.0.0.1:%d --key=testtest --host=test --service=test --message=test --returncode=0", GEARMAND_TEST_PORT); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); like(result, "^\\s*$", "output from ./send_gearman"); free(result); free(error); /***************************************** * send_multi */ snprintf(cmd, 150, "./send_multi --server=127.0.0.1:%d --host=blah < t/data/send_multi.txt", GEARMAND_TEST_PORT); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); like(result, "send_multi OK: 2 check_multi child checks submitted", "output from ./send_multi"); free(result); free(error); /***************************************** * check_gearman */ snprintf(cmd, 150, "./check_gearman -H 127.0.0.1:%d -s check -a -q worker_test", GEARMAND_TEST_PORT); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); like(result, "check_gearman OK - sending background job succeded", "output from ./check_gearman"); /* cleanup */ free(result); free(error); free_client(&client); free_worker(&worker); /* shutdown gearmand */ rc = send2gearmandadmin("shutdown\n", "127.0.0.1", GEARMAND_TEST_PORT, &output, &message); ok(rc == 0, "rc of send2gearmandadmin %d", rc); like(output, "OK", "output contains OK"); free(message); free(output); /* wait 5 seconds to shutdown */ for(i=0;i<=5;i++) { waitpid(gearmand_pid, &status, WNOHANG); if(pid_alive(gearmand_pid) == FALSE) { todo(); ok(status == 0, "gearmand (%d) exited with: %d", gearmand_pid, real_exit_code(status)); endtodo; break; } sleep(1); } if(pid_alive(gearmand_pid) == TRUE) { /* kill it the hard way */ kill(gearmand_pid, SIGTERM); waitpid(gearmand_pid, &status, 0); ok(status == 0, "gearmand (%d) exited with exit code %d", gearmand_pid, real_exit_code(status)); status = 0; ok(false, "gearmand had to be killed!"); } todo(); check_logfile("/tmp/gearmand.log", status != 0 ? 2 : 0); endtodo; status = 0; kill(worker_pid, SIGTERM); waitpid(worker_pid, &status, 0); ok(status == 0, "worker (%d) exited with exit code %d", worker_pid, real_exit_code(status)); check_no_worker_running(worker_logfile); status = 0; #ifdef EMBEDDEDPERL deinit_embedded_perl(0); #endif free(last_result); free(worker_logfile); endskip; mod_gm_free_opt(mod_gm_opt); return exit_status(); }
int nebmodule_init( int flags, char *args, nebmodule *handle ) { int i; int broker_option_errors = 0; send_now = FALSE; result_threads_running = 0; /* save our handle */ gearman_module_handle=handle; /* set some module info */ neb_set_module_info( gearman_module_handle, NEBMODULE_MODINFO_TITLE, "Mod-Gearman" ); neb_set_module_info( gearman_module_handle, NEBMODULE_MODINFO_AUTHOR, "Sven Nierlein" ); neb_set_module_info( gearman_module_handle, NEBMODULE_MODINFO_TITLE, "Copyright (c) 2010-2011 Sven Nierlein" ); neb_set_module_info( gearman_module_handle, NEBMODULE_MODINFO_VERSION, GM_VERSION ); neb_set_module_info( gearman_module_handle, NEBMODULE_MODINFO_LICENSE, "GPL v3" ); neb_set_module_info( gearman_module_handle, NEBMODULE_MODINFO_DESC, "distribute host/service checks and eventhandler via gearman" ); mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); /* parse arguments */ gm_log( GM_LOG_DEBUG, "Version %s\n", GM_VERSION ); gm_log( GM_LOG_DEBUG, "args: %s\n", args ); gm_log( GM_LOG_TRACE, "nebmodule_init(%i, %i)\n", flags ); gm_log( GM_LOG_DEBUG, "running on libgearman %s\n", gearman_version() ); if( read_arguments( args ) == GM_ERROR ) return NEB_ERROR; /* check for minimum eventbroker options */ if(!(event_broker_options & BROKER_PROGRAM_STATE)) { gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_PROGRAM_STATE (%i) event_broker_options enabled to work\n", BROKER_PROGRAM_STATE ); broker_option_errors++; } if(!(event_broker_options & BROKER_TIMED_EVENTS)) { gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_TIMED_EVENTS (%i) event_broker_options enabled to work\n", BROKER_TIMED_EVENTS ); broker_option_errors++; } if( ( mod_gm_opt->perfdata == GM_ENABLED || mod_gm_opt->hostgroups_num > 0 || mod_gm_opt->hosts == GM_ENABLED ) && !(event_broker_options & BROKER_HOST_CHECKS)) { gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_HOST_CHECKS (%i) event_broker_options enabled to work\n", BROKER_HOST_CHECKS ); broker_option_errors++; } if( ( mod_gm_opt->perfdata == GM_ENABLED || mod_gm_opt->servicegroups_num > 0 || mod_gm_opt->services == GM_ENABLED ) && !(event_broker_options & BROKER_SERVICE_CHECKS)) { gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_SERVICE_CHECKS (%i) event_broker_options enabled to work\n", BROKER_SERVICE_CHECKS ); broker_option_errors++; } if(mod_gm_opt->events == GM_ENABLED && !(event_broker_options & BROKER_EVENT_HANDLERS)) { gm_log( GM_LOG_ERROR, "mod_gearman needs BROKER_EVENT_HANDLERS (%i) event_broker option enabled to work\n", BROKER_EVENT_HANDLERS ); broker_option_errors++; } if(broker_option_errors > 0) return NEB_ERROR; /* check the minimal gearman version */ if((float)atof(gearman_version()) < (float)GM_MIN_LIB_GEARMAN_VERSION) { gm_log( GM_LOG_ERROR, "minimum version of libgearman is %.2f, yours is %.2f\n", (float)GM_MIN_LIB_GEARMAN_VERSION, (float)atof(gearman_version()) ); return NEB_ERROR; } /* init crypto functions */ if(mod_gm_opt->encryption == GM_ENABLED) { if(mod_gm_opt->crypt_key == NULL) { gm_log( GM_LOG_ERROR, "no encryption key provided, please use --key=... or keyfile=...\n"); return NEB_ERROR; } mod_gm_crypt_init(mod_gm_opt->crypt_key); } else { mod_gm_opt->transportmode = GM_ENCODE_ONLY; } /* create client */ if ( create_client( mod_gm_opt->server_list, &client ) != GM_OK ) { gm_log( GM_LOG_ERROR, "cannot start client\n" ); return NEB_ERROR; } /* register callback for process event where everything else starts */ neb_register_callback( NEBCALLBACK_PROCESS_DATA, gearman_module_handle, 0, handle_process_events ); neb_register_callback( NEBCALLBACK_TIMED_EVENT_DATA, gearman_module_handle, 0, handle_timed_events ); /* register export callbacks */ for(i=0;i<GM_NEBTYPESSIZE;i++) { if(mod_gm_opt->exports[i]->elem_number > 0) neb_register_callback( i, gearman_module_handle, 0, handle_export ); } /* log at least one line into the core logfile */ if ( mod_gm_opt->logmode != GM_LOG_MODE_CORE ) { int logmode_saved = mod_gm_opt->logmode; mod_gm_opt->logmode = GM_LOG_MODE_CORE; gm_log( GM_LOG_INFO, "initialized version %s (libgearman %s)\n", GM_VERSION, gearman_version() ); mod_gm_opt->logmode = logmode_saved; } gm_log( GM_LOG_DEBUG, "finished initializing\n" ); return NEB_OK; }
int main (int argc, char **argv, char **env) { argc = argc; argv = argv; env = env; #ifndef EMBEDDEDPERL plan(1); ok(1, "skipped epn tests"); return exit_status(); #endif #ifdef EMBEDDEDPERL int rc, rrc; char *result, *error; char cmd[120]; plan(17); /* create options structure and set debug level */ mod_gm_opt = malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); char cmds[150]; strcpy(cmds, "--p1_file=worker/mod_gearman_p1.pl"); parse_args_line(mod_gm_opt, cmds, 0); strcpy(cmds, "--enable_embedded_perl=on"); parse_args_line(mod_gm_opt, cmds, 0); strcpy(cmds, "--use_embedded_perl_implicitly=on"); parse_args_line(mod_gm_opt, cmds, 0); /* * mod_gm_opt->debug_level=4; * dumpconfig(mod_gm_opt, GM_WORKER_MODE); */ ok(p1_file != NULL, "p1_file: %s", p1_file); /***************************************** * send_gearman */ init_embedded_perl(env); rc=file_uses_embedded_perl("t/ok.pl"); cmp_ok(rc, "==", TRUE, "ok.pl: file_uses_embedded_perl returned rc %d", rc); rc=file_uses_embedded_perl("t/noepn.pl"); cmp_ok(rc, "==", FALSE, "noepn.pl: file_uses_embedded_perl returned rc %d", rc); strcpy(cmd, "./t/fail.pl"); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 3, "cmd '%s' returned rc %d", cmd, rrc); like(result, "ePN failed to compile", "returned result string"); like(error, "^$", "returned error string"); free(result); free(error); strcpy(cmd, "./t/ok.pl"); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 0, "cmd '%s' returned rc %d", cmd, rrc); like(result, "test plugin OK", "returned result string"); unlike(result, "plugin did not call exit", "returned result string"); like(error, "^$", "returned error string"); free(result); free(error); strcpy(cmd, "./t/crit.pl"); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 2, "cmd '%s' returned rc %d", cmd, rrc); like(result, "test plugin CRITICAL", "returned result string"); like(error, "some errors on stderr", "returned error string"); free(result); free(error); strcpy(cmd, "./t/noexit.pl"); rrc = real_exit_code(run_check(cmd, &result, &error)); cmp_ok(rrc, "==", 3, "cmd '%s' returned rc %d", cmd, rrc); like(result, "sample output but no exit", "returned result string"); like(result, "plugin did not call exit", "returned result string"); like(error, "^$", "returned error string"); free(result); free(error); /***************************************** * clean up */ mod_gm_free_opt(mod_gm_opt); deinit_embedded_perl(); return exit_status(); #endif }
int qdpll_main (int argc, char **argv) { QDPLLResult result = QDPLL_RESULT_UNKNOWN; QDPLLApp app; memset (&app, 0, sizeof (QDPLLApp)); set_default_options (&app); qdpll = qdpll_create (); parse_cmd_line_options (&app, qdpll, argc, argv); check_options (&app); set_signal_handlers (&app); if (app.options.print_usage) { print_usage (); cleanup (qdpll, &app); return result; } if (app.options.print_version) { print_version (); cleanup (qdpll, &app); return result; } if (app.options.max_time) alarm (app.options.max_time); parse (&app, qdpll, app.options.in, app.options.trace); if (app.options.pretty_print) { /* Call 'qdpll_gc' to clean up the formula by removing variables which have no occurrences and removing empty quantifier blocks. */ qdpll_gc (qdpll); qdpll_print (qdpll, stdout); } else if (app.options.deps_only) { qdpll_init_deps (qdpll); if (app.options.print_deps) print_deps (&app, qdpll); if (app.options.dump_dep_graph) qdpll_dump_dep_graph (qdpll); } else { result = qdpll_sat (qdpll); #if (COMPUTE_STATS || COMPUTE_TIMES) qdpll_print_stats (qdpll); #endif } if (app.options.trace == TRACE_QRP) fprintf (stdout, "r "); else if (app.options.trace == TRACE_BQRP) fprintf (stdout, "%cr ", 0); print_result_message (&app, qdpll, result, stdout); cleanup (qdpll, &app); return result; }
int main(int argc, char *argv[]) { /* * Purpose * ======= * * The driver program CLINSOLX2. * * This example illustrates how to use CGSSVX to solve systems repeatedly * with the same sparsity pattern of matrix A. * In this case, the column permutation vector perm_c is computed once. * The following data structures will be reused in the subsequent call to * CGSSVX: perm_c, etree * */ char equed[1]; yes_no_t equil; trans_t trans; SuperMatrix A, A1, L, U; SuperMatrix B, B1, X; NCformat *Astore; NCformat *Ustore; SCformat *Lstore; GlobalLU_t Glu; /* facilitate multiple factorizations with SamePattern_SameRowPerm */ complex *a, *a1; int *asub, *xa, *asub1, *xa1; int *perm_r; /* row permutations from partial pivoting */ int *perm_c; /* column permutation vector */ int *etree; void *work; int info, lwork, nrhs, ldx; int i, j, m, n, nnz; complex *rhsb, *rhsb1, *rhsx, *xact; float *R, *C; float *ferr, *berr; float u, rpg, rcond; mem_usage_t mem_usage; superlu_options_t options; SuperLUStat_t stat; FILE *fp = stdin; extern void parse_command_line(); #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Enter main()"); #endif /* Defaults */ lwork = 0; nrhs = 1; equil = YES; u = 1.0; trans = NOTRANS; /* Set the default input options: options.Fact = DOFACT; options.Equil = YES; options.ColPerm = COLAMD; options.DiagPivotThresh = 1.0; options.Trans = NOTRANS; options.IterRefine = NOREFINE; options.SymmetricMode = NO; options.PivotGrowth = NO; options.ConditionNumber = NO; options.PrintStat = YES; */ set_default_options(&options); /* Can use command line input to modify the defaults. */ parse_command_line(argc, argv, &lwork, &u, &equil, &trans); options.Equil = equil; options.DiagPivotThresh = u; options.Trans = trans; if ( lwork > 0 ) { work = SUPERLU_MALLOC(lwork); if ( !work ) { ABORT("DLINSOLX: cannot allocate work[]"); } } /* Read matrix A from a file in Harwell-Boeing format.*/ creadhb(fp, &m, &n, &nnz, &a, &asub, &xa); if ( !(a1 = complexMalloc(nnz)) ) ABORT("Malloc fails for a1[]."); if ( !(asub1 = intMalloc(nnz)) ) ABORT("Malloc fails for asub1[]."); if ( !(xa1 = intMalloc(n+1)) ) ABORT("Malloc fails for xa1[]."); for (i = 0; i < nnz; ++i) { a1[i] = a[i]; asub1[i] = asub[i]; } for (i = 0; i < n+1; ++i) xa1[i] = xa[i]; cCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_C, SLU_GE); Astore = A.Store; printf("Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz); if ( !(rhsb = complexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsb[]."); if ( !(rhsb1 = complexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsb1[]."); if ( !(rhsx = complexMalloc(m * nrhs)) ) ABORT("Malloc fails for rhsx[]."); cCreate_Dense_Matrix(&B, m, nrhs, rhsb, m, SLU_DN, SLU_C, SLU_GE); cCreate_Dense_Matrix(&X, m, nrhs, rhsx, m, SLU_DN, SLU_C, SLU_GE); xact = complexMalloc(n * nrhs); ldx = n; cGenXtrue(n, nrhs, xact, ldx); cFillRHS(trans, nrhs, xact, ldx, &A, &B); for (j = 0; j < nrhs; ++j) for (i = 0; i < m; ++i) rhsb1[i+j*m] = rhsb[i+j*m]; if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[]."); if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[]."); if ( !(etree = intMalloc(n)) ) ABORT("Malloc fails for etree[]."); if ( !(R = (float *) SUPERLU_MALLOC(A.nrow * sizeof(float))) ) ABORT("SUPERLU_MALLOC fails for R[]."); if ( !(C = (float *) SUPERLU_MALLOC(A.ncol * sizeof(float))) ) ABORT("SUPERLU_MALLOC fails for C[]."); if ( !(ferr = (float *) SUPERLU_MALLOC(nrhs * sizeof(float))) ) ABORT("SUPERLU_MALLOC fails for ferr[]."); if ( !(berr = (float *) SUPERLU_MALLOC(nrhs * sizeof(float))) ) ABORT("SUPERLU_MALLOC fails for berr[]."); /* Initialize the statistics variables. */ StatInit(&stat); /* ------------------------------------------------------------ WE SOLVE THE LINEAR SYSTEM FOR THE FIRST TIME: AX = B ------------------------------------------------------------*/ cgssvx(&options, &A, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B, &X, &rpg, &rcond, ferr, berr, &Glu, &mem_usage, &stat, &info); printf("First system: cgssvx() returns info %d\n", info); if ( info == 0 || info == n+1 ) { /* This is how you could access the solution matrix. */ complex *sol = (complex*) ((DNformat*) X.Store)->nzval; if ( options.PivotGrowth ) printf("Recip. pivot growth = %e\n", rpg); if ( options.ConditionNumber ) printf("Recip. condition number = %e\n", rcond); Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); printf("FILL ratio = %.1f\n", (float)(Lstore->nnz + Ustore->nnz - n)/nnz); printf("L\\U MB %.3f\ttotal MB needed %.3f\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6); if ( options.IterRefine ) { printf("Iterative Refinement:\n"); printf("%8s%8s%16s%16s\n", "rhs", "Steps", "FERR", "BERR"); for (i = 0; i < nrhs; ++i) printf("%8d%8d%16e%16e\n", i+1, stat.RefineSteps, ferr[i], berr[i]); } fflush(stdout); } else if ( info > 0 && lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); Destroy_CompCol_Matrix(&A); Destroy_Dense_Matrix(&B); if ( lwork >= 0 ) { /* Deallocate storage associated with L and U. */ Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } /* ------------------------------------------------------------ NOW WE SOLVE ANOTHER LINEAR SYSTEM: A1*X = B1 ONLY THE SPARSITY PATTERN OF A1 IS THE SAME AS THAT OF A. ------------------------------------------------------------*/ options.Fact = SamePattern; StatInit(&stat); /* Initialize the statistics variables. */ cCreate_CompCol_Matrix(&A1, m, n, nnz, a1, asub1, xa1, SLU_NC, SLU_C, SLU_GE); cCreate_Dense_Matrix(&B1, m, nrhs, rhsb1, m, SLU_DN, SLU_C, SLU_GE); cgssvx(&options, &A1, perm_c, perm_r, etree, equed, R, C, &L, &U, work, lwork, &B1, &X, &rpg, &rcond, ferr, berr, &Glu, &mem_usage, &stat, &info); printf("\nSecond system: cgssvx() returns info %d\n", info); if ( info == 0 || info == n+1 ) { /* This is how you could access the solution matrix. */ complex *sol = (complex*) ((DNformat*) X.Store)->nzval; if ( options.PivotGrowth ) printf("Recip. pivot growth = %e\n", rpg); if ( options.ConditionNumber ) printf("Recip. condition number = %e\n", rcond); Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); printf("L\\U MB %.3f\ttotal MB needed %.3f\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6); if ( options.IterRefine ) { printf("Iterative Refinement:\n"); printf("%8s%8s%16s%16s\n", "rhs", "Steps", "FERR", "BERR"); for (i = 0; i < nrhs; ++i) printf("%8d%8d%16e%16e\n", i+1, stat.RefineSteps, ferr[i], berr[i]); } fflush(stdout); } else if ( info > 0 && lwork == -1 ) { printf("** Estimated memory: %d bytes\n", info - n); } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); SUPERLU_FREE (xact); SUPERLU_FREE (etree); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); SUPERLU_FREE (R); SUPERLU_FREE (C); SUPERLU_FREE (ferr); SUPERLU_FREE (berr); Destroy_CompCol_Matrix(&A1); Destroy_Dense_Matrix(&B1); Destroy_Dense_Matrix(&X); if ( lwork == 0 ) { Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); } else if ( lwork > 0 ) { SUPERLU_FREE(work); } #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Exit main()"); #endif }
/* Here is a driver inspired by A. Sheffer's "cow flattener". */ static NLboolean __nlFactorize_SUPERLU(__NLContext *context, NLint *permutation) { /* OpenNL Context */ __NLSparseMatrix* M = (context->least_squares)? &context->MtM: &context->M; NLuint n = context->n; NLuint nnz = __nlSparseMatrixNNZ(M); /* number of non-zero coeffs */ /* Compressed Row Storage matrix representation */ NLint *xa = __NL_NEW_ARRAY(NLint, n+1); NLfloat *rhs = __NL_NEW_ARRAY(NLfloat, n); NLfloat *a = __NL_NEW_ARRAY(NLfloat, nnz); NLint *asub = __NL_NEW_ARRAY(NLint, nnz); NLint *etree = __NL_NEW_ARRAY(NLint, n); /* SuperLU variables */ SuperMatrix At, AtP; NLint info, panel_size, relax; superlu_options_t options; /* Temporary variables */ NLuint i, jj, count; __nl_assert(!(M->storage & __NL_SYMMETRIC)); __nl_assert(M->storage & __NL_ROWS); __nl_assert(M->m == M->n); /* Convert M to compressed column format */ for(i=0, count=0; i<n; i++) { __NLRowColumn *Ri = M->row + i; xa[i] = count; for(jj=0; jj<Ri->size; jj++, count++) { a[count] = Ri->coeff[jj].value; asub[count] = Ri->coeff[jj].index; } } xa[n] = nnz; /* Free M, don't need it anymore at this point */ __nlSparseMatrixClear(M); /* Create superlu A matrix transposed */ sCreate_CompCol_Matrix( &At, n, n, nnz, a, asub, xa, SLU_NC, /* Colum wise, no supernode */ SLU_S, /* floats */ SLU_GE /* general storage */ ); /* Set superlu options */ set_default_options(&options); options.ColPerm = MY_PERMC; options.Fact = DOFACT; StatInit(&(context->slu.stat)); panel_size = sp_ienv(1); /* sp_ienv give us the defaults */ relax = sp_ienv(2); /* Compute permutation and permuted matrix */ context->slu.perm_r = __NL_NEW_ARRAY(NLint, n); context->slu.perm_c = __NL_NEW_ARRAY(NLint, n); if ((permutation == NULL) || (*permutation == -1)) { get_perm_c(3, &At, context->slu.perm_c); if (permutation) memcpy(permutation, context->slu.perm_c, sizeof(NLint)*n); } else memcpy(context->slu.perm_c, permutation, sizeof(NLint)*n); sp_preorder(&options, &At, context->slu.perm_c, etree, &AtP); /* Decompose into L and U */ sgstrf(&options, &AtP, relax, panel_size, etree, NULL, 0, context->slu.perm_c, context->slu.perm_r, &(context->slu.L), &(context->slu.U), &(context->slu.stat), &info); /* Cleanup */ Destroy_SuperMatrix_Store(&At); Destroy_CompCol_Permuted(&AtP); __NL_DELETE_ARRAY(etree); __NL_DELETE_ARRAY(xa); __NL_DELETE_ARRAY(rhs); __NL_DELETE_ARRAY(a); __NL_DELETE_ARRAY(asub); context->slu.alloc_slu = NL_TRUE; return (info == 0); }
int c_fortran_pdgssvx_ABglobal_(int *iopt, int_t *n, int_t *nnz, int *nrhs, double *values, int_t *rowind, int_t *colptr, double *b, int *ldb, int grid_handle[HANDLE_SIZE], double *berr, int factors[HANDLE_SIZE], int *info) { /* * Purpose * ======= * * This is a Fortran wrapper to use pdgssvx_ABglobal(). * * Arguments * ========= * * iopt (input) int * Specifies the operation to be performed: * = 1, performs LU decomposition for the first time * = 2, performs a subsequent LU decomposition for a new matrix * with the same sparsity pattern * = 3, performs triangular solve * = 4, frees all the storage in the end * * n (input) int, order of the matrix A * * nnz (input) int, number of nonzeros in matrix A * * nrhs (input) int, number of right-hand sides in the system AX = B * * values/rowind/colptr (input) column compressed data structure for A * * b (input/output) double * On input, the right-hand side matrix of dimension (ldb, nrhs) * On output, the solution matrix * * ldb (input) int, leading dimension of the matrix B * * grid_handle (input) int array of size 8, holds a pointer to the process * grid structure, which is created and freed separately. * * berr (output) double, the backward error of each right-hand side * * factors (input/output) int array of size 8 * If iopt == 1, it is an output and contains the pointer pointing to * the structure of the factored matrices. * Otherwise, it it an input. * * info (output) int * */ superlu_options_t options; SuperLUStat_t stat; SuperMatrix A; ScalePermstruct_t *ScalePermstruct; LUstruct_t *LUstruct; int_t nprow, npcol; int iam; int report; int i; gridinfo_t *grid; factors_dist_t *LUfactors; /* * Set option for printing statistics. * report = 0: no reporting * report = 1: reporting */ report = 0; /* Locate the process grid. */ grid = (gridinfo_t *) grid_handle[0]; iam = (*grid).iam; nprow = (int_t) grid->nprow; npcol = (int_t) grid->npcol; if ( *iopt == 1 ) { /* LU decomposition */ if ( !iam ) printf(".. Process grid: %d X %d\n", nprow, npcol); /* Initialize the statistics variables. */ PStatInit(&stat); dCreate_CompCol_Matrix_dist(&A, *n, *n, *nnz, values, rowind, colptr, SLU_NC, SLU_D, SLU_GE); /* Set options. */ set_default_options(&options); /* Initialize ScalePermstruct and LUstruct. */ ScalePermstruct = (ScalePermstruct_t *) SUPERLU_MALLOC(sizeof(ScalePermstruct_t)); ScalePermstructInit(*n, *n, ScalePermstruct); LUstruct = (LUstruct_t *) SUPERLU_MALLOC(sizeof(LUstruct_t)); LUstructInit(*n, *n, LUstruct); /* Call global routine with nrhs=0 to perform the factorization. */ pdgssvx_ABglobal(&options, &A, ScalePermstruct, NULL, *ldb, 0, grid, LUstruct, berr, &stat, info); if ( *info == 0 ) { if ( report == 1 ) PStatPrint(&options, &stat, grid); } else { printf("pdgssvx_ABglobal() error returns INFO= %d\n", *info); } /* Save the LU factors in the factors handle */ LUfactors = (factors_dist_t*) SUPERLU_MALLOC(sizeof(factors_dist_t)); LUfactors->ScalePermstruct = ScalePermstruct; LUfactors->LUstruct = LUstruct; factors[0] = (int) LUfactors; /* Free un-wanted storage */ Destroy_SuperMatrix_Store_dist(&A); PStatFree(&stat); } else if ( *iopt == 2 ) { /* Factor a modified matrix with the same sparsity pattern using existing permutations and L U storage */ /* Extract the LU factors in the factors handle */ LUfactors = (factors_dist_t*) factors[0]; ScalePermstruct = LUfactors->ScalePermstruct; LUstruct = LUfactors->LUstruct; PStatInit(&stat); /* Reset SuperMatrix pointers. */ dCreate_CompCol_Matrix_dist(&A, *n, *n, *nnz, values, rowind, colptr, SLU_NC, SLU_D, SLU_GE); /* Set options. */ set_default_options(&options); options.Fact = SamePattern_SameRowPerm; /* Call the routine with nrhs=0 to perform the factorization. */ pdgssvx_ABglobal(&options, &A, ScalePermstruct, NULL, *ldb, 0, grid, LUstruct, berr, &stat, info); if ( *info == 0 ) { if ( report == 1 ) PStatPrint(&options, &stat, grid); } else { printf("pdgssvx_ABglobal() error returns INFO= %d\n", *info); } /* Free un-wanted storage */ Destroy_SuperMatrix_Store_dist(&A); PStatFree(&stat); } else if ( *iopt == 3 ) { /* Triangular solve */ /* Extract the LU factors in the factors handle */ LUfactors = (factors_dist_t*) factors[0]; ScalePermstruct = LUfactors->ScalePermstruct; LUstruct = LUfactors->LUstruct; PStatInit(&stat); /* Reset SuperMatrix pointers. */ dCreate_CompCol_Matrix_dist(&A, *n, *n, *nnz, values, rowind, colptr, SLU_NC, SLU_D, SLU_GE); /* Set options. */ set_default_options(&options); options.Fact = FACTORED; /* Solve the system A*X=B, overwriting B with X. */ pdgssvx_ABglobal(&options, &A, ScalePermstruct, b, *ldb, *nrhs, grid, LUstruct, berr, &stat, info); /* Free un-wanted storage */ Destroy_SuperMatrix_Store_dist(&A); PStatFree(&stat); } else if ( *iopt == 4 ) { /* Free storage */ /* Free the LU factors in the factors handle */ LUfactors = (factors_dist_t*) factors[0]; Destroy_LU(*n, grid, LUfactors->LUstruct); LUstructFree(LUfactors->LUstruct); ScalePermstructFree(LUfactors->ScalePermstruct); SUPERLU_FREE(LUfactors->ScalePermstruct); SUPERLU_FREE(LUfactors->LUstruct); SUPERLU_FREE(LUfactors); } else { fprintf(stderr, "Invalid iopt=%d passed to c_fortran_pdgssvx_ABglobal()\n", *iopt); exit(-1); } }
static PyObject *Py_sgssv (PyObject *self, PyObject *args, PyObject *kwdict) { PyObject *Py_B=NULL, *Py_X=NULL; PyArrayObject *nzvals=NULL; PyArrayObject *colind=NULL, *rowptr=NULL; int N, nnz; int info; int csc=0, permc_spec=2; int *perm_r=NULL, *perm_c=NULL; SuperMatrix A, B, L, U; superlu_options_t options; SuperLUStat_t stat; static char *kwlist[] = {"N","nnz","nzvals","colind","rowptr","B", "csc", "permc_spec",NULL}; /* Get input arguments */ if (!PyArg_ParseTupleAndKeywords(args, kwdict, "iiO!O!O!O|ii", kwlist, &N, &nnz, &PyArray_Type, &nzvals, &PyArray_Type, &colind, &PyArray_Type, &rowptr, &Py_B, &csc, &permc_spec)) return NULL; if (!_CHECK_INTEGER(colind) || !_CHECK_INTEGER(rowptr)) { PyErr_SetString(PyExc_TypeError, "colind and rowptr must be of type cint"); return NULL; } /* Create Space for output */ Py_X = PyArray_CopyFromObject(Py_B,PyArray_FLOAT,1,2); if (Py_X == NULL) return NULL; if (csc) { if (NCFormat_from_spMatrix(&A, N, N, nnz, nzvals, colind, rowptr, PyArray_FLOAT)) { Py_DECREF(Py_X); return NULL; } } else { if (NRFormat_from_spMatrix(&A, N, N, nnz, nzvals, colind, rowptr, PyArray_FLOAT)) { Py_DECREF(Py_X); return NULL; } } if (DenseSuper_from_Numeric(&B, Py_X)) { Destroy_SuperMatrix_Store(&A); Py_DECREF(Py_X); return NULL; } /* B and Py_X share same data now but Py_X "owns" it */ /* Setup options */ if (setjmp(_superlu_py_jmpbuf)) goto fail; else { perm_c = intMalloc(N); perm_r = intMalloc(N); set_default_options(&options); options.ColPerm=superlu_module_getpermc(permc_spec); StatInit(&stat); /* Compute direct inverse of sparse Matrix */ sgssv(&options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info); } SUPERLU_FREE(perm_r); SUPERLU_FREE(perm_c); Destroy_SuperMatrix_Store(&A); Destroy_SuperMatrix_Store(&B); Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); StatFree(&stat); return Py_BuildValue("Ni", Py_X, info); fail: SUPERLU_FREE(perm_r); SUPERLU_FREE(perm_c); Destroy_SuperMatrix_Store(&A); Destroy_SuperMatrix_Store(&B); Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); StatFree(&stat); Py_XDECREF(Py_X); return NULL; }
main(int argc, char *argv[]) { SuperMatrix A; NCformat *Astore; double *a; int *asub, *xa; int *perm_c; /* column permutation vector */ int *perm_r; /* row permutations from partial pivoting */ SuperMatrix L; /* factor L */ SCformat *Lstore; SuperMatrix U; /* factor U */ NCformat *Ustore; SuperMatrix B; int nrhs, ldx, info, m, n, nnz; double *xact, *rhs; mem_usage_t mem_usage; superlu_options_t options; SuperLUStat_t stat; #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Enter main()"); #endif /* Set the default input options: options.Fact = DOFACT; options.Equil = YES; options.ColPerm = COLAMD; options.DiagPivotThresh = 1.0; options.Trans = NOTRANS; options.IterRefine = NOREFINE; options.SymmetricMode = NO; options.PivotGrowth = NO; options.ConditionNumber = NO; options.PrintStat = YES; */ set_default_options(&options); /* Now we modify the default options to use the symmetric mode. */ options.SymmetricMode = YES; options.ColPerm = MMD_AT_PLUS_A; options.DiagPivotThresh = 0.001; #if 1 /* Read matrix A from a file in Harwell-Boeing format.*/ if (argc < 2) { printf("Usage:\n%s [OPTION] < [INPUT] > [OUTPUT]\nOPTION:\n" "-h -hb:\n\t[INPUT] is a Harwell-Boeing format matrix.\n" "-r -rb:\n\t[INPUT] is a Rutherford-Boeing format matrix.\n" "-t -triplet:\n\t[INPUT] is a triplet format matrix.\n", argv[0]); return 0; } else { switch (argv[1][1]) { case 'H': case 'h': printf("Input a Harwell-Boeing format matrix:\n"); dreadhb(&m, &n, &nnz, &a, &asub, &xa); break; case 'R': case 'r': printf("Input a Rutherford-Boeing format matrix:\n"); dreadrb(&m, &n, &nnz, &a, &asub, &xa); break; case 'T': case 't': printf("Input a triplet format matrix:\n"); dreadtriple(&m, &n, &nnz, &a, &asub, &xa); break; default: printf("Unrecognized format.\n"); return 0; } } #else /* Read the matrix in Harwell-Boeing format. */ dreadhb(&m, &n, &nnz, &a, &asub, &xa); #endif dCreate_CompCol_Matrix(&A, m, n, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE); Astore = A.Store; printf("Dimension %dx%d; # nonzeros %d\n", A.nrow, A.ncol, Astore->nnz); nrhs = 1; if ( !(rhs = doubleMalloc(m * nrhs)) ) ABORT("Malloc fails for rhs[]."); dCreate_Dense_Matrix(&B, m, nrhs, rhs, m, SLU_DN, SLU_D, SLU_GE); xact = doubleMalloc(n * nrhs); ldx = n; dGenXtrue(n, nrhs, xact, ldx); dFillRHS(options.Trans, nrhs, xact, ldx, &A, &B); if ( !(perm_c = intMalloc(n)) ) ABORT("Malloc fails for perm_c[]."); if ( !(perm_r = intMalloc(m)) ) ABORT("Malloc fails for perm_r[]."); /* Initialize the statistics variables. */ StatInit(&stat); dgssv(&options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info); if ( info == 0 ) { /* This is how you could access the solution matrix. */ double *sol = (double*) ((DNformat*) B.Store)->nzval; /* Compute the infinity norm of the error. */ dinf_norm_error(nrhs, &B, xact); Lstore = (SCformat *) L.Store; Ustore = (NCformat *) U.Store; printf("No of nonzeros in factor L = %d\n", Lstore->nnz); printf("No of nonzeros in factor U = %d\n", Ustore->nnz); printf("No of nonzeros in L+U = %d\n", Lstore->nnz + Ustore->nnz - n); printf("FILL ratio = %.1f\n", (float)(Lstore->nnz + Ustore->nnz - n)/nnz); dQuerySpace(&L, &U, &mem_usage); printf("L\\U MB %.3f\ttotal MB needed %.3f\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6); } else { printf("dgssv() error returns INFO= %d\n", info); if ( info <= n ) { /* factorization completes */ dQuerySpace(&L, &U, &mem_usage); printf("L\\U MB %.3f\ttotal MB needed %.3f\n", mem_usage.for_lu/1e6, mem_usage.total_needed/1e6); } } if ( options.PrintStat ) StatPrint(&stat); StatFree(&stat); SUPERLU_FREE (rhs); SUPERLU_FREE (xact); SUPERLU_FREE (perm_r); SUPERLU_FREE (perm_c); Destroy_CompCol_Matrix(&A); Destroy_SuperMatrix_Store(&B); Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); #if ( DEBUGlevel>=1 ) CHECK_MALLOC("Exit main()"); #endif }
int main ( int argc, char *argv[] ) /**********************************************************************/ /* Purpose: SUPER_LU_D0 runs a small 5 by 5 example of the use of SUPER_LU. Modified: 23 April 2004 Reference: James Demmel, John Gilbert, Xiaoye Li, SuperLU Users's Guide, Sections 1 and 2. */ { double *a; SuperMatrix A; int *asub; SuperMatrix B; int i; int info; SuperMatrix L; int m; int n; int nnz; int nrhs; superlu_options_t options; int *perm_c; int *perm_r; int permc_spec; double *rhs; double sol[5]; SuperLUStat_t stat; SuperMatrix U; int *xa; /* Say hello. */ printf ( "\n" ); printf ( "SUPER_LU_D0:\n" ); printf ( " Simple 5 by 5 example of SUPER_LU solver.\n" ); /* Initialize parameters. */ m = 5; n = 5; nnz = 12; /* Set aside space for the arrays. */ a = doubleMalloc ( nnz ); if ( !a ) { ABORT ( "Malloc fails for a[]." ); } asub = intMalloc ( nnz ); if ( !asub ) { ABORT ( "Malloc fails for asub[]." ); } xa = intMalloc ( n+1 ); if ( !xa ) { ABORT ( "Malloc fails for xa[]." ); } /* Initialize matrix A. */ a[0] = 19.0; a[1] = 12.0; a[2] = 12.0; a[3] = 21.0; a[4] = 12.0; a[5] = 12.0; a[6] = 21.0; a[7] = 16.0; a[8] = 21.0; a[9] = 5.0; a[10]= 21.0; a[11]= 18.0; asub[0] = 0; asub[1] = 1; asub[2] = 4; asub[3] = 1; asub[4] = 2; asub[5] = 4; asub[6] = 0; asub[7] = 2; asub[8] = 0; asub[9] = 3; asub[10]= 3; asub[11]= 4; xa[0] = 0; xa[1] = 3; xa[2] = 6; xa[3] = 8; xa[4] = 10; xa[5] = 12; sol[0] = -0.031250000; sol[1] = 0.065476190; sol[2] = 0.013392857; sol[3] = 0.062500000; sol[4] = 0.032738095; /* Create matrix A in the format expected by SuperLU. */ dCreate_CompCol_Matrix ( &A, m, n, nnz, a, asub, xa, SLU_NC, SLU_D, SLU_GE ); /* Create the right-hand side matrix B. */ nrhs = 1; rhs = doubleMalloc ( m * nrhs ); if ( !rhs ) { ABORT("Malloc fails for rhs[]."); } for ( i = 0; i < m; i++ ) { rhs[i] = 1.0; } dCreate_Dense_Matrix ( &B, m, nrhs, rhs, m, SLU_DN, SLU_D, SLU_GE ); /* Set up the arrays for the permutations. */ perm_r = intMalloc ( m ); if ( !perm_r ) { ABORT ( "Malloc fails for perm_r[]." ); } perm_c = intMalloc ( n ); if ( !perm_c ) { ABORT ( "Malloc fails for perm_c[]." ); } /* Set the default input options, and then adjust some of them. */ set_default_options ( &options ); options.ColPerm = NATURAL; /* Initialize the statistics variables. */ StatInit ( &stat ); /* Factor the matrix and solve the linear system. */ dgssv ( &options, &A, perm_c, perm_r, &L, &U, &B, &stat, &info ); /* Print some of the results. */ dPrint_CompCol_Matrix ( "Matrix A", &A ); dPrint_SuperNode_Matrix ( "Factor L", &L ); dPrint_CompCol_Matrix ( "Factor U", &U ); dPrint_Dense_Matrix ( "Solution X", &B ); printf ( "\n" ); printf ( " The exact solution:\n" ); printf ( "\n" ); for ( i = 0; i < n; i++ ) { printf ( "%d %f\n", i, sol[i] ); } printf ( "\n" ); print_int_vec ( "perm_r", m, perm_r ); /* De-allocate storage. */ SUPERLU_FREE ( rhs ); SUPERLU_FREE ( perm_r ); SUPERLU_FREE ( perm_c ); Destroy_CompCol_Matrix ( &A ); Destroy_SuperMatrix_Store ( &B ); Destroy_SuperNode_Matrix ( &L ); Destroy_CompCol_Matrix ( &U ); StatFree ( &stat ); printf ( "\n" ); printf ( "SUPER_LU_D0:\n" ); printf ( " Normal end of execution.\n" ); return 0; }
/* work starts here */ int main (int argc, char **argv) { int opt; int result; mod_gm_opt = gm_malloc(sizeof(mod_gm_opt_t)); set_default_options(mod_gm_opt); /* * and parse command line */ while((opt = getopt(argc, argv, "vVhaH:t:w:c:W:C:q:s:e:p:u:")) != -1) { switch(opt) { case 'h': print_usage(); break; case 'v': opt_verbose++; break; case 'V': print_version(); break; case 't': opt_timeout = atoi(optarg); break; case 'w': opt_job_warning = atoi(optarg); break; case 'c': opt_job_critical = atoi(optarg); break; case 'W': opt_worker_warning = atoi(optarg); break; case 'C': opt_worker_critical = atoi(optarg); break; case 'H': add_server(&server_list_num, server_list, optarg); break; case 's': opt_send = optarg; break; case 'a': send_async = 1; break; case 'e': opt_expect = optarg; break; case 'q': opt_queue = optarg; break; case 'u': opt_unique_id = optarg; break; case '?': printf("Error - No such option: `%c'\n\n", optopt); print_usage(); break; } } mod_gm_opt->debug_level = opt_verbose; mod_gm_opt->logmode = GM_LOG_MODE_TOOLS; if(server_list_num == 0) { printf("Error - no hostname given\n\n"); print_usage(); } if(opt_send != NULL && opt_queue == NULL) { printf("Error - need queue (-q) when sending job\n\n"); print_usage(); } /* set alarm signal handler */ signal(SIGALRM, alarm_sighandler); if(opt_send != NULL ) { alarm(opt_timeout); result = check_worker(opt_queue, opt_send, opt_expect); } else { /* get gearman server statistics */ alarm(opt_timeout); result = check_server(server_list[server_list_num-1]->host, server_list[server_list_num-1]->port); } alarm(0); exit( result ); }
/* Here is a driver inspired by A. Sheffer's "cow flattener". */ static NLboolean __nlSolve_SUPERLU( NLboolean do_perm) { /* OpenNL Context */ __NLSparseMatrix* M = &(__nlCurrentContext->M); NLfloat* b = __nlCurrentContext->b; NLfloat* x = __nlCurrentContext->x; /* Compressed Row Storage matrix representation */ NLuint n = __nlCurrentContext->n; NLuint nnz = __nlSparseMatrixNNZ(M); /* Number of Non-Zero coeffs */ NLint* xa = __NL_NEW_ARRAY(NLint, n+1); NLfloat* rhs = __NL_NEW_ARRAY(NLfloat, n); NLfloat* a = __NL_NEW_ARRAY(NLfloat, nnz); NLint* asub = __NL_NEW_ARRAY(NLint, nnz); /* Permutation vector */ NLint* perm_r = __NL_NEW_ARRAY(NLint, n); NLint* perm = __NL_NEW_ARRAY(NLint, n); /* SuperLU variables */ SuperMatrix A, B; /* System */ SuperMatrix L, U; /* Inverse of A */ NLint info; /* status code */ DNformat *vals = NULL; /* access to result */ float *rvals = NULL; /* access to result */ /* SuperLU options and stats */ superlu_options_t options; SuperLUStat_t stat; /* Temporary variables */ __NLRowColumn* Ri = NULL; NLuint i,jj,count; __nl_assert(!(M->storage & __NL_SYMMETRIC)); __nl_assert(M->storage & __NL_ROWS); __nl_assert(M->m == M->n); /* * Step 1: convert matrix M into SuperLU compressed column * representation. * ------------------------------------------------------- */ count = 0; for(i=0; i<n; i++) { Ri = &(M->row[i]); xa[i] = count; for(jj=0; jj<Ri->size; jj++) { a[count] = Ri->coeff[jj].value; asub[count] = Ri->coeff[jj].index; count++; } } xa[n] = nnz; /* Save memory for SuperLU */ __nlSparseMatrixClear(M); /* * Rem: symmetric storage does not seem to work with * SuperLU ... (->deactivated in main SLS::Solver driver) */ sCreate_CompCol_Matrix( &A, n, n, nnz, a, asub, xa, SLU_NR, /* Row_wise, no supernode */ SLU_S, /* floats */ SLU_GE /* general storage */ ); /* Step 2: create vector */ sCreate_Dense_Matrix( &B, n, 1, b, n, SLU_DN, /* Fortran-type column-wise storage */ SLU_S, /* floats */ SLU_GE /* general */ ); /* Step 3: get permutation matrix * ------------------------------ * com_perm: 0 -> no re-ordering * 1 -> re-ordering for A^t.A * 2 -> re-ordering for A^t+A * 3 -> approximate minimum degree ordering */ get_perm_c(do_perm ? 3 : 0, &A, perm); /* Step 4: call SuperLU main routine * --------------------------------- */ set_default_options(&options); options.ColPerm = MY_PERMC; StatInit(&stat); sgssv(&options, &A, perm, perm_r, &L, &U, &B, &stat, &info); /* Step 5: get the solution * ------------------------ * Fortran-type column-wise storage */ vals = (DNformat*)B.Store; rvals = (float*)(vals->nzval); if(info == 0) { for(i = 0; i < n; i++){ x[i] = rvals[i]; } } /* Step 6: cleanup * --------------- */ /* * For these two ones, only the "store" structure * needs to be deallocated (the arrays have been allocated * by us). */ Destroy_SuperMatrix_Store(&A); Destroy_SuperMatrix_Store(&B); /* * These ones need to be fully deallocated (they have been * allocated by SuperLU). */ Destroy_SuperNode_Matrix(&L); Destroy_CompCol_Matrix(&U); StatFree(&stat); __NL_DELETE_ARRAY(xa); __NL_DELETE_ARRAY(rhs); __NL_DELETE_ARRAY(a); __NL_DELETE_ARRAY(asub); __NL_DELETE_ARRAY(perm_r); __NL_DELETE_ARRAY(perm); return (info == 0); }