コード例 #1
0
ファイル: NewPoissonOp.cpp プロジェクト: dtgraves/EBAMRCNS
void NewPoissonOp::residual(  FArrayBox& a_lhs, const FArrayBox& a_phi,
                              const FArrayBox& a_rhs, bool a_homogeneous)
{
  applyOp(a_lhs, a_phi, a_homogeneous);
  a_lhs*=-1.0;
  incr(a_lhs, a_rhs, 1);
}
コード例 #2
0
ファイル: ampiOneSided.C プロジェクト: quinoacomputing/quinoa
int
win_obj::accumulate(void *orgaddr, int orgcnt, MPI_Datatype orgtype,
                    MPI_Aint targdisp, int targcnt,
                    MPI_Datatype targtype, MPI_Op op) {
    applyOp(targtype, op, targcnt, (void*)((int*)baseAddr+targdisp) , (void*)orgaddr);
    return WIN_SUCCESS;
}
コード例 #3
0
inline static void Execute(void* Arg) {
    ThreadState lobject_lock;
    long i, rnum;
    volatile long j;
    long id = (long) Arg;

    setThreadId(id);
    _thread_pin(id);
    simSRandom(id + 1L);
    threadStateInit(&lobject_lock, &object_lock, (int)id);
    if (id == N_THREADS - 1)
        d1 = getTimeMillis();
    // Synchronization point
    int rc = pthread_barrier_wait(&barr);
    if (rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) {
        printf("Could not wait on barrier\n");
        exit(-1);
    }
    start_cpu_counters(id);
    for (i = 0; i < RUNS; i++) {
        // perform a fetchAndMultiply operation
        applyOp(&object_lock, &lobject_lock, fetchAndMultiply, (ArgVal) id, id);
        rnum = simRandomRange(1, MAX_WORK);
        for (j = 0; j < rnum; j++)
            ; 
    }
    stop_cpu_counters(id);
}
コード例 #4
0
ファイル: EBPoissonOp.cpp プロジェクト: dtgraves/EBAMRCNS
void EBPoissonOp::
residual(LevelData<EBCellFAB>&       a_residual,
         const LevelData<EBCellFAB>& a_phi,
         const LevelData<EBCellFAB>& a_rhs,
         bool                        a_homogeneousPhysBC)
{
  CH_TIME("EBPoissonOp::residual");
  //this is a multigrid operator so only homogeneous CF BC
  //and null coar level
  CH_assert(a_residual.ghostVect() == m_ghostCellsRHS);
  CH_assert(a_phi.ghostVect() == m_ghostCellsPhi);
  DataIterator dit = a_residual.dataIterator();
  applyOp(a_residual,a_phi, a_homogeneousPhysBC, dit );
  axby(a_residual,a_residual,a_rhs,-1.0, 1.0);
}
コード例 #5
0
ファイル: apl.C プロジェクト: Henry/BuddKaminInterpreters
void APLUnaryFunction::applyWithArgs
(
    Expr& target,
    ListNode* args,
    Environment* rho
)
{
    APLValue* arg1 = args->at(0)->isAPLValue();
    if (!arg1)
    {
        target = error("non-apl value given to unary function");
        return;
    }
    applyOp(target, arg1);
}
コード例 #6
0
/*
* Prototype: int evaluateExpression();

* Description: This method will evaluate the entered expression.

* How to call: This is method is called in parseExpression() to evaluate the expression.
ex: evaluateExpression();

* Pre-Conditions:
- A Calculator object must have been built.
- The expression must have been parsed.
- The expression must have been valid.

* Post-Conditions:
- This method returns an int as an error code.
0 = Success
2 = Not enough values to evaluate (e.g., 3++1)
3 = Too many values and not enough operators (e.g., 3(2+1), one must explicitly denote multiplication with '*'.
4 = Division by zero (e.g., 3/0)
*/
int Calculator::evaluateExpression()
{
	Queue<std::string> output2 = output; // Copy output into new queue so that printRPN() works
	while (!output2.empty())
	{
		const std::string token = output2.front();
		output2.dequeue();

		if (!isOperator(token))
			numbers.push(token);
		else
		{
			if (numbers.size() < 2)
				return 2; // Too few values
			else
			{
				double num1 = strtod(numbers.top().c_str(), NULL); // Rear number
				numbers.pop();
				double num2 = std::strtod(numbers.top().c_str(), NULL); // Leading number
				numbers.pop();

				if (token == "/" && num1 == 0)
					return 4; // Division by zero

				double result = applyOp(num2, num1, token);
				numbers.push(std::to_string(result));
			}
		}
	}
	if (numbers.size() == 1)
	{
		answer = std::strtod(numbers.top().c_str(), NULL);
		numbers.pop();
		return 0; // Success!
	}
	else
		return 3; // Too many values
}
コード例 #7
0
ファイル: apl.C プロジェクト: Henry/BuddKaminInterpreters
void APLBinaryFunction::applyWithArgs
(
    Expr& target,
    ListNode* args,
    Environment* rho
)
{
    if (args->length() != 2)
    {
        target = error("binary function given other than 2 arguments");
        return;
    }

    APLValue* arg1 = args->at(0)->isAPLValue();
    APLValue* arg2 = args->at(1)->isAPLValue();
    if ((!arg1) || (!arg2))
    {
        target = error("non-apl value given to binary function");
        return;
    }

    applyOp(target, arg1, arg2);
}
コード例 #8
0
ファイル: rs_sync.cpp プロジェクト: osheroff/mongo
    bool replset::InitialSync::oplogApplication(OplogReader& r, const Member* source,
        const OpTime& applyGTE, const OpTime& minValid) {

        const string hn = source->fullName();
        try {
            r.tailingQueryGTE( rsoplog, applyGTE );
            if ( !r.haveCursor() ) {
                log() << "replSet initial sync oplog query error" << rsLog;
                return false;
            }

            {
                if( !r.more() ) {
                    sethbmsg("replSet initial sync error reading remote oplog");
                    log() << "replSet initial sync error remote oplog (" << rsoplog << ") on host " << hn << " is empty?" << rsLog;
                    return false;
                }
                bo op = r.next();
                OpTime t = op["ts"]._opTime();
                r.putBack(op);

                if( op.firstElementFieldName() == string("$err") ) {
                    log() << "replSet initial sync error querying " << rsoplog << " on " << hn << " : " << op.toString() << rsLog;
                    return false;
                }

                uassert( 13508 , str::stream() << "no 'ts' in first op in oplog: " << op , !t.isNull() );
                if( t > applyGTE ) {
                    sethbmsg(str::stream() << "error " << hn << " oplog wrapped during initial sync");
                    log() << "replSet initial sync expected first optime of " << applyGTE << rsLog;
                    log() << "replSet initial sync but received a first optime of " << t << " from " << hn << rsLog;
                    return false;
                }

                sethbmsg(str::stream() << "initial oplog application from " << hn << " starting at "
                         << t.toStringPretty() << " to " << minValid.toStringPretty());
            }
        }
        catch(DBException& e) {
            log() << "replSet initial sync failing: " << e.toString() << rsLog;
            return false;
        }

        /* we lock outside the loop to avoid the overhead of locking on every operation. */
        writelock lk("");

        // todo : use exhaust
        OpTime ts;
        time_t start = time(0);
        unsigned long long n = 0;
        int fails = 0;
        while( ts < minValid ) {
            try {
                // There are some special cases with initial sync (see the catch block), so we
                // don't want to break out of this while until we've reached minvalid. Thus, we'll
                // keep trying to requery.
                if( !r.more() ) {
                    OCCASIONALLY log() << "replSet initial sync oplog: no more records" << endl;
                    sleepsecs(1);

                    r.resetCursor();
                    r.tailingQueryGTE(rsoplog, theReplSet->lastOpTimeWritten);
                    if ( !r.haveCursor() ) {
                        if (fails++ > 30) {
                            log() << "replSet initial sync tried to query oplog 30 times, giving up" << endl;
                            return false;
                        }
                    }

                    continue;
                }

                BSONObj o = r.nextSafe(); /* note we might get "not master" at some point */
                ts = o["ts"]._opTime();

                {
                    if( (source->state() != MemberState::RS_PRIMARY &&
                            source->state() != MemberState::RS_SECONDARY) ||
                            replSetForceInitialSyncFailure ) {

                        int f = replSetForceInitialSyncFailure;
                        if( f > 0 ) {
                            replSetForceInitialSyncFailure = f-1;
                            log() << "replSet test code invoked, replSetForceInitialSyncFailure" << rsLog;
                            throw DBException("forced error",0);
                        }
                        log() << "replSet we are now primary" << rsLog;
                        throw DBException("primary changed",0);
                    }

                    applyOp(o, applyGTE);
                }

                if ( ++n % 1000 == 0 ) {
                    time_t now = time(0);
                    if (now - start > 10) {
                        // simple progress metering
                        log() << "replSet initialSyncOplogApplication applied " << n << " operations, synced to "
                              << ts.toStringPretty() << rsLog;
                        start = now;
                    }
                }

                getDur().commitIfNeeded();
            }
            catch (DBException& e) {
                // Skip duplicate key exceptions.
                // These are relatively common on initial sync: if a document is inserted
                // early in the clone step, the insert will be replayed but the document
                // will probably already have been cloned over.
                if( e.getCode() == 11000 || e.getCode() == 11001 || e.getCode() == 12582) {
                    continue;
                }
                
                // handle cursor not found (just requery)
                if( e.getCode() == 13127 ) {
                    log() << "replSet requerying oplog after cursor not found condition, ts: " << ts.toStringPretty() << endl;
                    r.resetCursor();
                    r.tailingQueryGTE(rsoplog, ts);
                    if( r.haveCursor() ) {
                        continue;
                    }
                }

                // TODO: handle server restart

                if( ts <= minValid ) {
                    // didn't make it far enough
                    log() << "replSet initial sync failing, error applying oplog : " << e.toString() << rsLog;
                    return false;
                }

                // otherwise, whatever, we'll break out of the loop and catch
                // anything that's really wrong in syncTail
            }
        }
        return true;
    }