void runCoordinator(igcl::Coordinator * coord) { Raytracer raytracer; raytracer.setupScene(); // setup scene objects ::raytracer = &raytracer; ::coord = coord; coord->start(); coord->waitForNodes(nParticipants); th = new std::thread(runThread); th->detach(); image = new BmpImage(IMAGE_WIDTH, IMAGE_HEIGHT); imageSize = IMAGE_HEIGHT*IMAGE_WIDTH; for (int i=0; i<nTests; i++) { countJobs = 0; std::unique_lock<std::mutex> bufferLock(bufferingAccessMutex); igcl::NBuffering buf(bufferingLevel, imageSize, blockSize, sendJob); buffering = &buf; buffering->addPeers(coord->downstreamPeers()); buffering->addPeer(0); bufferLock.unlock(); timeval iniTime; start(iniTime); bufferLock.lock(); buffering->bufferToAll(); bufferLock.unlock(); while (1) { //cout << "lock buffering->allJobsCompleted()" << endl; bufferLock.lock(); //cout << buffering->allJobsCompleted() << " " << buffering->getNCompletedJobs() << endl; if (buffering->allJobsCompleted()) { bufferLock.unlock(); break; } bufferLock.unlock(); receiveResult(); } cout << "count: " << countJobs << endl; finish(iniTime); } coord->terminate(); }
void runPeer(igcl::Peer * peer) { peer->start(); Raytracer raytracer; raytracer.setupScene(); // setup scene objects timeval globalIni, end; gettimeofday(&globalIni, NULL); imageSize = IMAGE_HEIGHT*IMAGE_WIDTH; while (1) { uint startIndex = 0; igcl::result_type res = peer->waitRecvFrom(0, startIndex); if (res != igcl::SUCCESS) break; //std::cout << "received " << startIndex << endl; uint nIndexes = std::min(blockSize, imageSize-startIndex); uint endIndex = startIndex + nIndexes; color_s_char array[nIndexes]; for (uint i=startIndex; i<endIndex; ++i) { int row = i / IMAGE_WIDTH; int col = i % IMAGE_WIDTH; const color_s & c = raytracer.castRayFromScreen(row, col); // calculate color of pixel (CPU-HEAVY) array[i-startIndex] = color_s_char(c); } peer->sendTo(0, array+0, nIndexes); } gettimeofday(&end, NULL); cout << "total time:\t" << timeDiff(globalIni, end) << " ms\n"; peer->hang(); }
void runCoordinator(igcl::Coordinator * node) { const uint blockSize = 10000; Raytracer raytracer; raytracer.setupScene(); // setup scene objects for (int t=0; t<30; t++) { timeval iniTime; start(iniTime); //#pragma omp parallel for num_threads(N_THREADS) #pragma omp parallel for schedule(dynamic, 10000) num_threads(N_THREADS) for (uint i=0; i<imageSize; i++) { int row = i / IMAGE_WIDTH; int col = i % IMAGE_WIDTH; color_s c = raytracer.castRayFromScreen(row, col); // calculate color of pixel (CPU-HEAVY) image->setPixel(row, col, c.r, c.g, c.b); } finish(iniTime); } }