#include<iostream>
#include<string>
#include<pthread.h>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<cstdio>
#include<sys/time.h>
#define MAX 100000000
using namespace std;
double result = 0;
int thread_num;
int Every_P;
pthread_mutex_t mut;
void *t_hread(void *arg){
int m = *(int*)arg;
if(m != thread_num - 1){
for(int i = m * Every_P;i < (m + 1) * Every_P;i++){
double x = sqrt(MAX) * sqrt(MAX - ((i + 0.5)/MAX)*(i + 0.5));
int xx = x;
double count;
if((x - xx) > 0.5){
count = xx + 1;
}
else{
count = xx;
}
pthread_mutex_lock(&mut);
result = result + (double)count/MAX;
pthread_mutex_unlock(&mut);
}
}
if(m == thread_num - 1){
for(int i = m * Every_P;i < MAX;i++){
double x = sqrt(M
蒙特卡洛法多线程求圆周率
最新推荐文章于 2025-03-27 16:30:45 发布