Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

problem finding time

Sharada_Kulkarni
Beginner
301 Views

#include
#include
#include
#include
#define MAX 10000

void qsort(void);
void quicksort(int a[],int lo,int hi);

int main()
{

FILE *fp;
int i,n=0,j;
int a[MAX];
clock_t start,stop;
char ar[MAX];double startTime,endTime;

printf("Enter the file name \n");
scanf("%s",ar);
if((fp=fopen(ar,"r"))==NULL)
{
printf("Can't open file.\n");
exit(1);
}
i=fscanf(fp,"%d",&a);
while(i != EOF)
{
n++;
i=fscanf(fp,"%d",&a);
}
fclose(fp);

startTime = omp_get_wtime( );
start = clock( );
printf("\nn=%d,\nstart time=%10.9f\n",n,(((double)(start))/CLOCKS_PER_SEC));
quicksort(a,0,n-1);
stop = clock();
endTime=omp_get_wtime( );

printf("Elapsed time=%10.5f",endTime-startTime);
printf("\nstop=%10.9f\n",(((double)(stop))/CLOCKS_PER_SEC));
printf("Time taken :%10.9f sec",(((double)(stop-start))/CLOCKS_PER_SEC));
}

void quicksort(int a[],int lb,int ub)
{
int i,j,temp,key,flag=1;
if ( lb < ub )
{
i = lb;
j = ub + 1;
key = a [ lb ];
while ( flag )
{ i++;
while(a < key && i < ub )
i++;
j--;
while ( a [ j ] > key)
j--;
if ( i < j )
{
temp = a;
a = a;
a = temp;
}
else
flag = 0;
}
a[lb]=a;
a=key;
#pragma omp parallel sections
{
#pragma omp section
{ if(lb<(j-1))
quicksort(a,lb,j-1);
}
#pragma omp section
{
if ((j+1) quicksort(a,j+1,ub);
}
}
}
}

sorry !I had not submitted the full code.

Even when itestwith 1100 numbers there is no difference in the start and stop time(I am working on dual core machine). Please can anybody tell me why .
Which time functions I must use for serial codes to find elapsed time.(I am using intel C++)

0 Kudos
2 Replies
Quoc-An_L_Intel
Moderator
301 Views
See if this link and other time calculation references from MSDN.

http://en.allexperts.com/q/C-1040/time-milliseconds-Windows.htm
0 Kudos
TimP
Honored Contributor III
301 Views
clock() typically has a resolution of 0.010 seconds (10 milliseconds of CPU time between ticks). You could easily test it; write a program like:
loop until timer increases
display time
loop....
I'd be disappointed if omp_get_wtime() doesn't resolve intervals of 1 millisecond or less. On linux, where it typically is a wrapper for gettimeofday(), it's significantly better than that, but not as good as timers such as Windows QueryPerformanceCounter() or __rdtsc().
0 Kudos
Reply