示例#1
0
文件: matmul-lace.c 项目: fritzo/lace
/*
 * A \in M(m, n)
 * B \in M(n, p)
 * C \in M(m, p)
 */
VOID_TASK_8(rec_matmul, REAL*, A, REAL*, B, REAL*, C, int, m, int, n, int, p, int, ld, int, add)
{
    if ((m + n + p) <= 64) {
        int i, j, k;
        /* base case */
        if (add) {
            for (i = 0; i < m; i++)
                for (k = 0; k < p; k++) {
                    REAL c = 0.0;
                    for (j = 0; j < n; j++)
                        c += A[i * ld + j] * B[j * ld + k];
                    C[i * ld + k] += c;
                }
        } else {
            for (i = 0; i < m; i++)
                for (k = 0; k < p; k++) {
                    REAL c = 0.0;
                    for (j = 0; j < n; j++)
                        c += A[i * ld + j] * B[j * ld + k];
                    C[i * ld + k] = c;
                }
        }
    } else if (m >= n && n >= p) {
        int m1 = m >> 1;
        SPAWN(rec_matmul, A, B, C, m1, n, p, ld, add);
        CALL(rec_matmul, A + m1 * ld, B, C + m1 * ld, m - m1, n, p, ld, add);
        SYNC(rec_matmul);
    } else if (n >= m && n >= p) {
示例#2
0
TASK_3(BDD, union_par, BDD*, arr, int, first, int, last)
{
    if (first == last) return arr[first];

    BDD left, right;

    int mid = (first+last)/2;
    // check: last == first + 1
    if (first == mid) { // we have 2
        return CALL(sylvan_ite, arr[first], sylvan_true, arr[last], 0); // or
    }

    if (mid+1 == last) { // we have 3
        left = sylvan_ref(CALL(sylvan_ite, arr[first], sylvan_true, arr[mid], 0)); // or
        BDD result = CALL(sylvan_ite, left, sylvan_true, arr[last], 0);
        sylvan_deref(left);
        return result;
    }

    SPAWN(union_par, arr, first, mid);
    right = sylvan_ref(CALL(union_par, arr, mid+1, last));
    left = sylvan_ref(SYNC(union_par));
    BDD result = CALL(sylvan_ite, left, sylvan_true, right, 0);
    sylvan_deref(left);
    sylvan_deref(right);
    return result;
}
示例#3
0
文件: spawn.c 项目: ytoto/uemacs
/*
 * Run a command. The "cmd" is a pointer to a command string, or NULL if you
 * want to run a copy of DCL in the subjob (this is how the standard routine
 * LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
 * and the way out, because DCL does not want the channel to be in raw mode.
 */
int sys(char *cmd)
{
	struct dsc$descriptor cdsc;
	struct dsc$descriptor *cdscp;
	long status;
	long substatus;
	long iosb[2];

	status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
			  oldmode, sizeof(oldmode), 0, 0, 0, 0);
	if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
		return FALSE;
	cdscp = NULL;		/* Assume DCL.          */
	if (cmd != NULL) {	/* Build descriptor.    */
		cdsc.dsc$a_pointer = cmd;
		cdsc.dsc$w_length = strlen(cmd);
		cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
		cdsc.dsc$b_class = DSC$K_CLASS_S;
		cdscp = &cdsc;
	}
	status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
	if (status != SS$_NORMAL)
		substatus = status;
	status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
			  newmode, sizeof(newmode), 0, 0, 0, 0);
	if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
		return FALSE;
	if ((substatus & STS$M_SUCCESS) == 0)	/* Command failed.      */
		return FALSE;
	return TRUE;
}
示例#4
0
文件: fib-lace.c 项目: trolando/lace
TASK_1(int, pfib, int, n)
{
    if( n < 2 ) {
        return n;
    } else {
        int m,k;
        SPAWN( pfib, n-1 );
        k = CALL( pfib, n-2 );
        m = SYNC( pfib );
        return m+k;
    }
}
示例#5
0
文件: sysdep.cpp 项目: Viriana/SISE
globle void VMSSystem(
  char *cmd)
  {
   long status, complcode;
   struct dsc$descriptor_s cmd_desc;

   cmd_desc.dsc$w_length = strlen(cmd);
   cmd_desc.dsc$a_pointer = cmd;
   cmd_desc.dsc$b_class = DSC$K_CLASS_S;
   cmd_desc.dsc$b_dtype = DSC$K_DTYPE_T;

   status = LIB$SPAWN(&cmd_desc,0,0,0,0,0,&complcode,0,0,0);
  }
示例#6
0
static void spawn_authorize(char *expected_file)
{
	static $DESCRIPTOR(cmd_dx, "MCR SYS$SYSTEM:AUTHORIZE list/brief *");
	int status, flags;

	printf("Spawning authorize command...\n");
	flags = 2 + 8;		/* noclisym + nokeypad */
	status = LIB$SPAWN(&cmd_dx, 0, 0, &flags, 0, 0, 0, 0, 0, 0, 0, 0, 0);
	if ((status & 1) == 0) {
		printf("Error spawning spawn\n");
		exit(status);
	}
}
示例#7
0
MVMint64 MVM_proc_shell(MVMThreadContext *tc, MVMString *cmd, MVMString *cwd, MVMObject *env) {
    MVMint64 result = 0, spawn_result = 0;
    uv_process_t *process = calloc(1, sizeof(uv_process_t));
    uv_process_options_t process_options = {0};
    uv_stdio_container_t process_stdio[3];
    int i;

    char * const cmdin = MVM_string_utf8_encode_C_string(tc, cmd);
    char * const _cwd = MVM_string_utf8_encode_C_string(tc, cwd);
    const MVMuint64 size = MVM_repr_elems(tc, env);
    MVMIter * const iter = (MVMIter *)MVM_iter(tc, env);
    char **_env = malloc((size + 1) * sizeof(char *));

#ifdef _WIN32
    const MVMuint16 acp = GetACP(); /* We should get ACP at runtime. */
    char * const _cmd = ANSIToUTF8(acp, getenv("ComSpec"));
    char *args[3];
    args[0] = "/c";
    {
        MVMint64 len = strlen(cmdin);
        MVMint64 i;
        for (i = 0; i < len; i++)
            if (cmdin[i] == '/')
                cmdin[i] = '\\';
    }
    args[1] = cmdin;
    args[2] = NULL;
#else
    char * const _cmd = "/bin/sh";
    char *args[4];
    args[0] = "/bin/sh";
    args[1] = "-c";
    args[2] = cmdin;
    args[3] = NULL;
#endif

    INIT_ENV();
    SPAWN(_cmd);
    FREE_ENV();

    free(_cwd);

#ifdef _WIN32
    free(_cmd);
#endif

    free(cmdin);
    return result;
}
示例#8
0
void CpuGMTask::draw() {
    SkBitmap bitmap;
    SetupBitmap(fColorType, fGM.get(), &bitmap);

    SkCanvas canvas(bitmap);
    canvas.concat(fGM->getInitialTransform());
    fGM->draw(&canvas);
    canvas.flush();

#define SPAWN(ChildTask, ...) this->spawnChild(SkNEW_ARGS(ChildTask, (*this, __VA_ARGS__)))
    SPAWN(ExpectationsTask, fExpectations, bitmap);

    SPAWN(PipeTask, fGMFactory(NULL), bitmap, false, false);
    SPAWN(PipeTask, fGMFactory(NULL), bitmap, true, false);
    SPAWN(PipeTask, fGMFactory(NULL), bitmap, true, true);
    SPAWN(QuiltTask, fGMFactory(NULL), bitmap);
    SPAWN(RecordTask, fGMFactory(NULL), bitmap);
    SPAWN(ReplayTask, fGMFactory(NULL), bitmap, false);
    SPAWN(ReplayTask, fGMFactory(NULL), bitmap, true);
    SPAWN(SerializeTask, fGMFactory(NULL), bitmap);

    SPAWN(WriteTask, bitmap);
#undef SPAWN
}
示例#9
0
文件: nqueens.c 项目: prc33/dovetail
TASK_3(int, nqueens, int, n , int, j, char*, a) {
#else
int nqueens(int n, int j, char *a) {
#endif
  // No more queens to place.
  if(n == j) {
    return 1;
  }

  // Try each possible position for queen <j>
  int solutions = 0;
  
  for(int i = 0; i < n; i++) {
#ifdef WOOL
    SPAWN(nqueens_next, n, j, a, i);
#else
    a[j] = i;

    if(ok(j + 1, a)) {
      solutions += nqueens(n, j + 1, a);
    }
#endif
  }

#ifdef WOOL
  for(int i = 0; i < n; i++) {
    solutions += SYNC(nqueens_next);
  }
#endif

  return solutions;
}


#ifdef WOOL
TASK_IMPL_4(int, nqueens_next, int, n, int, j, char*, a, int, i) {
  char *b = (char *) alloca((j + 1) * sizeof(char));

  memcpy(b, a, j * sizeof(char));
  b[j] = i;

  if(ok(j + 1, b)) {
    return CALL(nqueens, n, j + 1, b);
  } else {
    return 0;
  }
}
示例#10
0
文件: skew.c 项目: gburd/wool
TASK_3( int, tree, int, d, int, s, int, n )
{
  if( d>0 ) {
    int r = 1, l = 1, a, b;
    if( s<0 ) {
      r = -s;
    } else {
      l = s;
    }
    SPAWN( tree, d-r, s, n );
    a = CALL( tree, d-l, s, n);
    b = SYNC( tree );
    return a+b;
  } else {
    loop( n );
    return 1;
  }
}
示例#11
0
文件: ldd2bdd.c 项目: trolando/sylvan
TASK_3(MTBDD, bdd_from_ldd, MDD, dd, MDD, bits_dd, uint32_t, firstvar)
{
    /* simple for leaves */
    if (dd == lddmc_false) return mtbdd_false;
    if (dd == lddmc_true) return mtbdd_true;

    MTBDD result;
    /* get from cache */
    /* note: some assumptions about the encoding... */
    if (cache_get3(bdd_from_ldd_id, dd, bits_dd, firstvar, &result)) return result;

    mddnode_t n = LDD_GETNODE(dd);
    mddnode_t nbits = LDD_GETNODE(bits_dd);
    int bits = (int)mddnode_getvalue(nbits);

    /* spawn right, same bits_dd and firstvar */
    mtbdd_refs_spawn(SPAWN(bdd_from_ldd, mddnode_getright(n), bits_dd, firstvar));

    /* call down, with next bits_dd and firstvar */
    MTBDD down = CALL(bdd_from_ldd, mddnode_getdown(n), mddnode_getdown(nbits), firstvar + 2*bits);

    /* encode current value */
    uint32_t val = mddnode_getvalue(n);
    for (int i=0; i<bits; i++) {
        /* encode with high bit first */
        int bit = bits-i-1;
        if (val & (1LL<<i)) down = mtbdd_makenode(firstvar + 2*bit, mtbdd_false, down);
        else down = mtbdd_makenode(firstvar + 2*bit, down, mtbdd_false);
    }

    /* sync right */
    mtbdd_refs_push(down);
    MTBDD right = mtbdd_refs_sync(SYNC(bdd_from_ldd));

    /* take union of current and right */
    mtbdd_refs_push(right);
    result = sylvan_or(down, right);
    mtbdd_refs_pop(2);

    /* put in cache */
    cache_put3(bdd_from_ldd_id, dd, bits_dd, firstvar, result);

    return result;
}
示例#12
0
/*
 * return the optimal solution for n items (first is e) and
 * capacity c. Value so far is v.
 */
TASK_4(int, knapsack, struct item *, e, int, c, int, n, int, v)
{
    int with, without, best;
    double ub;

    /* base case: full knapsack or no items */
    if (c < 0)
        return INT_MIN;

    if (n == 0 || c == 0)
        return v;		/* feasible solution, with value v */

    ub = (double) v + c * e->value / e->weight;

    if (ub < best_so_far) {
        /* prune ! */
        //return INT_MIN;
    }
    /*
     * compute the best solution without the current item in the knapsack
     */
    SPAWN(knapsack, e + 1, c, n - 1, v);

    /* compute the best solution with the current item in the knapsack */
    with = CALL(knapsack, e + 1, c - e->weight, n - 1, v + e->value);

    without = SYNC(knapsack);

    best = with > without ? with : without;

    /*
     * notice the race condition here. The program is still
     * correct, in the sense that the best solution so far
     * is at least best_so_far. Moreover best_so_far gets updated
     * when returning, so eventually it should get the right
     * value. The program is highly non-deterministic.
     */
    //if (best > best_so_far)
    // best_so_far = best;

    return best;
}
示例#13
0
文件: ldd2bdd.c 项目: trolando/sylvan
VOID_TASK_3(compute_highest_action, MDD, dd, MDD, meta, uint32_t*, target)
{
    if (dd == lddmc_true || dd == lddmc_false) return;
    if (meta == lddmc_true) return;

    uint64_t result = 1;
    if (cache_get3(compute_highest_action_id, dd, meta, 0, &result)) return;
    cache_put3(compute_highest_action_id, dd, meta, 0, result);

    /* meta:
     *  0 is skip
     *  1 is read
     *  2 is write
     *  3 is only-read
     *  4 is only-write
     *  5 is action label (at end, before -1)
     * -1 is end
     */

    const mddnode_t n = LDD_GETNODE(dd);
    const mddnode_t nmeta = LDD_GETNODE(meta);
    const uint32_t vmeta = mddnode_getvalue(nmeta);
    if (vmeta == (uint32_t)-1) return;

    SPAWN(compute_highest_action, mddnode_getright(n), meta, target);
    CALL(compute_highest_action, mddnode_getdown(n), mddnode_getdown(nmeta), target);
    SYNC(compute_highest_action);

    if (vmeta == 5) {
        has_actions = 1;
        const uint32_t v = mddnode_getvalue(n);
        while (1) {
            const uint32_t cur = *(volatile uint32_t*)target;
            if (v <= cur) break;
            if (__sync_bool_compare_and_swap(target, cur, v)) break;
        }
    }
}
示例#14
0
文件: ldd2bdd.c 项目: trolando/sylvan
VOID_TASK_2(compute_highest, MDD, dd, uint32_t*, arr)
{
    if (dd == lddmc_true || dd == lddmc_false) return;

    uint64_t result = 1;
    if (cache_get3(compute_highest_id, dd, 0, 0, &result)) return;
    cache_put3(compute_highest_id, dd, 0, 0, result);

    mddnode_t n = LDD_GETNODE(dd);

    SPAWN(compute_highest, mddnode_getright(n), arr);
    CALL(compute_highest, mddnode_getdown(n), arr+1);
    SYNC(compute_highest);

    if (!mddnode_getcopy(n)) {
        const uint32_t v = mddnode_getvalue(n);
        while (1) {
            const uint32_t cur = *(volatile uint32_t*)arr;
            if (v <= cur) break;
            if (__sync_bool_compare_and_swap(arr, cur, v)) break;
        }
    }
}
示例#15
0
文件: uts2-lace.c 项目: fritzo/lace
TASK_2(Result, parTreeSearch, int, depth, Node *, parent) {
  int numChildren, childType;
  counter_t parentHeight = parent->height;

  Result r = { depth, 1, 0 };

  numChildren = uts_numChildren(parent);
  childType   = uts_childType(parent);

  // record number of children in parent
  parent->numChildren = numChildren;
  
  // Recurse on the children
  if (numChildren > 0) {
    int i, j;
    for (i = 0; i < numChildren; i++) {
      Node *child = (Node*)alloca(sizeof(Node));
      child->type = childType;
      child->height = parentHeight + 1;
      child->numChildren = -1;    // not yet determined
      for (j = 0; j < computeGranularity; j++) {
        rng_spawn(parent->state.state, child->state.state, i);
      }
      SPAWN(parTreeSearch, depth+1, child);
    }

    /* Wait a bit */
    struct timespec tim = (struct timespec){0, 100L*numChildren};
    nanosleep(&tim, NULL);

    for (i = 0; i < numChildren; i++) {
      Result c = SYNC(parTreeSearch);
      if (c.maxdepth>r.maxdepth) r.maxdepth = c.maxdepth;
      r.size += c.size;
      r.leaves += c.leaves;
    }
  } else {
示例#16
0
MVMint64 MVM_proc_spawn(MVMThreadContext *tc, MVMObject *argv, MVMString *cwd, MVMObject *env) {
    MVMint64 result = 0, spawn_result = 0;
    uv_process_t *process = calloc(1, sizeof(uv_process_t));
    uv_process_options_t process_options = {0};
    uv_stdio_container_t process_stdio[3];
    int i;

    char   * const      _cwd = MVM_string_utf8_encode_C_string(tc, cwd);
    const MVMuint64     size = MVM_repr_elems(tc, env);
    MVMIter * const     iter = (MVMIter *)MVM_iter(tc, env);
    char              **_env = malloc((size + 1) * sizeof(char *));
    const MVMuint64  arg_size = MVM_repr_elems(tc, argv);
    char             **args = malloc((arg_size + 1) * sizeof(char *));
    MVMRegister        reg;

    i = 0;
    while(i < arg_size) {
        REPR(argv)->pos_funcs.at_pos(tc, STABLE(argv), argv, OBJECT_BODY(argv), i, &reg, MVM_reg_obj);
        args[i++] = MVM_string_utf8_encode_C_string(tc, MVM_repr_get_str(tc, reg.o));
    }
    args[arg_size] = NULL;

    INIT_ENV();
    SPAWN(arg_size ? args[0] : NULL);
    FREE_ENV();

    free(_cwd);

    i = 0;
    while(args[i])
        free(args[i++]);

    free(args);

    return result;
}
示例#17
0
/*****************************************************************************
 **
 ** OptimizedStrassenMultiply
 **
 ** For large matrices A, B, and C of size MatrixSize * MatrixSize this
 ** function performs the operation C = A x B efficiently.
 **
 ** INPUT:
 **    C = (*C WRITE) Address of top left element of matrix C.
 **    A = (*A IS READ ONLY) Address of top left element of matrix A.
 **    B = (*B IS READ ONLY) Address of top left element of matrix B.
 **    MatrixSize = Size of matrices (for n*n matrix, MatrixSize = n)
 **    RowWidthA = Number of elements in memory between A[x,y] and A[x,y+1]
 **    RowWidthB = Number of elements in memory between B[x,y] and B[x,y+1]
 **    RowWidthC = Number of elements in memory between C[x,y] and C[x,y+1]
 **
 ** OUTPUT:
 **    C = (*C WRITE) Matrix C contains A x B. (Initial value of *C undefined.)
 **
 *****************************************************************************/
VOID_TASK_7(OptimizedStrassenMultiply, REAL *, C, REAL *, A, REAL *, B,
        unsigned, MatrixSize,
        unsigned, RowWidthC,
        unsigned, RowWidthA,
        unsigned, RowWidthB
        )
{
    unsigned QuadrantSize = MatrixSize >> 1; /* MatixSize / 2 */
    unsigned QuadrantSizeInBytes = sizeof(REAL) * QuadrantSize * QuadrantSize
        + 32;
    unsigned Column, Row;

    /************************************************************************
     ** For each matrix A, B, and C, we'll want pointers to each quandrant
     ** in the matrix. These quandrants will be addressed as follows:
     **  --        --
     **  | A11  A12 |
     **  |          |
     **  | A21  A22 |
     **  --        --
     ************************************************************************/
    REAL /* *A11, *B11, *C11, */ *A12, *B12, *C12,
         *A21, *B21, *C21, *A22, *B22, *C22;

    REAL *S1,*S2,*S3,*S4,*S5,*S6,*S7,*S8,*M2,*M5,*T1sMULT;
#define T2sMULT C22
#define NumberOfVariables 11

    PTR TempMatrixOffset = 0;
    PTR MatrixOffsetA = 0;
    PTR MatrixOffsetB = 0;

    char *Heap;
    void *StartHeap;

    /* Distance between the end of a matrix row and the start of the next row */
    PTR RowIncrementA = ( RowWidthA - QuadrantSize ) << 3;
    PTR RowIncrementB = ( RowWidthB - QuadrantSize ) << 3;
    PTR RowIncrementC = ( RowWidthC - QuadrantSize ) << 3;


    if (MatrixSize <= SizeAtWhichDivideAndConquerIsMoreEfficient) {

        MultiplyByDivideAndConquer(C, A, B,
                MatrixSize,
                RowWidthC,
                RowWidthA,
                RowWidthB,
                0);
        return;
    }

    /* Initialize quandrant matrices */
#define A11 A
#define B11 B
#define C11 C
    A12 = A11 + QuadrantSize;
    B12 = B11 + QuadrantSize;
    C12 = C11 + QuadrantSize;
    A21 = A + (RowWidthA * QuadrantSize);
    B21 = B + (RowWidthB * QuadrantSize);
    C21 = C + (RowWidthC * QuadrantSize);
    A22 = A21 + QuadrantSize;
    B22 = B21 + QuadrantSize;
    C22 = C21 + QuadrantSize;

    /* Allocate Heap Space Here */
    StartHeap = Heap = malloc(QuadrantSizeInBytes * NumberOfVariables);
    /* ensure that heap is on cache boundary */
    if ( ((PTR) Heap) & 31)
        Heap = (char*) ( ((PTR) Heap) + 32 - ( ((PTR) Heap) & 31) );

    /* Distribute the heap space over the variables */
    S1 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S2 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S3 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S4 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S5 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S6 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S7 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    S8 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    M2 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    M5 = (REAL*) Heap; Heap += QuadrantSizeInBytes;
    T1sMULT = (REAL*) Heap; Heap += QuadrantSizeInBytes;

    /***************************************************************************
     ** Step through all columns row by row (vertically)
     ** (jumps in memory by RowWidth => bad locality)
     ** (but we want the best locality on the innermost loop)
     ***************************************************************************/
    for (Row = 0; Row < QuadrantSize; Row++) {

        /*************************************************************************
         ** Step through each row horizontally (addressing elements in each column)
         ** (jumps linearly througn memory => good locality)
         *************************************************************************/
        for (Column = 0; Column < QuadrantSize; Column++) {

            /***********************************************************
             ** Within this loop, the following holds for MatrixOffset:
             ** MatrixOffset = (Row * RowWidth) + Column
             ** (note: that the unit of the offset is number of reals)
             ***********************************************************/
            /* Element of Global Matrix, such as A, B, C */
#define E(Matrix)   (* (REAL*) ( ((PTR) Matrix) + TempMatrixOffset ) )
#define EA(Matrix)  (* (REAL*) ( ((PTR) Matrix) + MatrixOffsetA ) )
#define EB(Matrix)  (* (REAL*) ( ((PTR) Matrix) + MatrixOffsetB ) )

            /* FIXME - may pay to expand these out - got higher speed-ups below */
            /* S4 = A12 - ( S2 = ( S1 = A21 + A22 ) - A11 ) */
            E(S4) = EA(A12) - ( E(S2) = ( E(S1) = EA(A21) + EA(A22) ) - EA(A11) );

            /* S8 = (S6 = B22 - ( S5 = B12 - B11 ) ) - B21 */
            E(S8) = ( E(S6) = EB(B22) - ( E(S5) = EB(B12) - EB(B11) ) ) - EB(B21);

            /* S3 = A11 - A21 */
            E(S3) = EA(A11) - EA(A21);

            /* S7 = B22 - B12 */
            E(S7) = EB(B22) - EB(B12);

            TempMatrixOffset += sizeof(REAL);
            MatrixOffsetA += sizeof(REAL);
            MatrixOffsetB += sizeof(REAL);
        } /* end row loop*/

        MatrixOffsetA += RowIncrementA;
        MatrixOffsetB += RowIncrementB;
    } /* end column loop */

    /* M2 = A11 x B11 */
    SPAWN(OptimizedStrassenMultiply, M2, A11, B11, QuadrantSize,
            QuadrantSize, RowWidthA, RowWidthB);

    /* M5 = S1 * S5 */
    SPAWN(OptimizedStrassenMultiply, M5, S1, S5, QuadrantSize,
            QuadrantSize, QuadrantSize, QuadrantSize);

    /* Step 1 of T1 = S2 x S6 + M2 */
    SPAWN(OptimizedStrassenMultiply, T1sMULT, S2, S6,  QuadrantSize,
            QuadrantSize, QuadrantSize, QuadrantSize);

    /* Step 1 of T2 = T1 + S3 x S7 */
    SPAWN(OptimizedStrassenMultiply, C22, S3, S7, QuadrantSize,
            RowWidthC /*FIXME*/, QuadrantSize, QuadrantSize);

    /* Step 1 of C11 = M2 + A12 * B21 */
    SPAWN(OptimizedStrassenMultiply, C11, A12, B21, QuadrantSize,
            RowWidthC, RowWidthA, RowWidthB);

    /* Step 1 of C12 = S4 x B22 + T1 + M5 */
    SPAWN(OptimizedStrassenMultiply, C12, S4, B22, QuadrantSize,
            RowWidthC, QuadrantSize, RowWidthB);

    /* Step 1 of C21 = T2 - A22 * S8 */
    SPAWN(OptimizedStrassenMultiply, C21, A22, S8, QuadrantSize,
            RowWidthC, RowWidthA, QuadrantSize);

    /**********************************************
     ** Synchronization Point
     **********************************************/
    SYNC(OptimizedStrassenMultiply);
    SYNC(OptimizedStrassenMultiply);
    SYNC(OptimizedStrassenMultiply);
    SYNC(OptimizedStrassenMultiply);
    SYNC(OptimizedStrassenMultiply);
    SYNC(OptimizedStrassenMultiply);
    SYNC(OptimizedStrassenMultiply);


    /***************************************************************************
     ** Step through all columns row by row (vertically)
     ** (jumps in memory by RowWidth => bad locality)
     ** (but we want the best locality on the innermost loop)
     ***************************************************************************/
    for (Row = 0; Row < QuadrantSize; Row++) {

        /*************************************************************************
         ** Step through each row horizontally (addressing elements in each column)
         ** (jumps linearly througn memory => good locality)
         *************************************************************************/
        for (Column = 0; Column < QuadrantSize; Column += 4) {
            REAL LocalM5_0 = *(M5);
            REAL LocalM5_1 = *(M5+1);
            REAL LocalM5_2 = *(M5+2);
            REAL LocalM5_3 = *(M5+3);
            REAL LocalM2_0 = *(M2);
            REAL LocalM2_1 = *(M2+1);
            REAL LocalM2_2 = *(M2+2);
            REAL LocalM2_3 = *(M2+3);
            REAL T1_0 = *(T1sMULT) + LocalM2_0;
            REAL T1_1 = *(T1sMULT+1) + LocalM2_1;
            REAL T1_2 = *(T1sMULT+2) + LocalM2_2;
            REAL T1_3 = *(T1sMULT+3) + LocalM2_3;
            REAL T2_0 = *(C22) + T1_0;
            REAL T2_1 = *(C22+1) + T1_1;
            REAL T2_2 = *(C22+2) + T1_2;
            REAL T2_3 = *(C22+3) + T1_3;
            (*(C11))   += LocalM2_0;
            (*(C11+1)) += LocalM2_1;
            (*(C11+2)) += LocalM2_2;
            (*(C11+3)) += LocalM2_3;
            (*(C12))   += LocalM5_0 + T1_0;
            (*(C12+1)) += LocalM5_1 + T1_1;
            (*(C12+2)) += LocalM5_2 + T1_2;
            (*(C12+3)) += LocalM5_3 + T1_3;
            (*(C22))   = LocalM5_0 + T2_0;
            (*(C22+1)) = LocalM5_1 + T2_1;
            (*(C22+2)) = LocalM5_2 + T2_2;
            (*(C22+3)) = LocalM5_3 + T2_3;
            (*(C21  )) = (- *(C21  )) + T2_0;
            (*(C21+1)) = (- *(C21+1)) + T2_1;
            (*(C21+2)) = (- *(C21+2)) + T2_2;
            (*(C21+3)) = (- *(C21+3)) + T2_3;
            M5 += 4;
            M2 += 4;
            T1sMULT += 4;
            C11 += 4;
            C12 += 4;
            C21 += 4;
            C22 += 4;
        }

        C11 = (REAL*) ( ((PTR) C11 ) + RowIncrementC);
        C12 = (REAL*) ( ((PTR) C12 ) + RowIncrementC);
        C21 = (REAL*) ( ((PTR) C21 ) + RowIncrementC);
        C22 = (REAL*) ( ((PTR) C22 ) + RowIncrementC);
    }

    free(StartHeap);

}
示例#18
0
int
main (int argc, char **argv)
{
  int i;
  char cwdev [128], *devptr;
  int devlen;
  char *cwd = getcwd (0, 1024);

  devptr = strchr (cwd, ':');
  devlen = (devptr - cwd) + 1;
  strncpy (cwdev, cwd, devlen);
  cwdev [devlen] = '\0';

  search_dirs = xstrdup (system_search_dirs);
  defines = xstrdup (default_defines);

  addarg ("cc");
  preprocess_args (&argc , argv);
  process_args (&argc , argv);

  if (strlen (search_dirs) > 0)
    {
      addarg ("/include=(");
      addarg (search_dirs);
      addarg (")");
    }

  if (strlen (defines) > 0)
    {
      addarg ("/define=(");
      addarg (defines);
      addarg (")");
    }

  for (i = 1; i < argc; i++)
    {
      int arg_len = strlen (argv[i]);

      if (strcmp (argv[i], "-o") == 0)
	i++;
      else if (strcmp (argv[i], "-v" ) == 0
	       || strcmp (argv[i], "-E") == 0
	       || strcmp (argv[i], "-c") == 0
	       || strncmp (argv[i], "-g", 2 ) == 0
	       || strncmp (argv[i], "-O", 2 ) == 0
	       || strcmp (argv[i], "-save-temps") == 0
	       || (arg_len > 2 && strncmp (argv[i], "-I", 2) == 0)
	       || (arg_len > 2 && strncmp (argv[i], "-D", 2) == 0))
	;

      /* Unix style file specs and VMS style switches look alike, so assume
	 an arg consisting of one and only one slash, and that being first, is
	 really a switch.  */
      else if ((argv[i][0] == '/') && (strchr (&argv[i][1], '/') == 0))
	addarg (argv[i]);
      else
	{
	  /* Assume filename arg */
	  char buff [256], *ptr;

	  ptr = to_host_file_spec (argv[i]);
	  arg_len = strlen (ptr);

	  if (ptr[0] == '[')
	    sprintf (buff, "%s%s", cwdev, ptr);
	  else if (strchr (ptr, ':'))
	    sprintf (buff, "%s", ptr);
	  else
	    sprintf (buff, "%s%s", cwd, ptr);

	  ptr = xstrdup (buff);
	  addarg (ptr);
	}
    }

  addarg (NULL);

  if (verbose)
    {
      int i;

      for (i = 0; i < comp_arg_index; i++)
	printf ("%s ", comp_args [i]);

      putchar ('\n');
    }

  {
    int i;
    int len = 0;

    for (i = 0; comp_args[i]; i++)
      len = len + strlen (comp_args[i]) + 1;

    {
      char *allargs = (char *) alloca (len + 1);
      Descr cmd;
      int status;
      int status1 = 1;

      for (i = 0; i < len + 1; i++)
	allargs [i] = 0;

      for (i = 0; comp_args [i]; i++)
	{
	  strcat (allargs, comp_args [i]);
	  strcat (allargs, " ");
	}

      cmd.adr = allargs;
      cmd.len = len;
      cmd.mbz = 0;

      i = LIB$SPAWN (&cmd, 0, 0, 0, 0, 0, &status);

      if ((i & 1) != 1)
	{
	  LIB$SIGNAL (i);
	  exit (1);
	}

      if ((status & 1) == 1 && (status1 & 1) == 1)
	exit (0);

      exit (1);
    }
  }
}
示例#19
0
文件: driver.c 项目: YIwama/bcb
int
pload (int tbl)
{
	int c = 0, i, status;
	
	if (verbose > 0)
	{
		fprintf (stderr, "Starting %d children to load %s",
			children, tdefs[tbl].comment);
	}
	for (c = 0; c < children; c++)
	{
		pids[c] = SPAWN ();
		if (pids[c] == -1)
		{
			perror ("Child loader not created");
			kill_load ();
			exit (-1);
		}
		else if (pids[c] == 0)	/* CHILD */
		{
			SET_HANDLER (stop_proc);
			verbose = 0;
			partial (tbl, c+1);
			exit (0);
		}
		else if (verbose > 0)			/* PARENT */
			fprintf (stderr, ".");
	}
	
	if (verbose > 0)
		fprintf (stderr, "waiting...");

	c = children;
	while (c)
	{
		i = WAIT (&status, pids[c - 1]);
		if (i == -1 && children)
		{
			if (errno == ECHILD)
				fprintf (stderr, "\nCould not wait on pid %d\n", pids[c - 1]);
			else if (errno == EINTR)
				fprintf (stderr, "\nProcess %d stopped abnormally\n", pids[c - 1]);
			else if (errno == EINVAL)
				fprintf (stderr, "\nProgram bug\n");
		}
		if (! WIFEXITED(status)) {
			(void) fprintf(stderr, "\nProcess %d: ", i);
			if (WIFSIGNALED(status)) {
				(void) fprintf(stderr, "rcvd signal %d\n",
					WTERMSIG(status));
				} else if (WIFSTOPPED(status)) {
				(void) fprintf(stderr, "stopped, signal %d\n",
					WSTOPSIG(status));
					}
				
			}
		c--;
	}

	if (verbose > 0)
		fprintf (stderr, "done\n");
	return (0);
}
示例#20
0
文件: ldd2bdd.c 项目: trolando/sylvan
TASK_4(MTBDD, bdd_from_ldd_rel, MDD, dd, MDD, bits_dd, uint32_t, firstvar, MDD, meta)
{
    if (dd == lddmc_false) return mtbdd_false;
    if (dd == lddmc_true) return mtbdd_true;
    assert(meta != lddmc_false && meta != lddmc_true);

    /* meta:
     * -1 is end
     *  0 is skip
     *  1 is read
     *  2 is write
     *  3 is only-read
     *  4 is only-write
     */

    MTBDD result;
    /* note: assumptions */
    if (cache_get4(bdd_from_ldd_rel_id, dd, bits_dd, firstvar, meta, &result)) return result;

    const mddnode_t n = LDD_GETNODE(dd);
    const mddnode_t nmeta = LDD_GETNODE(meta);
    const mddnode_t nbits = LDD_GETNODE(bits_dd);
    const int bits = (int)mddnode_getvalue(nbits);

    const uint32_t vmeta = mddnode_getvalue(nmeta);
    assert(vmeta != (uint32_t)-1);

    if (vmeta == 0) {
        /* skip level */
        result = bdd_from_ldd_rel(dd, mddnode_getdown(nbits), firstvar + 2*bits, mddnode_getdown(nmeta));
    } else if (vmeta == 1) {
        /* read level */
        assert(!mddnode_getcopy(n));  // do not process read copy nodes for now
        assert(mddnode_getright(n) != mtbdd_true);

        /* spawn right */
        mtbdd_refs_spawn(SPAWN(bdd_from_ldd_rel, mddnode_getright(n), bits_dd, firstvar, meta));

        /* compute down with same bits / firstvar */
        MTBDD down = bdd_from_ldd_rel(mddnode_getdown(n), bits_dd, firstvar, mddnode_getdown(nmeta));
        mtbdd_refs_push(down);

        /* encode read value */
        uint32_t val = mddnode_getvalue(n);
        MTBDD part = mtbdd_true;
        for (int i=0; i<bits; i++) {
            /* encode with high bit first */
            int bit = bits-i-1;
            if (val & (1LL<<i)) part = mtbdd_makenode(firstvar + 2*bit, mtbdd_false, part);
            else part = mtbdd_makenode(firstvar + 2*bit, part, mtbdd_false);
        }

        /* intersect read value with down result */
        mtbdd_refs_push(part);
        down = sylvan_and(part, down);
        mtbdd_refs_pop(2);

        /* sync right */
        mtbdd_refs_push(down);
        MTBDD right = mtbdd_refs_sync(SYNC(bdd_from_ldd_rel));

        /* take union of current and right */
        mtbdd_refs_push(right);
        result = sylvan_or(down, right);
        mtbdd_refs_pop(2);
    } else if (vmeta == 2 || vmeta == 4) {
        /* write or only-write level */

        /* spawn right */
        assert(mddnode_getright(n) != mtbdd_true);
        mtbdd_refs_spawn(SPAWN(bdd_from_ldd_rel, mddnode_getright(n), bits_dd, firstvar, meta));

        /* get recursive result */
        MTBDD down = CALL(bdd_from_ldd_rel, mddnode_getdown(n), mddnode_getdown(nbits), firstvar + 2*bits, mddnode_getdown(nmeta));

        if (mddnode_getcopy(n)) {
            /* encode a copy node */
            for (int i=0; i<bits; i++) {
                int bit = bits-i-1;
                MTBDD low = mtbdd_makenode(firstvar + 2*bit + 1, down, mtbdd_false);
                mtbdd_refs_push(low);
                MTBDD high = mtbdd_makenode(firstvar + 2*bit + 1, mtbdd_false, down);
                mtbdd_refs_pop(1);
                down = mtbdd_makenode(firstvar + 2*bit, low, high);
            }
        } else {
            /* encode written value */
            uint32_t val = mddnode_getvalue(n);
            for (int i=0; i<bits; i++) {
                /* encode with high bit first */
                int bit = bits-i-1;
                if (val & (1LL<<i)) down = mtbdd_makenode(firstvar + 2*bit + 1, mtbdd_false, down);
                else down = mtbdd_makenode(firstvar + 2*bit + 1, down, mtbdd_false);
            }
        }

        /* sync right */
        mtbdd_refs_push(down);
        MTBDD right = mtbdd_refs_sync(SYNC(bdd_from_ldd_rel));

        /* take union of current and right */
        mtbdd_refs_push(right);
        result = sylvan_or(down, right);
        mtbdd_refs_pop(2);
    } else if (vmeta == 3) {
        /* only-read level */
        assert(!mddnode_getcopy(n));  // do not process read copy nodes

        /* spawn right */
        mtbdd_refs_spawn(SPAWN(bdd_from_ldd_rel, mddnode_getright(n), bits_dd, firstvar, meta));

        /* get recursive result */
        MTBDD down = CALL(bdd_from_ldd_rel, mddnode_getdown(n), mddnode_getdown(nbits), firstvar + 2*bits, mddnode_getdown(nmeta));

        /* encode read value */
        uint32_t val = mddnode_getvalue(n);
        for (int i=0; i<bits; i++) {
            /* encode with high bit first */
            int bit = bits-i-1;
            /* only-read, so write same value */
            if (val & (1LL<<i)) down = mtbdd_makenode(firstvar + 2*bit + 1, mtbdd_false, down);
            else down = mtbdd_makenode(firstvar + 2*bit + 1, down, mtbdd_false);
            if (val & (1LL<<i)) down = mtbdd_makenode(firstvar + 2*bit, mtbdd_false, down);
            else down = mtbdd_makenode(firstvar + 2*bit, down, mtbdd_false);
        }

        /* sync right */
        mtbdd_refs_push(down);
        MTBDD right = mtbdd_refs_sync(SYNC(bdd_from_ldd_rel));

        /* take union of current and right */
        mtbdd_refs_push(right);
        result = sylvan_or(down, right);
        mtbdd_refs_pop(2);
    } else if (vmeta == 5) {
        assert(!mddnode_getcopy(n));  // not allowed!

        /* we assume this is the last value */
        result = mtbdd_true;

        /* encode action value */
        uint32_t val = mddnode_getvalue(n);
        for (int i=0; i<actionbits; i++) {
            /* encode with high bit first */
            int bit = actionbits-i-1;
            /* only-read, so write same value */
            if (val & (1LL<<i)) result = mtbdd_makenode(1000000 + bit, mtbdd_false, result);
            else result = mtbdd_makenode(1000000 + bit, result, mtbdd_false);
        }
    } else {
        assert(vmeta <= 5);
    }

    cache_put4(bdd_from_ldd_rel_id, dd, bits_dd, firstvar, meta, result);

    return result;
}
示例#21
0
VOID_TASK_2(quicksort, int *, array, int, length) {
#else
void quicksort(int *array, int length) {
#endif
  if(length < 2) {
    return;
  }

  int pivot = array[length / 2];
  int left = 0;
  int right = length - 1;

  while(left <= right) {
    int left_data = array[left];

    if(left_data < pivot) {
      left++;
      continue;
    }

    int right_data = array[right];

    if(pivot < right_data) {
      right--;
      continue;
    }

    array[left++] = right_data;
    array[right--] = left_data;
  }

#ifdef WOOL
  SPAWN(quicksort, array, right + 1);
  CALL(quicksort, array + left, length - left);
  SYNC(quicksort);
#else
  quicksort(array, right + 1);
  quicksort(array + left, length - left);
#endif
}

int main(int argc, char **argv) {
#ifdef WOOL
  argc = wool_init(argc, argv);
#endif

  if(argc < 2) {
#ifdef WOOL
    fprintf(stderr, "Usage: quicksort <woolopt> <n>\n");
#else
    fprintf(stderr, "Usage: quicksort <n>\n");
#endif
    return 1;
  }

  int  n    = atoi(argv[1]);
  int *data = (int *) malloc(n * sizeof(int));

  for(int i = 0; i < n; i++) {
    data[i] = rand();
  }

#ifdef WOOL
  CALL(quicksort, data, n);
  wool_fini();
#else
  quicksort(data, n);
#endif

  printf("[ %d, %d, %d, %d, %d ... %d, %d, %d, %d, %d ] (len=%d)\n",
         data[0], data[1], data[2], data[3], data[4],
         data[n-5], data[n-4], data[n-3], data[n-2], data[n-1],
         n);

  return 0;
}
示例#22
0
void CpuGMTask::draw() {
    SkBitmap bitmap;
    AllocatePixels(fColorType, fGM->getISize().width(), fGM->getISize().height(), &bitmap);

    SkCanvas canvas(bitmap);
    canvas.concat(fGM->getInitialTransform());
    fGM->draw(&canvas);
    canvas.flush();

#define SPAWN(ChildTask, ...) this->spawnChild(SkNEW_ARGS(ChildTask, (*this, __VA_ARGS__)))
    SPAWN(ExpectationsTask, fExpectations, bitmap);

    SPAWN(PipeTask, fGMFactory(NULL), bitmap, PipeTask::kInProcess_Mode);
    SPAWN(PipeTask, fGMFactory(NULL), bitmap, PipeTask::kCrossProcess_Mode);
    SPAWN(PipeTask, fGMFactory(NULL), bitmap, PipeTask::kSharedAddress_Mode);
    SPAWN(QuiltTask, fGMFactory(NULL), bitmap);
    SPAWN(RecordTask, fGMFactory(NULL), bitmap, RecordTask::kOptimize_Mode);
    SPAWN(RecordTask, fGMFactory(NULL), bitmap, RecordTask::kNoOptimize_Mode);
    SPAWN(ReplayTask, fGMFactory(NULL), bitmap, ReplayTask::kNormal_Mode);
    SPAWN(ReplayTask, fGMFactory(NULL), bitmap, ReplayTask::kRTree_Mode);
    SPAWN(SerializeTask, fGMFactory(NULL), bitmap);

    SPAWN(WriteTask, bitmap);
#undef SPAWN
}