src/bisection.c
/** Finds all zeros in the interval [a, b]. This procedure
    divides the interval [a, b] into N smaller interval and
    then uses bisection on each of the subintervals. **/
Finds all zeros in the interval [a, b]. This procedure
divides the interval [a, b] into N smaller interval and
then uses bisection on each of the subintervals.
Finds all zeros in the interval [ a b ] . This procedure divides the interval [ a b ] into N smaller interval and then uses bisection on each of the subintervals .
array *find_all_zeros_bisection(double (*fun_ptr)(double), double a, double b, int N, int T) {
    array *zeros = malloc(sizeof(array));
    zeros->ptr = malloc(N*sizeof(double));
    zeros->size = 0;
    double dn = (b-a)/((double) N);
    double xl, xu;
    int chunk = ceil(N/(double)T);
#pragma omp parallel for num_threads(T) schedule(static, chunk) private(xl, xu)
    for (int i = 0; i < N; i++) {
        xl = a + dn*i;
        xu = a + dn*(i+1);
        zeros->ptr[i] = find_zero_bisection(fun_ptr, xl, xu);
    }
    for (int i = 0; i < N; i++) {
        if (zeros->ptr[i] != -1) {
            zeros->ptr[zeros->size] = zeros->ptr[i];
            zeros->size++;
        }
    }
    zeros->ptr = realloc(zeros->ptr, zeros->size*sizeof(double));
    return zeros;
}
array * find_all_zeros_bisection ( double ( * fun_ptr ) ( double ) , double a , double b , int N , int T ) { array * zeros = malloc ( sizeof ( array ) ) ; zeros -> ptr = malloc ( N * sizeof ( double ) ) ; zeros -> size = 0 ; double dn = ( b - a ) / ( ( double ) N ) ; double xl , xu ; int chunk = ceil ( N / ( double ) T ) ; #pragma  omp parallel for num_threads(T) schedule(static, chunk) private(xl, xu) for ( int i = 0 ; i < N ; i ++ ) { xl = a + dn * i ; xu = a + dn * ( i + 1 ) ; zeros -> ptr [ i ] = find_zero_bisection ( fun_ptr , xl , xu ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( zeros -> ptr [ i ] != -1 ) { zeros -> ptr [ zeros -> size ] = zeros -> ptr [ i ] ; zeros -> size ++ ; } } zeros -> ptr = realloc ( zeros -> ptr , zeros -> size * sizeof ( double ) ) ; return zeros ; }
Finds all zeros in the interval [a, b].
Finds all zeros in the interval [ a b ] .
/* collect the found zeros */