c++ - OpenMP unpredictable overhead -
i have simple openmp code runs 4 empty threads , reports time:
#include "omp.h" #include <sys/time.h> #include <cstdio> double start_time; void process_thread() { } int main(){ struct timeval tv; gettimeofday(&tv, null); start_time = 1000*((double)tv.tv_sec + 1e-6*(double)tv.tv_usec); printf("beginning time: %.3fms ",start_time-start_time); #pragma omp parallel schedule(static,1) for(int i=0;i<4;i++) process_thread(); gettimeofday(&tv, null); double cur_time = 1000*((double)tv.tv_sec + 1e-6*(double)tv.tv_usec); printf("finishing time: %.3fms\n\n",cur_time-start_time); }
without openmp running time small , consistent:
beginning time: 0.000ms finishing time: 0.050ms beginning time: 0.000ms finishing time: 0.050ms beginning time: 0.000ms finishing time: 0.049ms beginning time: 0.000ms finishing time: 0.049ms beginning time: 0.000ms finishing time: 0.050ms beginning time: 0.000ms finishing time: 0.049ms beginning time: 0.000ms finishing time: 0.051ms beginning time: 0.000ms finishing time: 0.063ms beginning time: 0.000ms finishing time: 0.050ms beginning time: 0.000ms finishing time: 0.051ms
however, when use openmp takes longer , time becomes inconsistent:
beginning time: 0.000ms finishing time: 0.497ms beginning time: 0.000ms finishing time: 1.001ms beginning time: 0.000ms finishing time: 0.484ms beginning time: 0.000ms finishing time: 16.728ms beginning time: 0.000ms finishing time: 4.205ms beginning time: 0.000ms finishing time: 6.041ms beginning time: 0.000ms finishing time: 3.754ms beginning time: 0.000ms finishing time: 4.126ms beginning time: 0.000ms finishing time: 0.230ms beginning time: 0.000ms finishing time: 0.183ms beginning time: 0.000ms finishing time: 2.438ms beginning time: 0.000ms finishing time: 0.248ms
i under impression openmp overheads in range of 150ms seems way more.
i use xeon e5 1650 6 cores ubuntu 12.04. use gcc 4.6.3. have tried other openmp configurations static works best case.
what responsible fluctuation? fault of compiler, openmp runtime, os, or else? how can improve it?
Comments
Post a Comment