Skip to content
Prev 34471 / 63424 Next

Fortran with OpenMP

Dear,

I wrote a code in Fortran using OpenMP. When testing the code in Fortran it was working. However, changing the code for the R, it does not indicate the use of threads, it should indicate.
I know that the R accepts the directives of OpenMP, but I can not use them correctly in R.
Below is a small sample code that should work with the use of OpenMP, but does not work when I use the R. 

	SUBROUTINE A1(N, A, B)
	  INCLUDE "omp_lib.h"
	  INTEGER :: I, N
	  DOUBLE PRECISION, DIMENSION(N) :: B(N), A(N)
	  LOGICAL :: OMP_IN_PARALLEL

!$OMP PARALLEL DO 
	  WRITE(*,*) OMP_IN_PARALLEL()
!$OMP DO
	  DO I=2,N
	    B(I) = (A(I) + A(I-1)) / 2.0
	  ENDDO
!$OMP END DO
!$OMP END PARALLEL
	END SUBROUTINE A1

# Compiling

R CMD SHLIB teste.f95 -o teste.so -fopenmp


# Output of the R

a <- rnorm(10)
b <- rnorm(10)
N <- length(a)
dyn.load("teste.so")
.Fortran("A1", as.integer(n), as.double(a),as.double(b))

F    ######### Should return TRUE and not FALSE

[[1]]
[1] 5

[[2]]
 [1] -1.0885364  0.4170852 -0.4627566  0.5662825 -1.9792053  1.0347733
 [7]  1.1615486  1.1752779  1.4337560 -0.2803431

[[3]]
 [1] -0.52768479 -0.33572564 -0.02283571  0.05176294 -0.70646140 -0.15066979
 [7] -0.82335438  1.20606866 -1.65533309  1.04965146


Somebody to say would know me where is the error?

Thank you very much!

? ???????????? F?bio Mathias Corr?a
Estat?stica e Experimenta??o Agropecu?ria/UFLA



      ____________________________________________________________________________________
Veja quais s?o os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com