Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This code isn't running because of the rand _ r in line 8 3 . Can you help me fix it ? #include #include #include
This code isn't running because of the randr in line Can you help me fix it
#include
#include
#include
#define MAXTHREADS
void computepivoid ;
long samplepoints;
long totalhits;
long totalmisses;
long hitsMAXTHREADS;
long samplepointsperthread;
int numthreads;
int mainint argc, char argv
local variables
int ii;
int retval;
pthreadt pthreadsMAXTHREADS;
pthreadattrt attr;
double computedpi;
initialize local variables
retval ;
pthreadattrinit&attr;
pthreadattrsetscope&attr, PTHREADSCOPESYSTEM;
parse command line arguments into sample points and number of threads
there is no error checking here!!!!!
samplepoints atolargv;
numthreads atoiargv;
uncomment this block if you want interactive input!!!!
if socomment out the two statements above
printf "Enter number of sample points: ;
scanfd &samplepoints ;
printf "Enter number of threads: ;
scanfd &numthreads ;
totalhits ;
samplepointsperthread samplepoints numthreads;
for ii ; ii numthreads; ii
hitsii ii;
pthreadcreate&pthreadsii &attr, computepivoid &hitsii;
for ii ; ii numthreads; ii
pthreadjoinpthreadsii NULL;
totalhits hitsii;
computedpi doubletotalhits doublesamplepoints;
printfComputed PI lf
computedpi;
return to calling environment
return retval;
void computepivoid s
int seed;
long ii;
long hitpointer;
long localhits;
double randnox;
double randnoy;
hitpointer long s;
seed hitpointer;
localhits ;
for ii ; ii samplepointsperthread; ii
randnox doublerandr&seeddoubleRANDMAX;
randnoy doublerandr&seeddoubleRANDMAX;
if randnox randnox
randnoy randnoy
localhits;
seed ii;
hitpointer localhits;
pthreadexit;
Promppt: The first part of this assignment is to explore the use of threads in an application that computes PI Download the computepimontecarlo.c compile: gcc computepimontecarlo.c o pi lpthreadexecute: pi program to your Project subdirectory. Compile and run this program a few times to understand the basic operation and to verify that it does approximate PI Next, time your program andor add appropriate timing system calls to your code. Run the application varying the number of threads and number of sample points. You may get a core dump when you exceed the number of threads permitted note that value Record the times it takes your program to execute when changing the number of threads and number of sample points.
Create a plot of time vs number of threads when the number of sample points is fixed.
Create a plot of time vs number of sample points when the number of threads is fixed.
Use an Excel like application to create your plot
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started