Displaying 3 results from an estimated 3 matches for "helloopenmp".
Did you mean:
hello_openmp
2019 Feb 01
2
Set the number of threads using openmp with .Fortran?
...!$call omp_set_num_threads(ncores)
!$omp parallel private(iam)
iam=omp_get_thread_num()
!$omp critical
write(*,*) 'Hello from', iam
!$omp end critical
!$omp end parallel
end subroutine hello
end module hello_openmp
*and this is my R function:*
#'@export
#'@useDynLib helloOpenMP, .registration = TRUE
hello <- function(ncores=4) {
.Fortran("hello", ncores = as.integer(ncores))
}
*Alas, when I call hello things only run with one thread:*
> hello(ncores = 2)$ncores
Hello from 0
[1] 2
Could you point me in the right direction? What am I missi...
2019 Feb 02
1
Set the number of threads using openmp with .Fortran?
...dows, is that correct?*
If so, what should I do? differently?
To get it to work on Linux, I modified my R script as follows:
#' OpenMP Hello World
#'
#' @param nthreads The number of threads that you want to use
#' @example
#' hello(nthreads=2)
#' @export
#' @useDynLib helloOpenMP, .registration = TRUE
hello <- function(nthreads=4) {
(OpenMPController::omp_set_num_threads(nthreads))
.Fortran("hello")
return('Each thread will say hi to you!')
}
> hello(nthreads = 2) Hello from 0
Hello from 1
[1] "Each thread will say...
2019 Feb 02
0
Set the number of threads using openmp with .Fortran?
...> iam=omp_get_thread_num()
> !$omp critical
> write(*,*) 'Hello from', iam
> !$omp end critical
> !$omp end parallel
> end subroutine hello
>
> end module hello_openmp
>
>
> *and this is my R function:*
>
> #'@export
> #'@useDynLib helloOpenMP, .registration = TRUE
>
> hello <- function(ncores=4) {
> .Fortran("hello", ncores = as.integer(ncores))
> }
>
>
> *Alas, when I call hello things only run with one thread:*
>
> > hello(ncores = 2)$ncores
> Hello from 0
> [1] 2
>
>...