Beispiel #1
0
int main(int argc, char *argv[]) {
  Node root;
  double t1, t2;

  lace_parseParams(&argc, argv);
  uts_parseParams(argc, argv);

  uts_printParams();
  uts_initRoot(&root, type);
  
  lace_init(_lace_workers, _lace_dqsize);
  lace_startup(32*1024*1024, 0, 0);

  printf("Initialized Lace with %d workers, dqsize=%d\n", _lace_workers, _lace_dqsize);

  LACE_ME;

  t1 = uts_wctime();
  Result r = CALL(parTreeSearch, 0, &root);
  t2 = uts_wctime();

  maxTreeDepth = r.maxdepth;
  nNodes  = r.size;
  nLeaves = r.leaves;

  uts_showStats(GET_NUM_THREADS, 0, t2-t1, nNodes, nLeaves, maxTreeDepth);

  printf("Time: %f\n", t2-t1);

  lace_exit();

  return 0;
}
Beispiel #2
0
int main(int argc, char *argv[])
{
    int workers = 1;
    int dqsize = 100000;

    char c;
    while ((c=getopt(argc, argv, "w:q:h")) != -1) {
        switch (c) {
        case 'w':
            workers = atoi(optarg);
            break;
        case 'q':
            dqsize = atoi(optarg);
            break;
        case 'h':
            usage(argv[0]);
            break;
        default:
            abort();
        }
    }

    if (optind == argc) {
        usage(argv[0]);
        exit(1);
    }

    lace_init(workers, dqsize);
    lace_startup(0, 0, 0);

    LACE_ME;

    struct item items[MAX_ITEMS];	/* array of items */
    int n, capacity, sol;

    if (read_input(argv[optind], items, &capacity, &n))
        return 1;

    double t1 = wctime();
    sol = CALL(knapsack, items, capacity, n, 0);
    double t2 = wctime();

    printf("Best value is %d\n", sol);
    printf("Time: %f\n", t2-t1);

    return 0;
}
Beispiel #3
0
int main(int argc, char **argv)
{
    int workers = 1;
    int dqsize = 100000;

    char c;
    while ((c=getopt(argc, argv, "w:q:h")) != -1) {
        switch (c) {
            case 'w':
                workers = atoi(optarg);
                break;
            case 'q':
                dqsize = atoi(optarg);
                break;
            case 'h':
                usage(argv[0]);
                break;
            default:
                abort();
        }
    }

    if (optind == argc) {
        usage(argv[0]);
        exit(1);
    }

    lace_init(workers, dqsize);
    lace_startup(0, 0, 0);

    LACE_ME;

    int n = atoi(argv[optind]);

    double t1 = wctime();
    int m = CALL(pfib, n);
    double t2 = wctime();

    printf("fib(%d) = %d\n", n, m);
    printf("Time: %f\n", t2-t1);

    lace_exit();
    return 0;
}
Beispiel #4
0
int
main (int argc, char *argv[])
{
    struct args_t args = (struct args_t){argc, argv};
#ifdef HAVE_SYLVAN
    poptContext optCon = poptGetContext(NULL, argc, (const char**)argv, lace_options, 0);
    while(poptGetNextOpt(optCon) != -1 ) { /* ignore errors */ }
    poptFreeContext(optCon);

#if defined(PROB)
    if (lace_n_workers != 1) lace_n_workers = 1;
    Warning(info, "Falling back to 1 LACE worker, since the ProB front-end is not yet compatible with HRE.");
#endif

    lace_init(lace_n_workers, lace_dqsize);
    lace_startup(lace_stacksize, TASK(actual_main), (void*)&args);
#else
    actual_main((void*)&args);
#endif
    return 0;
}
Beispiel #5
0
JNIEXPORT void JNICALL
Java_jsylvan_JSylvan_initLace(JNIEnv *env, jclass cl, jlong threads, jlong stacksize)
{
    lace_init(threads, stacksize);
    lace_startup(0, NULL, NULL);
}
Beispiel #6
0
int main(int argc, char *argv[])
{
    int workers = 1;
    int dqsize = 100000;
    int verify = 0;

    char c;
    while ((c=getopt(argc, argv, "w:q:h:c")) != -1) {
        switch (c) {
            case 'w':
                workers = atoi(optarg);
                break;
            case 'q':
                dqsize = atoi(optarg);
                break;
            case 'c':
                verify = 1;
                break;
            case 'h':
                usage(argv[0]);
                break;
            default:
                abort();
        }
    }

    if (optind == argc) {
        usage(argv[0]);
        exit(1);
    }

    int n = atoi(argv[optind]);

    lace_init(workers, dqsize);
    lace_startup(0, 0, 0);

    REAL *A, *B, *C1, *C2;

    if ((n & (n - 1)) != 0 || (n % 16) != 0) {
        printf("%d: matrix size must be a power of 2"
                " and a multiple of %d\n", n, 16);
        return 1;
    }

    A = alloc_matrix(n);
    B = alloc_matrix(n);
    C1 = alloc_matrix(n);
    C2 = alloc_matrix(n);

    init_matrix(n, A, n);
    init_matrix(n, B, n);

    LACE_ME;

    double t1=wctime();
    CALL(OptimizedStrassenMultiply, C2, A, B, n, n, n, n);
    double t2=wctime();

    if (verify) {
        matrixmul(n, A, n, B, n, C1, n);
        verify = compare_matrix(n, C1, n, C2, n);
    }

    if (verify)
        printf("WRONG RESULT!\n");
    else {	
        printf("Time: %f\n", t2-t1);
    }

    lace_exit();

    return 0;
}
Beispiel #7
0
int
main(int argc, char **argv)
{
    argp_parse(&argp, argc, argv, 0, 0, 0);

    // Init Lace
    lace_init(workers, 1000000); // auto-detect number of workers, use a 1,000,000 size task queue
    lace_startup(0, NULL, NULL); // auto-detect program stack, do not use a callback for startup
    LACE_ME;

    size_t max = 16LL<<30;
    if (max > getMaxMemory()) max = getMaxMemory()/10*9;
    printf("Setting Sylvan main tables memory to ");
    print_h(max);
    printf(" max.\n");

    // Init Sylvan
    sylvan_set_limits(max, 1, 10);
    sylvan_init_package();
    sylvan_init_ldd();
    sylvan_init_mtbdd();
    sylvan_gc_hook_pregc(TASK(gc_start));
    sylvan_gc_hook_postgc(TASK(gc_end));

    // Obtain operation ids for the operation cache
    compute_highest_id = cache_next_opid();
    compute_highest_action_id = cache_next_opid();
    bdd_from_ldd_id = cache_next_opid();
    bdd_from_ldd_rel_id = cache_next_opid();

    // Open file
    FILE *f = fopen(model_filename, "r");
    if (f == NULL) Abort("Cannot open file '%s'!\n", model_filename);

    // Read integers per vector
    if (fread(&vector_size, sizeof(int), 1, f) != 1) Abort("Invalid input file!\n");

    // Read initial state
    if (verbose) printf("Loading initial state.\n");
    set_t initial = set_load(f);

    // Read number of transitions
    if (fread(&next_count, sizeof(int), 1, f) != 1) Abort("Invalid input file!\n");
    next = (rel_t*)malloc(sizeof(rel_t) * next_count);

    // Read transitions
    if (verbose) printf("Loading transition relations.\n");
    for (int i=0; i<next_count; i++) next[i] = rel_load_proj(f);
    for (int i=0; i<next_count; i++) rel_load(f, next[i]);

    // Read whether reachable states are stored
    int has_reachable = 0;
    if (fread(&has_reachable, sizeof(int), 1, f) != 1) Abort("Input file missing reachable states!\n");
    if (has_reachable == 0) Abort("Input file missing reachable states!\n");

    // Read reachable states
    if (verbose) printf("Loading reachable states.\n");
    set_t states = set_load(f);
    
    // Read number of action labels
    int action_labels_count = 0;
    if (fread(&action_labels_count, sizeof(int), 1, f) != 1) action_labels_count = 0;
    // ignore: Abort("Input file missing action label count!\n");

    // Read action labels
    char *action_labels[action_labels_count];
    for (int i=0; i<action_labels_count; i++) {
        uint32_t len;
        if (fread(&len, sizeof(uint32_t), 1, f) != 1) Abort("Invalid input file!\n");
        action_labels[i] = (char*)malloc(sizeof(char[len+1]));
        if (fread(action_labels[i], sizeof(char), len, f) != len) Abort("Invalid input file!\n");
        action_labels[i][len] = 0;
    }

    // Close file
    fclose(f);

    // Report that we have read the input file
    printf("Read file %s.\n", argv[1]);

    // Report statistics
    if (verbose) {
        printf("%d integers per state, %d transition groups\n", vector_size, next_count);
        printf("LDD nodes:\n");
        printf("Initial states: %zu LDD nodes\n", lddmc_nodecount(initial->dd));
        for (int i=0; i<next_count; i++) {
            printf("Transition %d: %zu LDD nodes\n", i, lddmc_nodecount(next[i]->dd));
        }
    }

    // Report that we prepare BDD conversion
    if (verbose) printf("Preparing conversion to BDD...\n");

    // Compute highest value at each level (from reachable states)
    uint32_t highest[vector_size];
    for (int i=0; i<vector_size; i++) highest[i] = 0;
    compute_highest(states->dd, highest);

    // Compute highest action label value (from transition relations)
    uint32_t highest_action = 0;
    for (int i=0; i<next_count; i++) {
        compute_highest_action(next[i]->dd, next[i]->meta, &highest_action);
    }

    // Compute number of bits for each level
    int bits[vector_size];
    for (int i=0; i<vector_size; i++) {
        bits[i] = 0;
        while (highest[i] != 0) {
            bits[i]++;
            highest[i]>>=1;
        }
        if (bits[i] == 0) bits[i] = 1;
    }

    // Compute number of bits for action label
    actionbits = 0;
    while (highest_action != 0) {
        actionbits++;
        highest_action>>=1;
    }
    if (actionbits == 0 && has_actions) actionbits = 1;

    // Report number of bits
    if (verbose) {
        printf("Bits per level: ");
        for (int i=0; i<vector_size; i++) {
            if (i>0) printf(", ");
            printf("%d", bits[i]);
        }
        printf("\n");
        printf("Action bits: %d.\n", actionbits);
    }

    // Compute bits MDD
    MDD bits_dd = lddmc_true;
    for (int i=0; i<vector_size; i++) {
        bits_dd = lddmc_makenode(bits[vector_size-i-1], bits_dd, lddmc_false);
    }
    lddmc_ref(bits_dd);

    // Compute total number of bits
    int totalbits = 0;
    for (int i=0; i<vector_size; i++) {
        totalbits += bits[i];
    }

    // Compute state variables
    MTBDD state_vars = mtbdd_true;
    for (int i=0; i<totalbits; i++) {
        state_vars = mtbdd_makenode(2*(totalbits-i-1), mtbdd_false, state_vars);
    }
    mtbdd_protect(&state_vars);

    // Report that we begin the actual conversion
    if (verbose) printf("Converting to BDD...\n");

    // Create BDD file
    f = fopen(bdd_filename, "w");
    if (f == NULL) Abort("Cannot open file '%s'!\n", bdd_filename);

    // Write domain...
    fwrite(&vector_size, sizeof(int), 1, f);
    fwrite(bits, sizeof(int), vector_size, f);
    fwrite(&actionbits, sizeof(int), 1, f);

    // Write initial state...
    MTBDD new_initial = bdd_from_ldd(initial->dd, bits_dd, 0);
    assert((size_t)mtbdd_satcount(new_initial, totalbits) == (size_t)lddmc_satcount_cached(initial->dd));
    mtbdd_refs_push(new_initial);
    {
        int k = -1;
        fwrite(&k, sizeof(int), 1, f);
        mtbdd_writer_tobinary(f, &new_initial, 1);
    }

    // Custom operation that converts to BDD given number of bits for each level
    MTBDD new_states = bdd_from_ldd(states->dd, bits_dd, 0);
    assert((size_t)mtbdd_satcount(new_states, totalbits) == (size_t)lddmc_satcount_cached(states->dd));
    mtbdd_refs_push(new_states);

    // Report size of BDD
    if (verbose) {
        printf("Initial states: %zu BDD nodes\n", mtbdd_nodecount(new_initial));
        printf("Reachable states: %zu BDD nodes\n", mtbdd_nodecount(new_states));
    }

    // Write number of transitions
    fwrite(&next_count, sizeof(int), 1, f);

    // Write meta for each transition
    for (int i=0; i<next_count; i++) {
        fwrite(&next[i]->r_k, sizeof(int), 1, f);
        fwrite(&next[i]->w_k, sizeof(int), 1, f);
        fwrite(next[i]->r_proj, sizeof(int), next[i]->r_k, f);
        fwrite(next[i]->w_proj, sizeof(int), next[i]->w_k, f);
    }

    // Write BDD for each transition
    for (int i=0; i<next_count; i++) {
        // Compute new transition relation
        MTBDD new_rel = bdd_from_ldd_rel(next[i]->dd, bits_dd, 0, next[i]->meta);
        mtbdd_refs_push(new_rel);
        mtbdd_writer_tobinary(f, &new_rel, 1);

        // Report number of nodes
        if (verbose) printf("Transition %d: %zu BDD nodes\n", i, mtbdd_nodecount(new_rel));

        if (check_results) {
            // Compute new <variables> for the current transition relation
            MTBDD new_vars = meta_to_bdd(next[i]->meta, bits_dd, 0);
            mtbdd_refs_push(new_vars);

            // Test if the transition is correctly converted
            MTBDD test = sylvan_relnext(new_states, new_rel, new_vars);
            mtbdd_refs_push(test);
            MDD succ = lddmc_relprod(states->dd, next[i]->dd, next[i]->meta);
            lddmc_refs_push(succ);
            MTBDD test2 = bdd_from_ldd(succ, bits_dd, 0);
            if (test != test2) Abort("Conversion error!\n");
            lddmc_refs_pop(1);
            mtbdd_refs_pop(2);
        }

        mtbdd_refs_pop(1);
    }

    // Write reachable states
    if (no_reachable) has_reachable = 0;
    fwrite(&has_reachable, sizeof(int), 1, f);
    if (has_reachable) {
        int k = -1;
        fwrite(&k, sizeof(int), 1, f);
        mtbdd_writer_tobinary(f, &new_states, 1);
    }
    mtbdd_refs_pop(1);  // new_states

    // Write action labels
    fwrite(&action_labels_count, sizeof(int), 1, f);
    for (int i=0; i<action_labels_count; i++) {
        uint32_t len = strlen(action_labels[i]);
        fwrite(&len, sizeof(uint32_t), 1, f);
        fwrite(action_labels[i], sizeof(char), len, f);
    }

    // Close the file
    fclose(f);

    // Report to the user
    printf("Written file %s.\n", bdd_filename);

    // Report Sylvan statistics (if SYLVAN_STATS is set)
    if (verbose) sylvan_stats_report(stdout);

    return 0;
}