#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
int main(int argc, char **argv)
{
    unsigned long long in = 1;
    unsigned long long total = 2;
    double tol , change, new, secs , old = 0.0;
    struct timeval start , end;
    int threads ; /* ignored */
    if ( argc < 2) {
        exit (-1);
    }
    threads = atoi ( argv[1]);
    tol = atof ( argv[2]);
    if (( threads < 1) || ( tol < 0.0)) {
        exit (-1);
    }
    tol = tol *tol;
    srand48(clock());
    gettimeofday (&start , NULL);
    do
    {
        double x, y;
        x = drand48();
        y = drand48();
        total ++;
        if (( x*x + y*y) <= 1.00)
            in ++;
        new = 4.0 * (double)in/( double)total ;
        change = fabs (new - old);
        old = new;
    }while (change > tol );
    gettimeofday (&end, NULL);
    secs = (( double)end.tv_sec - (double)start.tv_sec )
    + (( double)end.tv_usec - (double)start.tv_usec )/1000000.0;
    printf ( ”Found estimate of pi of %.12f in %llu iterations , %.6f seconds.n n”,
            new, total - 2, secs );
}
上記のコードは、円周率をどれだけ正確に推定するかの許容誤差を引数にとる逐次プログラムです。これらの古い値と新しい値の変化が許容範囲を下回ると、終了します。
このプログラムを pthreads で並列化する必要があります。私は誰かにそれをやらせようとしているのではなく、私がこれを行うことができるように、いくつかの指針とアイデアを考えてもらいたいと思っています. pthreads プログラムは、引数としてスレッド数と許容誤差を取り、推定値を出力します。私は並列プログラムに非常に慣れておらず、どこから始めればよいか本当にわからないので、アドバイスをいたします。ありがとう。