Esempio n. 1
0
Camera::Camera()
{
    eye = XMVectorSet(0,0,0,0);
    theta = 0;
    phi = 0;
    BuildMatrices();
}
        //----------------------------------------------------------
        /// Build Matrices
        //----------------------------------------------------------
        void SkinnedAnimationGroup::BuildMatrices(s32 indwCurrentParent, const Core::Matrix4& inParentMatrix)
        {
            const std::vector<SkeletonNodeCUPtr>& nodes = mpSkeleton->GetNodes();
			u32 currIndex = 0;
			for (auto it = nodes.begin(); it != nodes.end(); ++it)
			{
				if ((*it)->mdwParentIndex == indwCurrentParent)
				{
					//get the world translation and orientation
					Core::Matrix4 localMat;
                    if(mCurrentAnimationData->m_nodeTranslations.empty() == false)
                    {
						localMat = Core::Matrix4::CreateTransform(mCurrentAnimationData->m_nodeTranslations[currIndex], mCurrentAnimationData->m_nodeScales[currIndex], mCurrentAnimationData->m_nodeOrientations[currIndex]);
                    }
					
					//convert to matrix and store
					mCurrentAnimationMatrices[currIndex] =  localMat * inParentMatrix;
					
					//Apply to all children
					BuildMatrices(currIndex, mCurrentAnimationMatrices[currIndex]);
				}
                
				currIndex++;
			}
        }
Esempio n. 3
0
void Camera::MoveTo(XMVECTOR new_eye, float new_theta, float new_phi)
{
    eye = new_eye;
    theta = new_theta;
    phi = new_phi;

    BuildMatrices();
}
Esempio n. 4
0
HRESULT DrawScene()
{
    HRESULT hr;
    do
    {
        // clear back buffer
        hr = pID3DDevice->Clear(0,
                                nullptr,
                                D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                                D3DCOLOR_RGBA(0, 0, 127, 0),
                                1.0,
                                0);
        if(FAILED(hr))
        {
            break;
        }

        BuildMatrices();

        // start drawing
        hr = pID3DDevice->BeginScene();
        if(FAILED(hr))
        {
            break;
        }

        // draw our triangle
        hr = pID3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
                                               0,
                                               0,
                                               ARRAYSIZE(vertices),
                                               0,
                                               ARRAYSIZE(indices) / 3);
        if(FAILED(hr))
        {
            break;
        }

        hr = pID3DDevice->EndScene();
        if(FAILED(hr))
        {
            break;
        }

        // flip back buffer to front
        hr = pID3DDevice->Present(nullptr, nullptr, nullptr, nullptr);
    } while(ONCE);

    return hr;
}
Esempio n. 5
0
void Camera::Update()
{
    XMMATRIX rotation = XMMatrixRotationRollPitchYaw(phi, theta, 0);  // rotation around x axis, y axis, z axis
    XMVECTOR cross = rotation.r[0];
    XMVECTOR up    = rotation.r[1];
    XMVECTOR look  = rotation.r[2];
    
    if (Input::key_down['W'])
        eye += look * scCameraTranslationSpeed;
    if (Input::key_down['S'])
        eye -= look * scCameraTranslationSpeed;
    if (Input::key_down['A'])
        eye -= cross * scCameraTranslationSpeed;
    if (Input::key_down['D'])
        eye += cross * scCameraTranslationSpeed;
    if (Input::key_down['Q'])
        eye += XMVectorSet(0,1,0,0) * scCameraTranslationSpeed;
    if (Input::key_down['E'])
        eye -= XMVectorSet(0,1,0,0) * scCameraTranslationSpeed;

	float boost = 1 + Input::gamepad_right_trigger*10;

	eye += cross * scCameraTranslationSpeed * Input::gamepad_left_x * boost;
	eye += look * scCameraTranslationSpeed * Input::gamepad_left_y * boost;
	eye -= XMVectorSet(0,1,0,0) * scCameraTranslationSpeed * Input::gamepad_left_shoulder * boost;
	eye += XMVectorSet(0,1,0,0) * scCameraTranslationSpeed * Input::gamepad_right_shoulder * boost;
	theta += scCameraRotationSpeed * Input::gamepad_right_x * boost;
	phi -= scCameraRotationSpeed * Input::gamepad_right_y * boost;

    if (Input::mousebutton_right_down)
    {
        theta += scCameraRotationSpeed * Input::mouse_dx;
        phi += scCameraRotationSpeed * Input::mouse_dy;
    }

    BuildMatrices();
}
Esempio n. 6
0
void  SingleWell1DLinear::MatSolve(bool& setupRequired)  // main driver
{
  if (!allAreConstant)
  {
    parameterTime = currSeqTime.testTime;
    BuildMatrices();
    setupRequired = true;
  }

  if (setupRequired)
  {
    LinearMatSetup();
    setupRequired = false;
  }

  LinearMatSolve();

  currSeqTZ.tzPressure = nodePressure[0];
  currSeqTZ.formFlow = wellDTerm * (currSeqTZ.tzPressure - nodePressure[1]) +
                       fracSVector[0] * (currSeqTZ.tzPressure - lastSeqTZ.tzPressure) / deltaT;

  if ((currSeqTZ.tzPressure < 0.0) && (!allowNegativePressure))
    throw SimError("1D linear well sucked dry - reduce pumping rate", SimError::seSemiFatal);
}
Esempio n. 7
0
double LCPPolyDist<Dimension,FVector,DVector>::ProcessLoop (
    bool halfspaceConstructor, int& statusCode, FVector closest[2])
{
    int i;
    double* Q = new1<double>(mNumEquations);
    double** M = new2<double>(mNumEquations, mNumEquations);

    statusCode = 0;

    bool processing = true;
    if (!BuildMatrices(M, Q))
    {
        WM5_LCPPOLYDIST_FUNCTION(CloseLog());
        closest[0] = FVector::ZERO;
        closest[1] = FVector::ZERO;
        processing = false;
    }

    WM5_LCPPOLYDIST_FUNCTION(PrintMatrices(M, Q));

    int tryNumber = 0;
    double distance = -Mathd::MAX_REAL;
    while (processing)
    {
        double* zResult = new1<double>(mNumEquations);
        double* wResult = new1<double>(mNumEquations);
        int lcpStatusCode;

        LCPSolver solver(mNumEquations, M, Q, zResult, wResult, lcpStatusCode);
        WM5_UNUSED(solver);

        switch (lcpStatusCode)
        {
        case SC_FOUND_TRIVIAL_SOLUTION:
        {
            statusCode = SC_FOUND_TRIVIAL_SOLUTION;
            break;
        }
        case SC_FOUND_SOLUTION:
        {
            DVector lcpClosest[2];
            for (i = 0; i < mDimension; ++i)
            {
                lcpClosest[0][i] = (float)zResult[i];
                lcpClosest[1][i] = (float)zResult[i + mDimension];
            }

            DVector diff = lcpClosest[0] - lcpClosest[1];
            distance = diff.Length();

            statusCode = VerifySolution(lcpClosest);

            if (!halfspaceConstructor)
            {
                WM5_LCPPOLYDIST_FUNCTION(VerifyWithTestPoints(lcpClosest,
                    statusCode));
            }

            for (i = 0; i < mDimension; ++i)
            {
                closest[0][i] = (float)lcpClosest[0][i];
                closest[1][i] = (float)lcpClosest[1][i];
            }
            processing = false;
            break;
        }
        case SC_CANNOT_REMOVE_COMPLEMENTARY:
        {
            WM5_LCPPOLYDIST_FUNCTION(LogRetries(tryNumber));
            if (tryNumber == 3)
            {
                statusCode = SC_CANNOT_REMOVE_COMPLEMENTARY;
                processing = false;
                break;
            }
            MoveHalfspaces(mNumFaces1, mA1, mB1);
            WM5_LCPPOLYDIST_FUNCTION(LogHalfspaces(mNumFaces1, mA1, mB1));
            MoveHalfspaces(mNumFaces2, mA2, mB2);
            WM5_LCPPOLYDIST_FUNCTION(LogHalfspaces(mNumFaces2, mA2, mB2));
            BuildMatrices(M, Q);
            ++tryNumber;
            break;
        }
        case SC_EXCEEDED_MAX_RETRIES:
        {
            WM5_LCPPOLYDIST_FUNCTION(LCPSolverLoopLimit());
            statusCode = SC_EXCEEDED_MAX_RETRIES;
            processing = false;
            break;
        }
        }
        delete1(wResult);
        delete1(zResult);
    }

    delete2(M);
    delete1(Q);

    return distance;
}
BOOL ALSZOTExtRec::receiver_routine(uint32_t id, uint64_t myNumOTs) {
	uint64_t myStartPos = id * myNumOTs;
	uint64_t wd_size_bits = m_nBlockSizeBits;

	uint64_t internal_numOTs = std::min(myNumOTs + myStartPos, m_nOTs) - myStartPos;
	uint64_t lim = myStartPos + internal_numOTs;

	uint64_t processedOTBlocks = std::min(num_ot_blocks, ceil_divide(internal_numOTs, wd_size_bits));
	uint64_t OTsPerIteration = processedOTBlocks * wd_size_bits;
	uint64_t OTwindow = num_ot_blocks * wd_size_bits;
	uint64_t** rndmat;
	bool use_mat_chan = (m_eSndOTFlav == Snd_GC_OT || m_bUseMinEntCorRob);
	uint32_t nchans = 2;
	if(use_mat_chan) {
		nchans = 3;
	}

	channel* ot_chan = new channel(OT_BASE_CHANNEL+nchans*id, m_cRcvThread, m_cSndThread);
	channel* check_chan = new channel(OT_BASE_CHANNEL+nchans*id+1, m_cRcvThread, m_cSndThread);
	channel* mat_chan;
	if(use_mat_chan) {
		mat_chan = new channel(nchans*id+2, m_cRcvThread, m_cSndThread);
	}

	// A temporary part of the T matrix
	CBitVector T(wd_size_bits * OTsPerIteration);

	// The send buffer
	CBitVector vSnd(m_nBaseOTs * OTsPerIteration);

	// A temporary buffer that stores the resulting seeds from the hash buffer
	//TODO: Check for some maximum size
	CBitVector seedbuf(OTwindow * m_cCrypt->get_aes_key_bytes() * 8);

	uint64_t otid = myStartPos;
	std::queue<alsz_rcv_check_t> check_buf;

	std::queue<mask_block*> mask_queue;
	CBitVector maskbuf;
	maskbuf.Create(m_nBitLength * OTwindow);

	//these two values are only required for the min entropy correlation robustness assumption
	alsz_rcv_check_t check_tmp;
	CBitVector Ttmp(wd_size_bits * OTsPerIteration);

	OT_AES_KEY_CTX* tmp_base_keys;

	uint64_t base_ot_block_ctr = otid / (myNumOTs);

	//TODO only do when successfull checks
	if(m_eSndOTFlav == Snd_GC_OT) {
		initRndMatrix(&rndmat, m_nBitLength, m_nBaseOTs);
	}

#ifdef OTTiming
	double totalMtxTime = 0, totalTnsTime = 0, totalHshTime = 0, totalRcvTime = 0, totalSndTime = 0,
			totalChkTime = 0, totalMaskTime = 0, totalEnqueueTime = 0, totalOutputSetTime = 0;
	timespec tempStart, tempEnd;
#endif

	while (otid < lim) {
		processedOTBlocks = std::min(num_ot_blocks, ceil_divide(lim - otid, wd_size_bits));
		OTsPerIteration = processedOTBlocks * wd_size_bits;
		//nSize = bits_in_bytes(m_nBaseOTs * OTsPerIteration);

		tmp_base_keys = m_tBaseOTKeys[base_ot_block_ctr];
		//m_tBaseOTQ.pop();

#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
		BuildMatrices(&T, &vSnd, otid, processedOTBlocks, tmp_base_keys);
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalMtxTime += getMillies(tempStart, tempEnd);
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
		check_buf.push(EnqueueSeed(T.GetArr(), vSnd.GetArr(), otid, processedOTBlocks));
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalEnqueueTime += getMillies(tempStart, tempEnd);
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
		MaskBaseOTs(&T, &vSnd, otid, processedOTBlocks);
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalMaskTime += getMillies(tempStart, tempEnd);
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
		SendMasks(&vSnd, ot_chan, otid, OTsPerIteration);
		//ot_chan->send_id_len(vSnd.GetArr(), nSize, otid, OTsPerIteration);
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalSndTime += getMillies(tempStart, tempEnd);
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif

		ReceiveAndFillMatrix(rndmat, mat_chan);
		if(!m_bUseMinEntCorRob) {
			T.Transpose(wd_size_bits, OTsPerIteration);
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalTnsTime += getMillies(tempStart, tempEnd);
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
			HashValues(&T, &seedbuf, &maskbuf, otid, std::min(lim - otid, OTsPerIteration), rndmat);
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalHshTime += getMillies(tempStart, tempEnd);
		clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
		}
		if(check_chan->data_available()) {
			if(m_bUseMinEntCorRob) {
				check_tmp = check_buf.front();
				Ttmp.Copy(check_tmp.T0, 0, check_tmp.numblocks * m_nBlockSizeBytes);
			}
			ComputeOWF(&check_buf, check_chan);
			if(m_bUseMinEntCorRob) {
				ReceiveAndXORCorRobVector(&Ttmp, check_tmp.numblocks * wd_size_bits, mat_chan);
				Ttmp.Transpose(wd_size_bits, OTsPerIteration);
				HashValues(&Ttmp, &seedbuf, &maskbuf, check_tmp.otid, std::min(lim - check_tmp.otid, check_tmp.numblocks * wd_size_bits), rndmat);
			}
#ifdef OTTiming
			clock_gettime(CLOCK_MONOTONIC, &tempEnd);
			totalChkTime += getMillies(tempStart, tempEnd);
			clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
		}

		SetOutput(&maskbuf, otid, OTsPerIteration, &mask_queue, ot_chan);

		otid += std::min(lim - otid, OTsPerIteration);
		base_ot_block_ctr++;
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalOutputSetTime += getMillies(tempStart, tempEnd);
#endif

		//free(tmp_base_keys);
		//free(tmp_baseots);

		vSnd.Reset();
		T.Reset();
	}

	while(!check_buf.empty()) {
		if(check_chan->data_available()) {
			if(m_bUseMinEntCorRob) {
				check_tmp = check_buf.front();
				Ttmp.Copy(check_tmp.T0, 0, check_tmp.numblocks * m_nBlockSizeBytes);
			}
#ifdef OTTiming
			clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
			ComputeOWF(&check_buf, check_chan);
#ifdef OTTiming
			clock_gettime(CLOCK_MONOTONIC, &tempEnd);
			totalChkTime += getMillies(tempStart, tempEnd);
#endif
			if(m_bUseMinEntCorRob) {
				ReceiveAndXORCorRobVector(&Ttmp, check_tmp.numblocks * wd_size_bits, mat_chan);
				Ttmp.Transpose(wd_size_bits, OTsPerIteration);
				HashValues(&Ttmp, &seedbuf, &maskbuf, check_tmp.otid, std::min(lim - check_tmp.otid, check_tmp.numblocks * wd_size_bits), rndmat);
			}
		}
	}


	if(m_eSndOTFlav != Snd_R_OT) {
		//finevent->Wait();
#ifdef ABY_OT
		while(!(mask_queue.empty())) {
#else
		while(ot_chan->is_alive() && !(mask_queue.empty())) {
#endif
#ifdef OTTiming
			clock_gettime(CLOCK_MONOTONIC, &tempStart);
#endif
			ReceiveAndUnMask(ot_chan, &mask_queue);
#ifdef OTTiming
		clock_gettime(CLOCK_MONOTONIC, &tempEnd);
		totalOutputSetTime += getMillies(tempStart, tempEnd);
#endif
		}
	}

	ot_chan->synchronize_end();
	check_chan->synchronize_end();
	delete ot_chan;
	delete check_chan;


	T.delCBitVector();
	vSnd.delCBitVector();
	seedbuf.delCBitVector();
	maskbuf.delCBitVector();
	Ttmp.delCBitVector();

	if(use_mat_chan) {
		mat_chan->synchronize_end();
		delete mat_chan;
	}

	if(m_eSndOTFlav==Snd_GC_OT) {
		freeRndMatrix(rndmat, m_nBaseOTs);
	}

#ifdef OTTiming
	std::cout << "Receiver time benchmark for performing " << internal_numOTs << " OTs on " << m_nBitLength << " bit strings" << std::endl;
	std::cout << "Time needed for: " << std::endl;
	std::cout << "\t Matrix Generation:\t" << totalMtxTime << " ms" << std::endl;
	std::cout << "\t Enqueuing Seeds:\t" << totalEnqueueTime << " ms" << std::endl;
	std::cout << "\t Base OT Masking:\t" << totalMaskTime << " ms" << std::endl;
	std::cout << "\t Sending Matrix:\t" << totalSndTime << " ms" << std::endl;
	std::cout << "\t Transposing Matrix:\t" << totalTnsTime << " ms" << std::endl;
	std::cout << "\t Hashing Matrix:\t" << totalHshTime << " ms" << std::endl;
	std::cout << "\t Receiving Values:\t" << totalRcvTime << " ms" << std::endl;
	std::cout << "\t Checking OWF:  \t" << totalChkTime << " ms" << std::endl;
	std::cout << "\t Setting Output:\t" << totalOutputSetTime << " ms" << std::endl;
#endif

	return TRUE;
}


void ALSZOTExtRec::ReceiveAndFillMatrix(uint64_t** rndmat, channel* mat_chan) {
	if(m_eSndOTFlav == Snd_GC_OT) {
		uint8_t* rnd_seed = mat_chan->blocking_receive();
		//initRndMatrix(&rndmat, m_nBitLength, m_nBaseOTs);
		fillRndMatrix(rnd_seed, rndmat, m_nBitLength, m_nBaseOTs, m_cCrypt);
		free(rnd_seed);
	}
}

alsz_rcv_check_t ALSZOTExtRec::EnqueueSeed(uint8_t* T0, uint8_t* T1, uint64_t otid, uint64_t numblocks) {
	uint64_t expseedbytelen = m_nBaseOTs * numblocks * m_nBlockSizeBytes;
	alsz_rcv_check_t seedstr;

	seedstr.otid = otid;
	seedstr.numblocks = numblocks;
	seedstr.T0 = (uint8_t*) malloc(expseedbytelen);
	seedstr.T1 = (uint8_t*) malloc(expseedbytelen);

	memcpy(seedstr.T0, T0, expseedbytelen);
	memcpy(seedstr.T1, T1, expseedbytelen);

	return seedstr;
}
Esempio n. 9
0
void SingleWell1DLinear::SetRunParameters()
{
  SingleWell1D::SetRunParameters();

  double fVolCons = 1.0;
  if (control.IsDual())
  {
    SetRockMap(fracStartNode, nradialNodes, fracParGroup);

    double mVolFactor = wPar[pM_V].GetData();
    fVolCons = 1.0 - mVolFactor;
    for (int j = 0; j < nradialNodes; j++)
    {
      dGeomTerm[j] *= fVolCons;
      sGeomTerm[j] *= fVolCons;
    }

    matrix.ConstantInit(staticPressure, kpaConst);
    matrix.SetParameters(wPar, matParGroup, sGeomTerm);

    // for output calcs only
    double mk     = CalcKTerm(matParGroup);
    double mss    = CalcStoreTerm(matParGroup);
    double malpha;
    if (enterDualAlpha)
      malpha = wPar[pM_Alpha].GetData();
    else
    {
      if (dualGeometryIsPrismatic)
        malpha = 12.0 / Sqr(wPar[pM_t].GetData());  // slab thick
      else
        malpha = 15.0 / Sqr(wPar[pM_d].GetData()/2.0);  // sphere diameter * ???
    }
    // calcs for output
    double fracK  = CalcKTerm(fracParGroup) * (1.0 - mVolFactor);  // for analytic compatibility
    double calcLambda = malpha * mk / fracK * Sqr(wPar[pTZ_r_w].GetData());
    simulatorRadiiFO.dualLambdaDO.SetCalcValue(calcLambda);

    double fracT = fracK * wPar[pF_t].GetData(0);
    simulatorRadiiFO.dualFractureTDO.SetCalcValue(fracT);

    double fracSS  = CalcStoreTerm(fracParGroup) * (1.0 - mVolFactor);
    double calcOmega = fracSS / (fracSS + mss * mVolFactor);
    simulatorRadiiFO.dualOmegaDO.SetCalcValue(calcOmega);
  }

  if (control.IsLeaky())
  {
    for (int j = 0; j < nradialNodes; j++)
      leakArea[j] = nodePlanArea[j] * fVolCons;

    if (leakageType != ltUpperLower)
    {
      singleLeak.ConstantInit(staticPressure, kpaConst);
      singleLeak.SetParameters(wPar, slParGroup, leakArea);
    }
    else
    {
      lowerLeak.ConstantInit(staticPressure, kpaConst);
      lowerLeak.SetParameters(wPar, llParGroup, leakArea);

      upperLeak.ConstantInit(staticPressure, kpaConst);
      upperLeak.SetParameters(wPar, ulParGroup, leakArea);
    }
  }

  ScaleGeomTerms(kpaToPa, kpaToPa);


  allAreConstant = true;
  dTermIsConstant.FillToSize(false);
  sTermIsConstant.FillToSize(false);

  if (isPartialRun)
    parameterTime = wSeq[partialStartSeqVal].startTime;
  else
    parameterTime = wSeq[0].startTime;

  for (int j = 0; j < nradialNodes; j++)
  {
    lastWasConstant = true;
    double nextD = GetDTerm(j);
    dConstantTerm[j] = nextD;
    dTermIsConstant[j] = lastWasConstant;
    if (!lastWasConstant)
      allAreConstant = false;

    lastWasConstant = true;
    double sterm = GetSTerm(j);
    sConstantTerm[j] = sterm;
    sTermIsConstant[j] = lastWasConstant;
    if (!lastWasConstant)
      allAreConstant = false;
  }

  BuildMatrices();

  if (!control.IsDual())
    CalcFluidFormationFactors();

}
Esempio n. 10
0
BOOL NNOBOTExtRec::receiver_routine(uint32_t id, uint64_t myNumOTs) {
	uint64_t myStartPos = id * myNumOTs;
	uint64_t wd_size_bits = m_nBlockSizeBits;

	myNumOTs = min(myNumOTs + myStartPos, m_nOTs) - myStartPos;
	uint64_t lim = myStartPos + myNumOTs;

	uint64_t processedOTBlocks = min((uint64_t) NUMOTBLOCKS, ceil_divide(myNumOTs, wd_size_bits));
	uint64_t OTsPerIteration = processedOTBlocks * wd_size_bits;
	uint64_t OTwindow = NUMOTBLOCKS * wd_size_bits;
	uint64_t** rndmat;
	bool use_mat_chan = (m_eSndOTFlav == Snd_GC_OT || m_bUseMinEntCorRob);
	uint32_t nchans = 2;
	if(use_mat_chan) {
		nchans = 3;
	}

	channel* ot_chan = new channel(nchans*id, m_cRcvThread, m_cSndThread);
	channel* check_chan = new channel(nchans*id+1, m_cRcvThread, m_cSndThread);
	channel* mat_chan;
	if(use_mat_chan) {
		mat_chan = new channel(nchans*id+2, m_cRcvThread, m_cSndThread);
	}

	//counter variables
	uint64_t numblocks = ceil_divide(myNumOTs, OTsPerIteration);

	// A temporary part of the T matrix
	CBitVector T(wd_size_bits * OTsPerIteration);

	// The send buffer
	CBitVector vSnd(m_nBaseOTs * OTsPerIteration);

	// A temporary buffer that stores the resulting seeds from the hash buffer
	//TODO: Check for some maximum size
	CBitVector seedbuf(OTwindow * m_cCrypt->get_aes_key_bytes() * 8);

	uint64_t otid = myStartPos;
	queue<nnob_rcv_check_t> check_buf;

	queue<mask_block*> mask_queue;
	CBitVector maskbuf;
	maskbuf.Create(m_nBitLength * OTwindow);

	//TODO only do when successfull checks
	if(m_eSndOTFlav == Snd_GC_OT) {
		initRndMatrix(&rndmat, m_nBitLength, m_nBaseOTs);
	}

#ifdef OTTiming
	double totalMtxTime = 0, totalTnsTime = 0, totalHshTime = 0, totalRcvTime = 0, totalSndTime = 0,
			totalChkTime = 0, totalMaskTime = 0, totalEnqueueTime = 0;
	timeval tempStart, tempEnd;
#endif

	while (otid < lim) {
		processedOTBlocks = min((uint64_t) NUMOTBLOCKS, ceil_divide(lim - otid, wd_size_bits));
		OTsPerIteration = processedOTBlocks * wd_size_bits;
		//nSize = bits_in_bytes(m_nBaseOTs * OTsPerIteration);

#ifdef OTTiming
		gettimeofday(&tempStart, NULL);
#endif
		BuildMatrices(T, vSnd, otid, processedOTBlocks);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalMtxTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		check_buf.push(EnqueueSeed(T.GetArr(), otid, processedOTBlocks));
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalEnqueueTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		MaskBaseOTs(T, vSnd, otid, processedOTBlocks);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalMaskTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		SendMasks(vSnd, ot_chan, otid, OTsPerIteration);
		//ot_chan->send_id_len(vSnd.GetArr(), nSize, otid, OTsPerIteration);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalSndTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		ReceiveAndFillMatrix(rndmat, mat_chan);
		ReceiveAndXORCorRobVector(T, OTsPerIteration, mat_chan);

		T.Transpose(wd_size_bits, OTsPerIteration);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalTnsTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif

		HashValues(&T, &seedbuf, &maskbuf, otid, min(lim - otid, OTsPerIteration), rndmat);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalHshTime += getMillies(tempStart, tempEnd);
		gettimeofday(&tempStart, NULL);
#endif
		if(check_chan->data_available()) {
			ComputeOWF(&check_buf, check_chan);
		}
		//if(ot_chan->data_available()) {
		//	ReceiveAndUnMask(ot_chan);
		//}
		SetOutput(&maskbuf, otid, OTsPerIteration, &mask_queue, ot_chan);

		otid += min(lim - otid, OTsPerIteration);
#ifdef OTTiming
		gettimeofday(&tempEnd, NULL);
		totalRcvTime += getMillies(tempStart, tempEnd);
#endif

		vSnd.Reset();
		T.Reset();
	}

	while(!check_buf.empty()) {
		if(check_chan->data_available()) {
			ComputeOWF(&check_buf, check_chan);
		}
	}


	if(m_eSndOTFlav != Snd_R_OT) {
		//finevent->Wait();
		while(ot_chan->is_alive() && !(mask_queue.empty()))
			ReceiveAndUnMask(ot_chan, &mask_queue);
	}
	ot_chan->synchronize_end();
	check_chan->synchronize_end();

	T.delCBitVector();
	vSnd.delCBitVector();
	seedbuf.delCBitVector();
	maskbuf.delCBitVector();

	if(use_mat_chan) {
		mat_chan->synchronize_end();
	}

	if(m_eSndOTFlav==Snd_GC_OT) {
		freeRndMatrix(rndmat, m_nBaseOTs);
	}

#ifdef OTTiming
	cout << "Receiver time benchmark for performing " << myNumOTs << " OTs on " << m_nBitLength << " bit strings" << endl;
	cout << "Time needed for: " << endl;
	cout << "\t Matrix Generation:\t" << totalMtxTime << " ms" << endl;
	cout << "\t Enqueuing Seeds:\t" << totalEnqueueTime << " ms" << endl;
	cout << "\t Base OT Masking:\t" << totalMaskTime << " ms" << endl;
	cout << "\t Sending Matrix:\t" << totalSndTime << " ms" << endl;
	cout << "\t Transposing Matrix:\t" << totalTnsTime << " ms" << endl;
	cout << "\t Hashing Matrix:\t" << totalHshTime << " ms" << endl;
	cout << "\t Receiving Values:\t" << totalRcvTime << " ms" << endl;
#endif


	return TRUE;
}