The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:Elementary,Middle School,High School,College,University,PHD
MBA IT, Mater in Science and Technology Devry Jul-1996 - Jul-2000
Professor Devry University Mar-2010 - Oct-2016
Change this program into multi-threaded program, in this case 8 threads.
Do not modify anything in between the comments. Each thread only perform on the number it is given.Â
Â
#include <stdio.h>#include <sys/time.h>#define START_NUMBER 1#define END_NUMBER 10000FILE *f;int main() {// START: Do not modify anything herestruct timeval start_time, end_time;gettimeofday(&start_time, 0);long unsigned i;f = fopen("./squared_numbers.txt", "w");// END: Do not modify anything herefor (i=START_NUMBER; i<=END_NUMBER; i++) {fprintf(f, "%lu squared = %lu\n", i, i*i);}// START: Do not modify anything herefclose(f);gettimeofday(&end_time, 0);float elapsed = (end_time.tv_sec-start_time.tv_sec) * 1000.0f + \(end_time.tv_usec-start_time.tv_usec) /1000.0f;printf("took %0.2f milliseconds\n", elapsed);// END: Do not modify anything here}
-----------