<commit_before>#include <iostream>
#include <omp.h>

int main() {
    long num_steps = 1000;
    double step = 0;
    double x, pi, sum = 0.0;

    step = 1.0 / (double) num_steps;

    omp_set_num_threads(10);
    #pragma omp parallel for
    for (int i = 0; i < num_steps ; ++i) {
        x = (i + 0.5) * step;
#pragma omp critical
        {
            sum = sum + 4.0 / (1 + x * x);
        }
    }

    pi = step * sum;
    std::cout << pi;
    return 0;
}<commit_msg>adds critical usage in integral<commit_after>#include <iostream>
#include <omp.h>

void calculation1();

void calculation2();

int main() {
//    calculation1();
    calculation2();
}


void calculation1() {
    int NTHREADS = 48, nthreads;
    long num_steps = 100000000;
    double step = 0;
    double pi = 0.0;
    double sum[NTHREADS];

    step = 1.0 / (double) num_steps;
    double timer_start = omp_get_wtime();
    omp_set_num_threads(NTHREADS);

    #pragma omp parallel
    {
        int i, id, lnthreads;
        double x;

        lnthreads = omp_get_num_threads();
        id = omp_get_thread_num();
        if (id == 0)
            nthreads = lnthreads;

        for (i = id, sum[id]=0; i < num_steps; i+=lnthreads) {
            x = (i+0.5) * step;
            sum[id] += 4.0 / (1.0 + x*x);
        }

    }
    for (int i = 0; i < nthreads; ++i) {
        pi += sum[i] * step;
    }

    double timer_took = omp_get_wtime() - timer_start;
    std::cout << pi << " took " << timer_took;

    // 1 threads  --> 0.57 seconds.
    // 4 threads  --> 1.34 seconds.
    // 24 threads --> 0.59 seconds.
    // 48 threads --> 0.46 seconds.
}



void calculation2() {
    int NTHREADS = 4;
    long num_steps = 100000000;
    double step = 0;
    double pi = 0.0;

    step = 1.0 / (double) num_steps;
    double timer_start = omp_get_wtime();
    omp_set_num_threads(NTHREADS);

    #pragma omp parallel
    {
        int i, id, lnthreads;
        double x, sum = 0;

        lnthreads = omp_get_num_threads();
        id = omp_get_thread_num();

        for (i = id; i < num_steps; i+=lnthreads) {
            x = (i+0.5) * step;
            sum += 4.0 / (1.0 + x*x);
        }

        #pragma omp atomic
        pi += sum * step;

    }

    double timer_took = omp_get_wtime() - timer_start;
    std::cout << pi << " took " << timer_took;
    // 1 threads  --> 0.53 seconds.
    // 4 threads  --> 0.25 seconds.
    // 24 threads --> 0.24 seconds.
    // 48 threads --> 0.21 seconds.
}
{'fraction_non_alphanumeric': 0.1465587044534413, 'fraction_numerical': 0.04331983805668016, 'mean_word_length': 1.8369690011481057, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2834009', 'n_tokens_mistral': 987, 'n_tokens_neox': 885, 'n_words': 240}