示例#1
0
void fibSeq(int term1, int term2, std::vector<int>& pairVec) {
    if (!(term2 % 2)) {
        pairVec.push_back(term2);
    }

    if (term2 < 4000000) {
        fibSeq(term2, (term1 + term2), pairVec);
    }
}
示例#2
0
int problem2() {
    int sum = 0;

    std::vector<int> pairVec;

    fibSeq(1, 2, pairVec);

    for (auto x: pairVec) sum += x;

    return sum;
}
void *testThread(void *threadid)
{
   double DT=0.0;
   int i;

   // THREADED TEST
   //

   // Start time for all threads
   startTOD=readTOD();

   for(i=0;i<NUM_THREADS;i++)
	{

//-----------------------------------------------------------------
///CODE ADDED HERE

       nowTOD = readTOD();
       syslog(LOG_INFO, "\nCreating Thread %d\n",i);
       syslog(LOG_INFO, "\nTimeis:%lf sec \n", nowTOD);
//=================================================================
       //printf("\nCreating thread %d \n",i); 
       pthread_create(&threads[i], &rt_sched_attr, fibSeq, (void *)i);
	}
	
   for(i=0;i<NUM_THREADS;i++)
       {

       
       pthread_join(threads[i], NULL);

//-----------------------------------------------------------------
///CODE ADDED HERE
       nowTOD = readTOD();
       syslog(LOG_INFO, "\nJoining Thread %d \n",i);
       syslog(LOG_INFO, "\nTimeis:%lf sec \n", nowTOD);
//=================================================================
       }
   // Stop time for all threads
   stopTOD=readTOD();

   DT = elapsedTOD(stopTOD, startTOD);
   printf("Threaded:   Fib(%llu)\t\t\t\t%lf secs\n", (seqIterations*Iterations), DT);


   // SEQUENTIAL TEST
   //

   // Start time for sequential function calls
   startTOD=readTOD();

   for(i=0;i<NUM_THREADS;i++)
       fibSeq((void *)i);

   // Stop time for sequential function calls
   stopTOD=readTOD();

   DT = elapsedTOD(stopTOD, startTOD);
   printf("Sequential: Fib(%llu)\t\t\t\t%lf secs\n", (seqIterations*Iterations), DT);

}