void cSystem::startNthreadsFFTW(void) { require( fftw_init_threads() != 0, "void cSystem::startNthreadsFFTW(void)"); require(fftwf_init_threads() != 0, "void cSystem::startNthreadsFFTW(void)"); fftw_plan_with_nthreads(getNumProcessors()); fftwf_plan_with_nthreads(getNumProcessors()); std::cout << "FFTW multithreading is turned on: " << getNumProcessors() << " threads\n\n"; }
int main (int argc, char * argv[]) { int nthreads; int iterations; int objSize; int repetitions; if (argc > 4) { nthreads = atoi(argv[1]); iterations = atoi(argv[2]); objSize = atoi(argv[3]); repetitions = atoi(argv[4]); } else { fprintf (stderr, "Usage: %s nthreads iterations objSize repetitions\n", argv[0]); exit(1); } pthread_t threads[nthreads]; int numCPU = getNumProcessors(); pthread_setconcurrency(numCPU); int i; /* Call allocator-specific initialization function */ mm_init(); pthread_attr_t attr; initialize_pthread_attr(PTHREAD_CREATE_JOINABLE, SCHED_RR, -10, PTHREAD_EXPLICIT_SCHED, PTHREAD_SCOPE_SYSTEM, &attr); timer_start(); for (i = 0; i < nthreads; i++) { struct workerArg * w = (struct workerArg *)mm_malloc(sizeof(struct workerArg)); w->_objSize = objSize; w->_repetitions = repetitions / nthreads; w->_iterations = iterations; w->_cpu = (i+1)%numCPU; pthread_create(&threads[i], &attr, &worker, (void *)w); } for (i = 0; i < nthreads; i++) { pthread_join(threads[i], NULL); } double t = timer_stop(); printf ("Time elapsed = %f seconds\n", t); printf ("Memory used = %d bytes\n",mem_usage()); return 0; }
void cSystem::checkComputingResource(unsigned int nGPU, unsigned int nCPU) { std::string message; std::string hostname = getComputerName(); unsigned int nGPUmax = 0, nCPUmax = 0; nGPUmax = getNumGPUs(); message = "(" + hostname + ") "; message += "has only " + num2str(nGPUmax) + " GPUs!"; require(nGPU <= nGPUmax, message.c_str()); nCPUmax = getNumProcessors(); message = "(" + hostname + ") "; message += "has only " + num2str(nCPUmax) + " CPU cores!"; require(nCPU <= nCPUmax, message.c_str()); }
ThreadPool::ThreadPool() { numThreads = getNumProcessors(); pthread_cond_init(&startCondition, NULL); pthread_cond_init(&endCondition, NULL); pthread_mutex_init(&lock, NULL); thread.resize(numThreads); pthread_mutex_lock(&lock); waitCount = 0; for (int i = 0; i < numThreads; i++) { ThreadData* data = new ThreadData(*this, i); data->isDeleted = false; threadData.push_back(data); pthread_create(&thread[i], NULL, threadBody, data); } while (waitCount < numThreads) pthread_cond_wait(&endCondition, &lock); pthread_mutex_unlock(&lock); }
/** If the configuration of this installation has not been reported for the * current version, collect the hardware statistics and send it to STK's * server. */ void reportHardwareStats() { // Version of the hw report, which is stored in the DB. If new fields // are added, increase this version. Each STK installation will report // its configuration only once (per version number). So if the version // number is increased, a new report will be sent. const int report_version = 1; if(UserConfigParams::m_last_hw_report_version>=report_version) return; while(UserConfigParams::m_random_identifier==0) { RandomGenerator rg; UserConfigParams::m_random_identifier = rg.get(1<<30); user_config->saveConfig(); } Json json; #ifdef WIN32 json.add("os_win", 1); #else json.add("os_win", 0); #endif #ifdef __APPLE__ json.add("os_macosx", 1); #else json.add("os_macosx", 0); #endif #ifdef __linux__ json.add("os_linux", 1); json.add("os_unix", 1); #else json.add("os_linux", 0); json.add("os_unix", 0); #endif #ifdef DEBUG json.add("build_debug", 1); #endif json.add("os_version", getOSVersion()); unsigned int ogl_version = irr_driver->getGLSLVersion(); unsigned int major = ogl_version/100; unsigned int minor = ogl_version - 100*major; std::string version = StringUtils::insertValues("%d.%d", major, minor); json.add("GL_SHADING_LANGUAGE_VERSION", version); std::string vendor, renderer, full_version; irr_driver->getOpenGLData(&vendor, &renderer, &full_version); json.add("GL_VENDOR", vendor ); json.add("GL_RENDERER", renderer ); json.add("GL_VERSION", full_version ); json.add("gfx_drv_ver", "OpenGL "+vendor); std::string card_name = vendor; if(StringUtils::startsWith(card_name, "ATI Technologies Inc.")) card_name="ATI"; else if (StringUtils::startsWith(card_name, "NVIDIA Corporation")) card_name="NVIDIA"; else if(StringUtils::startsWith(card_name, "S3 Graphics")) card_name="S3"; json.add("gfx_card", card_name+" "+renderer); json.add("video_xres", UserConfigParams::m_width ); json.add("video_yres", UserConfigParams::m_height); int mem = getRAM(); if(mem>0) json.add("ram_total", mem); int nr_procs = getNumProcessors(); if(nr_procs>0) json.add("cpu_numprocs", nr_procs); json.add("GL_EXTENSIONS", getGLExtensions()); getGLLimits(&json); json.finish(); // ------------------------------------------------------------------------ /** A small class which sends the HW report to the STK server. On * completion, it will either update the last-submitted-hw-report version, * or log an error message (in which case next time STK is started it * wil try again to log the report). */ class HWReportRequest : public Online::HTTPRequest { private: /** Version number of the hw report. */ int m_version; public: HWReportRequest(int version) : Online::HTTPRequest(/*manage memory*/true, 1) , m_version(version) {} // -------------------------------------------------------------------- /** Callback after the request has been executed. */ virtual void callback() { // If the request contains incorrect data, it will not have a // download error, but return an error string as return value: if(hadDownloadError() || getData()=="<h1>Bad Request (400)</h1>") { Log::error("HW report", "Error uploading the HW report."); if(hadDownloadError()) Log::error("HW report", "%s", getDownloadErrorMessage()); else Log::error("HW report", "%s", getData().c_str()); } else { Log::info("HW report", "Upload successful."); UserConfigParams::m_last_hw_report_version = m_version; // The callback is executed by the main thread, so no need // to worry about locks when writing the file. user_config->saveConfig(); } } // callback }; // HWReportRequest // ------------------------------------------------------------------------ Online::HTTPRequest *request = new HWReportRequest(report_version); request->addParameter("user_id", UserConfigParams::m_random_identifier); request->addParameter("time", StkTime::getTimeSinceEpoch()); request->addParameter("type", "hwdetect"); request->addParameter("version", report_version); request->addParameter("data", json.toString()); request->setURL((std::string)UserConfigParams::m_server_hw_report+"/upload/v1/"); //request->setURL("http://127.0.0.1:8000/upload/v1/"); request->queue(); } // reportHardwareStats
int main (int argc, char *argv[]) { #if defined(_MT) || defined(_REENTRANT) int min_threads, max_threads ; int num_rounds ; int chperthread ; #endif unsigned seed=12345 ; int num_chunks=10000; long sleep_cnt; int matches; if (argc > 7) { sleep_cnt = atoi(argv[1]); min_size = atoi(argv[2]); max_size = atoi(argv[3]); chperthread = atoi(argv[4]); num_rounds = atoi(argv[5]); seed = atoi(argv[6]); max_threads = atoi(argv[7]); min_threads = max_threads; goto DoneWithInput; } #if defined(_MT) || defined(_REENTRANT) //#ifdef _MT printf( "\nMulti-threaded test driver \n") ; #else printf( "\nSingle-threaded test driver \n") ; #endif printf("C version (malloc and free)\n") ; printf("runtime (sec): ") ; /* 15 seconds */ if ((matches = scanf ("%ld", &sleep_cnt)) != 1) { printf("error scanning stdin for sleep_cnt - exiting\n"); return(1); } printf("chunk size (min,max): ") ; /* 8 40 */ if ((matches = scanf("%d %d", &min_size, &max_size )) != 2) { printf("error scanning stdin for chunk size (min,max) - exiting\n"); return(1); } #if defined(_MT) || defined(_REENTRANT) //#ifdef _MT printf("threads (min, max): ") ; /* same, 1 1, 2 2, etc. */ if ((matches = scanf("%d %d", &min_threads, &max_threads)) != 2) { printf("error scanning stdin for threads (min,max) - exiting\n"); return(1); } printf("chunks/thread: ") ; if ((matches = scanf("%d", &chperthread )) != 1) { /* 10K */ printf("error scanning stdin for chunks/thread - exiting\n"); return(1); } printf("no of rounds: ") ; if ((matches = scanf("%d", &num_rounds )) != 1) { /* 10 */ printf("error scanning stdin for no of rounds - exiting\n"); return(1); } num_chunks = max_threads*chperthread ; #else printf("no of chunks: ") ; if ((matches = scanf("%d", &num_chunks )) != 1) { printf("error scanning stdin for no of chunks - exiting\n"); return(1); } #endif printf("random seed: ") ; if ((matches = scanf("%d", &seed)) != 1) { printf("error scanning stdin for random seed - exiting\n"); return(1); } printf("\n"); DoneWithInput: if( num_chunks > MAX_BLOCKS ){ printf("Max %d chunks - exiting\n", MAX_BLOCKS ) ; return(1) ; } pthread_setconcurrency (max_threads); lran2_init(&rgen, seed) ; // Call allocator-specific initialization function mm_init(); numCPU=getNumProcessors(); #if defined(_MT) || defined(_REENTRANT) //#ifdef _MT runthreads(sleep_cnt, min_threads, max_threads, chperthread, num_rounds) ; #else runloops(sleep_cnt, num_chunks ) ; #endif #ifdef _DEBUG _cputs("Hit any key to exit...") ; (void)_getch() ; #endif return(0) ; } /* main */