Skip to contents

Time the multithreaded computation of Fibonacci numbers

Usage

fibonacci_omp(n)

Arguments

n

vector giving integers for which to compute the Fibonacci sum

Value

vector of integers giving the Fibonacci sum for each element in n

Details

The function being timed is the following:

int fib(int n) { return ((n <= 1) ? n : fib(n - 1) + fib(n - 2)); }

Runtime for computations less than n = 15 is nearly unmeasurable.

Examples

# \donttest{
fibonacci_omp(n = rep(10*(1:4), 10))
#>  [1]        55      6765    832040 102334155        55      6765    832040
#>  [8] 102334155        55      6765    832040 102334155        55      6765
#> [15]    832040 102334155        55      6765    832040 102334155        55
#> [22]      6765    832040 102334155        55      6765    832040 102334155
#> [29]        55      6765    832040 102334155        55      6765    832040
#> [36] 102334155        55      6765    832040 102334155
# this function creates a global environment variable "times"
times
#>       Name Milliseconds     SD Count
#> 1   fib_10        0.011  0.021    10
#> 2   fib_20        0.026  0.001    10
#> 3   fib_30        2.633  0.093    10
#> 4   fib_40      293.646 43.792    10
#> 5 fib_body      848.998  0.000     1
# }