c++ - Clock_gettime() function outputting incorrect time -


i trying runtime of following code using clock_gettime function. when running code receiving time of 0.0000 every time runs. have output start , stop time individually , receiving exact same answer.

struct timespec start, stop; double accum;  if( clock_gettime( clock_realtime, &start) == -1 ) {   perror( "clock gettime" );   exit( exit_failure ); }  int src = 1, final_ret = 0; (int t = 0; t < rows - 1; t += pyramid_height) {     int temp = src;     src = final_ret;     final_ret = temp;      // calculate kernel argument...     int arg0 = min(pyramid_height, rows-t-1);     int thehalo = halo;      // set kernel arguments.     clsetkernelarg(cl.kernel(kn), 0,  sizeof(cl_int), (void*) &arg0);     clsetkernelarg(cl.kernel(kn), 1,  sizeof(cl_mem), (void*) &d_gpuwall);     clsetkernelarg(cl.kernel(kn), 2,  sizeof(cl_mem), (void*) &d_gpuresult[src]);     clsetkernelarg(cl.kernel(kn), 3,  sizeof(cl_mem), (void*) &d_gpuresult[final_ret]);     clsetkernelarg(cl.kernel(kn), 4,  sizeof(cl_int), (void*) &cols);     clsetkernelarg(cl.kernel(kn), 5,  sizeof(cl_int), (void*) &rows);     clsetkernelarg(cl.kernel(kn), 6,  sizeof(cl_int), (void*) &t);     clsetkernelarg(cl.kernel(kn), 7,  sizeof(cl_int), (void*) &bordercols);     clsetkernelarg(cl.kernel(kn), 8,  sizeof(cl_int), (void*) &thehalo);     clsetkernelarg(cl.kernel(kn), 9,  sizeof(cl_int) * (cl.localsize()), 0);     clsetkernelarg(cl.kernel(kn), 10, sizeof(cl_int) * (cl.localsize()), 0);     clsetkernelarg(cl.kernel(kn), 11, sizeof(cl_mem), (void*) &d_outputbuffer);     cl.launch(kn); }  if( clock_gettime( clock_realtime, &stop) == -1 ) {   perror( "clock gettime" );   exit( exit_failure ); } printf( "%lf\n", stop.tv_sec );   printf( "%lf\n", start.tv_sec );   accum = ( stop.tv_sec - start.tv_sec )       + ( stop.tv_nsec - start.tv_nsec )         / billion; printf( "%lf\n", accum ); 

any advice on i'm doing wrong appreciated

timespec::tv_nsec integer type, if billion integer type then:

( stop.tv_nsec - start.tv_nsec )     / billion; 

will truncate zero. if tv_sec values same 0 difference.

try:

double( stop.tv_nsec - start.tv_nsec )     / billion; 

that perform division double type.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -