Esempio n. 1
0
void *
work_thread (void *lp)
{
    int task_id = *((int *) lp);
    struct timeval start, finish;
	
    int begin, end;    
    begin = (nsize * task_id) / task_num + 1;
    end = (nsize * (task_id + 1)) / task_num;
  
    barrier (task_num);
    
    // start timer if first thread
    if(task_id==0)
        gettimeofday (&start, NULL);
    
    // function for each thread
    computeGauss(task_id);

    //computeGauss(task_id);
    barrier(task_num);
    
    // once all threads have completed, check the time 
    gettimeofday (&finish, NULL);
    
    // print out the time for only one thread
    if(task_id==0)
	fprintf(stdout, "Time:  %f seconds\n", (finish.tv_sec - start.tv_sec) + (finish.tv_usec - start.tv_usec)*0.000001);
}
Esempio n. 2
0
void *work_thread (void *lp) {
    int task_id = *((int *) lp);
    int begin, end;
    struct timeval start, finish;
    int i;
    /*get the divided task*/
    begin = (nsize * task_id) / task_num + 1;
    end = (nsize * (task_id + 1)) / task_num;
    if(task_id==0) gettimeofday (&start, NULL);
    fprintf (stderr, "thread %d: begin %d, end %d\n", task_id, begin, end);

    barrier (task_num);
    /* initialization */
    if (task_id == 0)
    initRHS(nsize, begin, end);
    barrier (task_num);
    initResult(nsize, begin, end);
    barrier (task_num);
    /* Gauss Compute */
    computeGauss(nsize, task_id);
    barrier (task_num);

    /* Gauss computation done */
    if(task_id==0) {
	/* Since there are dependencies in computing equation stage
    the upper part need the results of upper part), it should be done by thread 0 solely. */
        solveGauss(nsize);
        gettimeofday (&finish, NULL);
        printf ("Elapsed time: %.2f seconds\n",
	        (((finish.tv_sec * 1000000.0) + finish.tv_usec) -
	        ((start.tv_sec * 1000000.0) + start.tv_usec)) / 1000000.0);
    }
}
Esempio n. 3
0
void *
work_thread (void *lp)
{
    int task_id = *((int *) lp);
    struct timeval start, finish;

    barrier (task_num);

    if(task_id==0)
        gettimeofday (&start, NULL);

    computeGauss(task_id);

    barrier (task_num);
    gettimeofday (&finish, NULL);

    // if(task_id==0)
    //     printf ("Elapsed time: %.2f seconds\n",
    //         (((finish.tv_sec * 1000000.0) + finish.tv_usec) -
    //         ((start.tv_sec * 1000000.0) + start.tv_usec)) / 1000000.0);
    return 0;
}