The taskwait directive ensures that the two tasks Until the argument passed to fib() is less than 2. Each of the calls to fib(n-1) and fib(n-2) will in turn generate two tasks. The return values are added together to produce the value returned by fib(n). One of the tasks computes fib(n-1) and the other computes fib(n-2), and The call to fib(n) generates two tasks, indicatedīy the task directive. That only one of the threads will execute the print statement In the parallelĬonstruct, the single directive is used to indicate In the example, the parallel directive denotesĪ parallel region which will be executed by four threads. In the above example, we have used eight terms.The following C/C++ program illustrates how the OpenMP task and taskwait directives can be used to compute Fibonacci numbers recursively. It is done until the number of terms you want or requested by the user. The next term is generated by using the second and third terms and not using the first term. The third term is made by adding the first two terms. In the above example, 0 and 1 are the first two terms of the series. 3 is calculated by adding the two numbers preceding it (1+2),.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |