cpp: #include <stdio.h>\n#include <assert.h>\nunsigned int input = 30;\nint fib(unsigned int n)\n{\n  if (n<2)\n    return n;\n  else\n  {\n    int i, j;\n#pragma omp task shared(i)\n    i=fib(n-1);\n#pragma omp task shared(j)\n    j=fib(n-2);\n#pragma omp taskwait\n    return i+j;\n  }\n}\nint main()\n{\n  int result = 0;\n#pragma omp parallel\n  {\n   #pragma omp single\n    {\n      result = fib(input);\n    }\n  }\n  printf ("Fib(%d)=%d\n", input, result);\n  assert (result==832040);\n  return 0;\n}\n
fortran: module DRB105\n    implicit none\n    integer input\ncontains\n    recursive function fib(n) result(r)\n        use omp_lib\n        implicit none\n        integer :: n, i, j, r\n\n        if (n<2) then\n            r = n\n        else\n            !$omp task shared(i)\n            i = fib(n-1)\n            !$omp end task\n            !$omp task shared(j)\n            j = fib(n-2)\n            !$omp end task\n            !$omp taskwait\n            r = i+j\n        end if\n    end function\nend module\n\nprogram DRB105_taskwait_orig_no\n    use omp_lib\n    use DRB105\n    implicit none\n\n    integer :: result\n    input = 30\n\n    !$omp parallel\n    !$omp single\n    result = fib(input)\n    !$omp end single\n    !$omp end parallel\n\n    print 100, input, result\n    100 format ('Fib for ',3i8,' =',3i8)\nend program