int main(){ std::cout << std::endl; std::vector<int> randValues; randValues.reserve(size); std::mt19937 engine; std::uniform_int_distribution<> uniformDist(1,10); for ( long long i=0 ; i< size ; ++i) randValues.push_back(uniformDist(engine)); unsigned long long sum= 0; auto start = std::chrono::system_clock::now(); std::thread t1(sumUp,std::ref(sum),std::ref(randValues),0,firBound); std::thread t2(sumUp,std::ref(sum),std::ref(randValues),firBound,secBound); std::thread t3(sumUp,std::ref(sum),std::ref(randValues),secBound,thiBound); std::thread t4(sumUp,std::ref(sum),std::ref(randValues),thiBound,fouBound); t1.join(); t2.join(); t3.join(); t4.join(); std::chrono::duration<double> dur= std::chrono::system_clock::now() - start; std::cout << "Time for addition " << dur.count() << " seconds" << std::endl; std::cout << "Result: " << sum << std::endl; std::cout << std::endl; }
int main(){ std::cout << std::endl; std::map<int,int> myMap; std::unordered_map<int,int> myHash; for ( long long i=0; i < mapSize; ++i ){ myMap[i]=i; myHash[i]= i; } std::vector<int> randValues; randValues.reserve(accSize); // random values std::random_device seed; std::mt19937 engine(seed()); std::uniform_int_distribution<> uniformDist(0,mapSize); for ( long long i=0 ; i< accSize ; ++i) randValues.push_back(uniformDist(engine)); auto start = std::chrono::system_clock::now(); for ( long long i=0; i < accSize; ++i){ myMap[randValues[i]]; } std::chrono::duration<double> dur= std::chrono::system_clock::now() - start; std::cout << "time for std::map: " << dur.count() << " seconds" << std::endl; auto start2 = std::chrono::system_clock::now(); for ( long long i=0; i < accSize; ++i){ myHash[randValues[i]]; } std::chrono::duration<double> dur2= std::chrono::system_clock::now() - start2; std::cout << "time for std::unordered_map: " << dur2.count() << " seconds" << std::endl; std::cout << std::endl; }
void FunnelReal::Private::getNewFeatsInvT(std::vector<std::vector<float> > &newFIDs, const std::vector<std::vector<std::vector<float> > > &originalFeats, const std::vector<float> &vparams, float centerX, float centerY) const { int numFeats = newFIDs[0].size(); std::vector<float> uniformDist(numFeats, 1.0f/numFeats); float postM[2][3] = {{1,0,centerX}, {0,1,centerY}}; float preM[3][3] = {{1,0,-centerX}, {0,1,-centerY}, {0,0,1}}; float tM[3][3] = {{1, 0, vparams[0]}, {0, 1, vparams[1]}, {0,0,1}}; float rM[3][3] = {{cosf(vparams[2]), -sinf(vparams[2]), 0}, {sinf(vparams[2]), cosf(vparams[2]), 0}, {0, 0, 1}}; float sM[3][3] = {{expf(vparams[3]), 0, 0}, {0, expf(vparams[3]), 0}, {0, 0, 1}}; cv::Mat tCVM(3, 3, CV_32FC1, tM); cv::Mat rCVM(3, 3, CV_32FC1, rM); cv::Mat sCVM(3, 3, CV_32FC1, sM); cv::Mat postCVM(2, 3, CV_32FC1, postM); cv::Mat preCVM(3, 3, CV_32FC1, preM); cv::Mat xform(2, 3, CV_32FC1); xform = postCVM * tCVM; xform = xform * rCVM; xform = xform * sCVM; xform = xform * preCVM; int height = (signed)originalFeats.size(); int width = (signed)originalFeats[0].size(); for(int i=0; i<(signed)newFIDs.size(); i++) { int j = randPxls[i].first; int k = randPxls[i].second; int nx = (int)(xform.at<float>(0)*k + xform.at<float>(1)*j + xform.at<float>(2) + 0.5f); int ny = (int)(xform.at<float>(3)*k + xform.at<float>(4)*j + xform.at<float>(5) + 0.5f); if(!(ny >= 0 && ny < height && nx >= 0 && nx < width)) newFIDs[i] = uniformDist; else newFIDs[i] = originalFeats[ny][nx]; } }
void generatePbcs(boost::numeric::ublas::vector<double> &spr, const std::vector<double> &pars) { double r; int a; rnd::uniform_01<> uniformDist; rnd::bernoulli_distribution<> bernoulliDist; for (unsigned int i=0; i<spr.size(); ++i) { if (isEven(static_cast<int>(i))) { r = uniformDist(rng); spr(i) = inverseCdfPbcs(r, pars[0]); } else { r = bernoulliDist(rng); a = r==0 ? -1 : 1; spr(i) = pars[0]+a*sqrt(1-pow(spr(i-1)-pars[0], 2)); } } }
// Create all threads and initialize shader push constants void prepareMultiThreadedRenderer() { // Since this demo updates the command buffers on each frame // we don't use the per-framebuffer command buffers from the // base class, and create a single primary command buffer instead VkCommandBufferAllocateInfo cmdBufAllocateInfo = vkTools::initializers::commandBufferAllocateInfo( cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1); VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, &primaryCommandBuffer)); // Create a secondary command buffer for rendering the star sphere cmdBufAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY; VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, &secondaryCommandBuffer)); threadData.resize(numThreads); float maxX = std::floor(std::sqrt(numThreads * numObjectsPerThread)); uint32_t posX = 0; uint32_t posZ = 0; std::mt19937 rndGenerator((unsigned)time(NULL)); std::uniform_real_distribution<float> uniformDist(0.0f, 1.0f); for (uint32_t i = 0; i < numThreads; i++) { ThreadData *thread = &threadData[i]; // Create one command pool for each thread VkCommandPoolCreateInfo cmdPoolInfo = vkTools::initializers::commandPoolCreateInfo(); cmdPoolInfo.queueFamilyIndex = swapChain.queueNodeIndex; cmdPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; VK_CHECK_RESULT(vkCreateCommandPool(device, &cmdPoolInfo, nullptr, &thread->commandPool)); // One secondary command buffer per object that is updated by this thread thread->commandBuffer.resize(numObjectsPerThread); // Generate secondary command buffers for each thread VkCommandBufferAllocateInfo secondaryCmdBufAllocateInfo = vkTools::initializers::commandBufferAllocateInfo( thread->commandPool, VK_COMMAND_BUFFER_LEVEL_SECONDARY, thread->commandBuffer.size()); VK_CHECK_RESULT(vkAllocateCommandBuffers(device, &secondaryCmdBufAllocateInfo, thread->commandBuffer.data())); thread->pushConstBlock.resize(numObjectsPerThread); thread->objectData.resize(numObjectsPerThread); for (uint32_t j = 0; j < numObjectsPerThread; j++) { float theta = 2.0f * float(M_PI) * uniformDist(rndGenerator); float phi = acos(1.0f - 2.0f * uniformDist(rndGenerator)); thread->objectData[j].pos = glm::vec3(sin(phi) * cos(theta), 0.0f, cos(phi)) * 35.0f; thread->objectData[j].rotation = glm::vec3(0.0f, rnd(360.0f), 0.0f); thread->objectData[j].deltaT = rnd(1.0f); thread->objectData[j].rotationDir = (rnd(100.0f) < 50.0f) ? 1.0f : -1.0f; thread->objectData[j].rotationSpeed = (2.0f + rnd(4.0f)) * thread->objectData[j].rotationDir; thread->objectData[j].scale = 0.75f + rnd(0.5f); thread->pushConstBlock[j].color = glm::vec3(rnd(1.0f), rnd(1.0f), rnd(1.0f)); } } }