Pthread calculating PI
2016-08-23
0 0 0
no vote
Other
Earn points
void *ThreadFunc(void *val)
{
int *value = (int *)val;
int myid = *value;
double factor = 0.0;
int my_n = num/threadNum;
int start = my_n*myid;
int last =start + my_n;
double my_sum = 0.0;
if(start % 2 == 0)
factor = 1.0;
else
factor = -1.0;
for (long long i = start; i < last; i++, factor = -factor)
{
my_sum += factor/(2*i + 1);
}
pthread_mutex_lock(&mutex);
pi_sum += my_sum;
pthread_mutex_unlock(&mutex);
return NULL;
}
{
int *value = (int *)val;
int myid = *value;
double factor = 0.0;
int my_n = num/threadNum;
int start = my_n*myid;
int last =start + my_n;
double my_sum = 0.0;
if(start % 2 == 0)
factor = 1.0;
else
factor = -1.0;
for (long long i = start; i < last; i++, factor = -factor)
{
my_sum += factor/(2*i + 1);
}
pthread_mutex_lock(&mutex);
pi_sum += my_sum;
pthread_mutex_unlock(&mutex);
return NULL;
}
c++
pi
PTHREAD
计算
Related Source Codes
TMS320F28335 DSP transmits data to EEPROM through
0
0
no vote
Local Path Planning Algorithm - DWA Algorithm
0
0
no vote
enDAQ-Shock-Data-Share-SRS-Blog
0
0
no vote
Calling chatGPT in a Windows application
0
0
no vote
Test Hello world
0
0
no vote
No comment