[Rd] Matrix with random number
Hello! I have a program in Fortran and would like to build a matrix with random numbers, I have a function in C. However, I have problems with the use of function in R. Code to compile: R CMD SHLIB mat.f myrbeta.c -o func.so Code in C. #include #include void F77_SUB(fseedi)(void){ GetRNGstate(); } void F77_SUB(fseedo)(void){ PutRNGstate(); } void F77_SUB(myrbeta)(double *px, double *pa, double *pb){ *px = rbeta(*pa,*pb); } Code in Fortran subroutine mat(x,l,c) integer l,c double precision x(l,c) integer i,j do j = 1, c do i = 1, l call fseedi() x(i,j) = call myrbeta(1,4,5) ! It's correct? call fseedo() enddo enddo end Thanks very much! -- Fábio Mathias Corrêa Estatística e Experimentação Agropecuária Fábio Mathias Corrêa UFLA [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Matrix with random number
Hello! I have a program in Fortran and would like to build a matrix with random numbers, I have a function in C. However, I have problems with the use of function in R. Code to compile: R CMD SHLIB mat.f myrbeta.c -o func.so Code in C. #include #include void F77_SUB(fseedi)(void){ GetRNGstate(); } void F77_SUB(fseedo)(void){ PutRNGstate(); } void F77_SUB(myrbeta)(double *px, double *pa, double *pb){ *px = rbeta(*pa,*pb); } Code in Fortran subroutine mat(x,l,c) integer l,c double precision x(l,c) integer i,j do j = 1, c do i = 1, l call fseedi() x(i,j) = call myrbeta(1,4,5) ! It's correct? call fseedo() enddo enddo end The code of the error in R is: dyn.load("func.so") Error in dyn.load("func.so") : unable to load shared library '/home/julio/Orientados/Fabio/Fortran/mat-fortran/func.so': /home/julio/Orientados/Fabio/Fortran/mat-fortran/func.so: undefined symbol: callmyrbeta_ Thanks very much! Fábio Mathias Corrêa UFLA [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Matrix with random number
Thanks Mr. Barry Rowlingson However, the matrix appears to zeros! Notice the code below! Please! Code in fortran subroutine mat(x,l,c,a) integer l,c double precision x(l,c), a integer i,j do j = 1, c do i = 1, l call fseedi() x(i,j) = myrbeta(a,1,2) call fseedo() enddo enddo end In R: dyn.load("func.so") x <- matrix(0,5,6) l <- nrow(x) c <- ncol(x) a <- 0 ..Fortran("mat", x = x, l, c, as.double(a)) Results: $x [,1] [,2] [,3] [,4] [,5] [,6] [1,] 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 [[2]] [1] 5 [[3]] [1] 6 [[4]] [1] 1 Thanks!!! Fábio Mathias Corrêa UFLA [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Matrix with random number
Thanks very much! Fábio Mathias Corrêa UFLA --- Em qua, 1/7/09, Kjell Konis escreveu: De: Kjell Konis Assunto: Re: [Rd] Matrix with random number Para: "Fabio Mathias" Cc: r-devel@r-project.org Data: Quarta-feira, 1 de Julho de 2009, 8:30 Hi Fabio, Your function myrbeta returns void so assigning the output isn't going to work. Instead you need to call it like a FORTRAN subroutine. Also, I added arguments for the parameters of the beta and moved the fseedi and fseedo calls outside of the loop. This is a pretty basic FORTRAN programming question and there are lots of books that can help you learn FORTRAN. subroutine mat(x,l,c,pa,pb) integer l,c double precision x(l,c), a integer i,j call fseedi() do j = 1, c do i = 1, l call myrbeta(x(i,j),pa,pb) enddo enddo call fseedo() end In R call it like this: storage.mode(x) <- "double" ..Fortran("mat", x = x, as.integer(l), as.integer(c), as.double(1), as.double(2)) Cheers, Kjell On 30 juin 09, at 20:02, Fabio Mathias wrote: > Thanks Mr. Barry Rowlingson > > However, the matrix appears to zeros! > > Notice the code below! Please! > > Code in fortran > > subroutine mat(x,l,c,a) > integer l,c > double precision x(l,c), a > integer i,j > do j = 1, c > do i = 1, l > call fseedi() > x(i,j) = myrbeta(a,1,2) > call fseedo() > enddo > enddo > end > > In R: > > dyn.load("func.so") > x <- matrix(0,5,6) > l <- nrow(x) > c <- > ncol(x) > a <- 0 > > ..Fortran("mat", x = x, l, c, as.double(a)) > > Results: > > $x > [,1] [,2] [,3] [,4] [,5] [,6] > [1,] 0 0 0 0 0 0 > [2,] 0 0 0 0 0 0 > [3,] 0 0 0 0 0 0 > [4,] 0 0 0 0 0 0 > [5,] 0 0 0 0 0 0 > > [[2]] > [1] 5 > > [[3]] > [1] 6 > > [[4]] > [1] 1 > > > Thanks!!! > > > Fábio Mathias Corrêa UFLA > > > > > > > [[elided Yahoo spam]] > > [[alternative HTML version deleted]] > > [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Generate random numbers in Fortran
Hi!!! It would like to know if it exists a form to use the functions to generate variates in FORTRAN with the same easiness I use that them in C? Or not? If yes. They would have some example? I would like to use the functions rbeta, rlnorm and others! Sorry my english..rsrsrs Thanks!!!             Fábio Mathias Corrêa   University Federal of the Lavras - Brazil Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Generate random numbers in Fortran
As I am wanting to generate a beta, then I created a function in C to generate a beta, but the problem appears when I go to compile My function in C is #include #include #include void F77_SUB(myrbeta)(double* px) {    GetRNGstate();    *px = rbeta(1.00,3.00);    PutRNGstate(); } My function in Fortran is subroutine blah(a) double precision (a) call myrbeta(RND) end The error fmc...@fmcron-desktop:~/teste$ R CMD SHLIB mat.c blah.f gcc -std=gnu99 -I/usr/share/R/include     -fpic -g -O2 -c mat.c -o mat.o gfortran  -fpic -g -O2 -c blah.f -o blah.o blah.f:1.1: subroutine blah(a)                                                     1 Erro: Non-numeric character in statement label at (1) blah.f:1.1: subroutine blah(a)                                                     1 Erro: Unclassifiable statement at (1) blah.f:2.1: double precision (a)                                                   1 Erro: Non-numeric character in statement label at (1) blah.f:2.1: double precision (a)                                                   1 Erro: Unclassifiable statement at (1) blah.f:4.1: end                                                                    1 Erro: Non-numeric character in statement label at (1) blah.f:4.1: end                                                                    1 Erro: Unclassifiable statement at (1) make: ** [blah.o] Erro 1             Fábio Mathias Corrêa                      UFLA --- Em sex, 13/2/09, Kjell Konis escreveu: De: Kjell Konis Assunto: Re: [Rd] Generate random numbers in Fortran Para: "fabio.u...@yahoo.com.br" Cc: "r-devel@r-project.org" Data: Sexta-feira, 13 de Fevereiro de 2009, 16:49 Take a look at section 6.6 in Writing R Extensions. It describes how to call C functions from FORTRAN. Basically it just boils down to this, in a C file define the functions void F77_SUB(fseedi)(void) { int x = 100; seed_in(&x); } void F77_SUB(fseedo)(void) { int x = 100; seed_out(&x); } void F77_SUB(myrunif)(double* px) { *px = unif_rand(); } Then you could write a FORTRAN subroutine like subroutine blah() implicit double precision (a-h,o-z) call fseedi() call myrunif(RND) call fseedo() end The fseed* subroutines only need to be called once, fseedi at the beginning of your FORTRAN code and fseedo at the end. HTH, Kjell On 13 févr. 09, at 17:32, Fabio Mathias wrote: > Hi!!! > It would like to know if it exists a form to use the functions to > generate variates in FORTRAN with the same easiness I use that them in > C? Or not? > If yes. They would have some example? I would like to use the functions rbeta, rlnorm and others! > > > Sorry my english..rsrsrs > > Thanks!!! > > > Fábio Mathias CorrêaUniversity Federal of the Lavras - Brazil > > > > Veja quais são os assuntos do momento no Yahoo! +Buscados > > [[alternative HTML version deleted]] > > Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] how to change nlme() contrast parametrization?
How to set the nlme() function to return the answer without the intercept parametrization? #= library(nlme) Soybean[1:3, ] (fm1Soy.lis <- nlsList(weight ~ SSlogis(Time, Asym, xmid, scal), data = Soybean)) (fm1Soy.nlme <- nlme(fm1Soy.lis)) fm2Soy.nlme <- update(fm1Soy.nlme, weights = varPower()) plot(ranef(fm2Soy.nlme, augFrame = TRUE), form = ~ Year * Variety, layout = c(3,1)) soyFix <- fixef(fm2Soy.nlme) options(contrasts = c("contr.treatment", "contr.poly")) (fm3Soy.nlme <- update(fm2Soy.nlme, fixed = Asym + xmid + scal ~ Year, start = c(soyFix[1], 0, 0, soyFix[2], 0, 0, soyFix[3], 0, 0))) # here I wouldn't like give the intercept parametrization but # the parameters by tratament with standard error. See: # before: # Fixed effects: list(Asym ~ Year * Variety, xmid ~ Year + Variety, scal - 1 ~ Year) # Value Std.Error DF t-value p-value # Asym.(Intercept) 19.43400 0.9537402 352 20.37661 0. # Asym.Year1989 -8.84208 1.0721164 352 -8.24731 0. # Asym.Year1990 -3.70719 1.1770024 352 -3.14969 0.0018 # after (I would like this): # Fixed effects: list(Asym ~ Year * Variety, xmid ~ Year + Variety, scal - 1 ~ Year) # Value Std.Error DF t-value p-value # Asym.Year1988 19.43400 0.9537402 352 20.37661 0. # Asym.Year1989 -8.84208 1.0721164 352 -8.24731 0. # Asym.Year1990 -3.70719 1.1770024 352 -3.14969 0.0018 #= Thanks in advance. Fábio Mathias Corrêa UFLA Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] how to change nlme() contrast parametrization?
How to set the nlme() function to return the answer without the intercept parametrization? #= library(nlme) Soybean[1:3, ] (fm1Soy.lis <- nlsList(weight ~ SSlogis(Time, Asym, xmid, scal), data = Soybean)) (fm1Soy.nlme <- nlme(fm1Soy.lis)) fm2Soy.nlme <- update(fm1Soy.nlme, weights = varPower()) plot(ranef(fm2Soy.nlme, augFrame = TRUE), form = ~ Year * Variety, layout = c(3,1)) soyFix <- fixef(fm2Soy.nlme) options(contrasts = c("contr.treatment", "contr.poly")) (fm3Soy.nlme <- update(fm2Soy.nlme, fixed = Asym + xmid + scal ~ Year, start = c(soyFix[1], 0, 0, soyFix[2], 0, 0, soyFix[3], 0, 0))) # here I wouldn't like give the intercept parametrization but # the parameters by tratament with standard error. See: # before: # Fixed effects: list(Asym ~ Year * Variety, xmid ~ Year + Variety, scal - 1 ~ Year) # Value Std.Error DF t-value p-value # Asym.(Intercept) 19.43400 0.9537402 352 20.37661 0. # Asym.Year1989 -8.84208 1.0721164 352 -8.24731 0. # Asym.Year1990 -3.70719 1.1770024 352 -3.14969 0.0018 # after (I would like this): # Fixed effects: list(Asym ~ Year * Variety, xmid ~ Year + Variety, scal - 1 ~ Year) # Value Std.Error DF t-value p-value # Asym.Year1988 19.43400 0.9537402 352 20.37661 0. # Asym.Year1989 -8.84208 1.0721164 352 -8.24731 0. # Asym.Year1990 -3.70719 1.1770024 352 -3.14969 0.0018 #= Thanks in advance. Fábio Mathias Corrêa UFLA Fábio Mathias Corrêa UFLA Veja quais são os assuntos do momento no Yahoo! +Buscados [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Namespace File
Dear Colleagues, I am developing a library. However I am having the following problem with the file NAMESPACE. My file contains: useDynLib(Bayesthres, vuA) export(Bayesthres, random.effects, fixed.effects, ) exportClasses("Bayesthres") My function is: Avuall <- function(Zz, Dd, A, Vu, FL) { m <- dim(A)[1] n <- dim(A)[2] tc <- length(Vu) ifc <- unlist(lapply(FL$fl, function(x) length(levels(x il <- 1 ic <- ifc[1] for(i in 2:tc){ ic[i] <- ifc[i]+ic[i-1] il[i] <- ic[i]-ifc[i]+1 } storage.mode(A) <- "double" Aux <- .Fortran("vuA", as.double(Vu), A=A, as.integer(ic), as.integer(il), as.integer(m), as.integer(n), as.integer(tc), PACKAGE="Bayesthres")$A V <- rbind(Zz, cbind(Dd,Aux)) return(V) } The vuA file was written in Fortran95. It's within the src directory. However the following error appears in R CMD check Error in .Fortran("vuA", as.double(Vu), A = A, as.integer(ic), as.integer(il), : name simbol in Fortran "vua" not is in DLL library "Bayesthres" Error : unable to load R code in package 'Bayesthres' ERROR: lazy loading failed for package ‘Bayesthres’ Where can I be wrong? Thank you very much! Fábio Mathias Corrêa Departamento de Estatística Universidade Estadual de Santa Cruz __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Namespace File
Dear colleagues, Problem solved with: ".First.lib" <- function(lib, pkg) { library.dynam("Bayesthres", package = pkg, lib.loc = lib) return(invisible(0)) } Fábio Mathias Corrêa Departamento de Estatística Universidade Estadual de Santa Cruz __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Namespace File
Dear Simon By using useDynLib (Bayesthres) in NAMESPACE file. Appeared another error: Error in dyn.load("Bayesthres.so") : unable to load shared object '/home/fmc/Bayesthres/Bayesthres.so': /home/fmc/Bayesthres/Bayesthres.so: cannot open shared object file: No such file or directory ERROR: lazy loading failed for package ‘Bayesthres’ * removing ‘/home/fmc/Bayesthres.Rcheck/Bayesthres’ Now he is not recognizing the file Bayesthres.so Grateful for the help. Fábio Mathias Corrêa Departamento de Estatística Universidade Estadual de Santa Cruz - Mensagem original De: Simon Urbanek Para: Fabio Mathias Corrêa Cc: r-devel@r-project.org Enviadas: Quarta-feira, 15 de Dezembro de 2010 13:41:34 Assunto: Re: [Rd] Namespace File On Dec 15, 2010, at 6:57 AM, Fabio Mathias Corrêa wrote: > Dear colleagues, > > > Problem solved with: > > > ".First.lib" <- function(lib, pkg) > { > library.dynam("Bayesthres", package = pkg, lib.loc = lib) > return(invisible(0)) > } > Well, that's shooting at a clay pigeon with a missile ;). You could have done the same simply using useDynLib(Bayesthres) in the NAMESPACE. Your issue is very likely just a mixup of cases as there is no "vuA" symbol in Fortran as all symbols are lower-case (at the object file level). Cheers, Simon __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Namespace File
Dear, I am using Ubuntu linux and R2.12.0 The trial version is in my home. \home\Bayesthres~$ To perform the R CMD check \home~$ R CMD check Bayesthres Within the directory Bayesthres, have: Directories: inst, man, R and src Files: DESCRIPTION AND NAMESPACE Best wishes Fábio ... but that's an entirely wrong place - I suspect you have some real issues in the way your package is constructed. Are you sure you have the correct layout and are using the *packaged* sources and not your working tree? (You didn't tell us anything about the package so there are many things that may be wrong - also you omitted the most basic details such as R version and platform...) Cheers, Simon Fábio Mathias Corrêa Departamento de Estatística Universidade Estadual de Santa Cruz __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Namespace File
The inst has CITATION only. Best wishes Fábio Mathias Corrêa Departamento de Estatística Universidade Estadual de Santa Cruz What is in inst? Make sure you have no binaries there. Cheers, Simon > > > Fábio Mathias Corrêa > Departamento de Estatística > Universidade Estadual de Santa Cruz > > > > > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Namespace File
See the complete log f...@raquel-laptop ~ $ R CMD check Bayesthres * using log directory ‘/home/fmc/Bayesthres.Rcheck’ * using R version 2.12.0 (2010-10-15) * using platform: i486-pc-linux-gnu (32-bit) * using session charset: UTF-8 * checking for file ‘Bayesthres/DESCRIPTION’ ... OK * this is package ‘Bayesthres’ version ‘0.1-0’ * checking package dependencies ... OK * checking if this is a source package ... WARNING Subdirectory ‘Bayesthres/src’ contains object files. * checking for executable files ... OK * checking whether package ‘Bayesthres’ can be installed ... ERROR Installation failed. See ‘/home/fmc/Bayesthres.Rcheck/00install.out’ for details. File 00install.out Error in dyn.load("Bayesthres.so") : unable to load shared object '/home/fmc/Bayesthres/Bayesthres.so': /home/fmc/Bayesthres/Bayesthres.so: cannot open shared object file: No such file or directory ERROR: lazy loading failed for package ‘Bayesthres’ * removing ‘/home/fmc/Bayesthres.Rcheck/Bayesthres’ Best wishes Fábio Mathias Corrêa Departamento de Estatística Universidade Estadual de Santa Cruz - Mensagem original De: Simon Urbanek Para: Fabio Mathias Corrêa Cc: R-devel Enviadas: Quarta-feira, 15 de Dezembro de 2010 17:10:21 Assunto: Re: [Rd] Namespace File On Dec 15, 2010, at 1:56 PM, Fabio Mathias Corrêa wrote: > Dear, > > I am using Ubuntu linux and R2.12.0 > The trial version is in my home. > > \home\Bayesthres~$ > > To perform the R CMD check > > \home~$ R CMD check Bayesthres > That is in general not a good idea, especially if you ever run things inside by hand for testing (because that will pollute the build). Make sure you clean your tree and use R CMD build followed by R CMD check on the resulting tar ball. Does the issue persist? > Within the directory Bayesthres, have: > > Directories: inst, man, R and src > What is in inst? Make sure you have no binaries there. Cheers, Simon > > ... but that's an entirely wrong place - I suspect you have some real issues > in > > the way your package is constructed. Are you sure you have the correct layout > and are using the *packaged* sources and not your working tree? (You didn't >tell > > us anything about the package so there are many things that may be wrong - > also > > you omitted the most basic details such as R version and platform...) > > Cheers, > Simon > > > > Fábio Mathias Corrêa > Departamento de Estatística > Universidade Estadual de Santa Cruz > > > > > __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Compile error gfortran-4.6
Dears, I am writing a code in Fortran using OpenMP directives. When compiling the code in gfortran 4.4 does not occur any problem. When compiling the code in gfortran 4.6, an error message appears. In other compilers the error does not occur. A small example. ## Code in Fortran subroutine hello() implicit none integer :: nthreads, tid integer :: omp_get_num_threads, omp_get_thread_num integer :: omp_get_max_threads, omp_set_num_threads print *, 'Máximo de threads', omp_get_max_threads() !$omp parallel tid = omp_get_thread_num() print *, 'Hello World from thread = ', tid print *, 'Number of threads =', omp_get_thread_num() !$omp end parallel end subroutine hello ### Compiling and testing system("R CMD COMPILE hello.f90 FCFLAGS=-fopenmp") system("R CMD SHLIB hello.o") dyn.load("hello.so") .Fortran("hello") ### Error message /home/fmcron/Documentos/Fortran/OpenMP/exemplos/hello.so: undefined symbol: _gfortran_transfer_character_write Thanks Fábio Mathias Corrêa Universidade Estadual de Santa Cruz Departamento de Ciências Exatas e da Terra - DCET Campus Soane Nazaré de Andrade, km 16 Rodovia Ilhéus-Itabuna CEP 45662-900. Ilhéus-Bahia Tel.: 73-3680-5076 [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Compile error with gfortran-4.6
Dears, I am writing a code in Fortran using OpenMP directives. When compiling the code in gfortran 4.4 does not occur any problem. When compiling the code in gfortran 4.6, an error message appears. In other compilers the error does not occur. A small example. ## Code in Fortran subroutine hello() implicit none integer :: nthreads, tid integer :: omp_get_num_threads, omp_get_thread_num integer :: omp_get_max_threads, omp_set_num_threads print *, 'Máximo de threads', omp_get_max_threads() !$omp parallel tid = omp_get_thread_num() print *, 'Hello World from thread = ', tid print *, 'Number of threads =', omp_get_thread_num() !$omp end parallel end subroutine hello ### Compiling and testing system("R CMD COMPILE hello.f90 FCFLAGS=-fopenmp") system("R CMD SHLIB hello.o") dyn.load("hello.so") .Fortran("hello") ### Error message /home/fmcron/Documentos/Fortran/OpenMP/exemplos/hello.so: undefined symbol: _gfortran_transfer_character_write Thanks Fábio Mathias Corrêa Universidade Estadual de Santa Cruz Departamento de Ciências Exatas e da Terra - DCET Campus Soane Nazaré de Andrade, km 16 Rodovia Ilhéus-Itabuna CEP 45662-900. Ilhéus-Bahia [[alternative HTML version deleted]] __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem with gfortran-4.6
Dears, I am writing a code in Fortran using OpenMP directives. When compiling the code in gfortran 4.4 does not occur any problem. When compiling the code in gfortran 4.6, an error message appears. In other compilers the error does not occur. A small example. ## Code in Fortran subroutine hello() implicit none integer :: nthreads, tid integer :: omp_get_num_threads, omp_get_thread_num integer :: omp_get_max_threads, omp_set_num_threads print *, 'Máximo de threads', omp_get_max_threads() !$omp parallel tid = omp_get_thread_num() print *, 'Hello World from thread = ', tid print *, 'Number of threads =', omp_get_thread_num() !$omp end parallel end subroutine hello ### Compiling and testing system("R CMD COMPILE hello.f90 FCFLAGS=-fopenmp") system("R CMD SHLIB hello.o") dyn.load("hello.so") .Fortran("hello") ### Error message /home/fmcron/Documentos/Fortran/OpenMP/exemplos/hello.so: undefined symbol: _gfortran_transfer_character_write Thanks Fábio Mathias Corrêa Universidade Estadual de Santa Cruz Departamento de Ciências Exatas e da Terra - DCET Campus Soane Nazaré de Andrade, km 16 Rodovia Ilhéus-Itabuna CEP 45662-900. Ilhéus-Bahia Tel.: 73-3680-5076 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Compile error with gfortran-4.6
Dear prof. Brian Ripley, Thanks for help! I compiled using the command: MAKEFLAGS="FCFLAGS=-fopenmp" R CMD SHLIB hello.f90 I use linux mint Maya, R 3.0.1 and gfortran 4.6.3. Thanks, Fábio Mathias Corrêa Universidade Estadual de Santa Cruz Departamento de Ciências Exatas e da Terra - DCET Campus Soane Nazaré de Andrade, km 16 Rodovia Ilhéus-Itabuna CEP 45662-900. Ilhéus-Bahia Tel.: 73-3680-5076 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Changing the compiler gfortran to ifort
I tried the manual R Installation and Administration to change the gcc compiler to icc and ifort for gfotran. However I could not find the correct path for the R to identify the icc and ifort. In which file I define the change of compiler? Thanks very much!!! Fábio Mathias Corrêa Estatística e Experimentação Agropecuária/UFLA Brazil Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem with function in fortran 95
I am writing a function in fortran 95, but the intrinsic function MATMUL is not working properly. Here's an example. SUBROUTINE mymult(x,y,res,m,n) IMPLICIT NONE INTEGER :: m,n REAL :: x, y, res DIMENSION :: x(m,n), y(n,m), res(m,m) res = MATMUL(x,y) END SUBROUTINE mymult R CMD SHLIB mat.f95 In R: dyn.load("mat.so") x <- matrix(1:20,5) l <- nrow(x) c <- ncol(x) y <- matrix(20:1,c) res <- matrix(0,l,l) dim(x) dim(y) dim(res) l c .Fortran("mymult", x,y,res,l,c) [[1]] [,1] [,2] [,3] [,4] [1,]16 11 16 [2,]27 12 17 [3,]38 13 18 [4,]49 14 19 [5,]5 10 15 20 [[2]] [,1] [,2] [,3] [,4] [,5] [1,] 20 16 1284 [2,] 19 15 1173 [3,] 18 14 1062 [4,] 17 13951 [[3]] [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]00000 [3,]00000 [4,]00000 [5,]00000 [[4]] [1] 5 [[5]] [1] 4 Linux Ubuntu 8.04 and use compiler gfortran 4.2. The problem is the compiler? Thanks! Fábio Mathias Corrêa Estatística e Experimentação Agropecuária/UFLA Brazil Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem with function in fortran 95
Thanks very much!!! Fábio Mathias Corrêa Estatística e Experimentação Agropecuária/UFLA --- Em sex, 14/8/09, Simone Giannerini escreveu: > De: Simone Giannerini > Assunto: Re: [Rd] Problem with function in fortran 95 > Para: "Fabio Mathias Corrêa" > Cc: r-devel@r-project.org > Data: Sexta-feira, 14 de Agosto de 2009, 9:19 > Fabio, > > I see two problems with your code: > > 1. R type numeric corresponds to FORTRAN Real*8 (or double > precision) > so that line 4 of your mat.f95 becomes: > > REAL*8 :: x, y, res > > 2. your R code won't ever succeed because you pass integer > matrices > (x,y,res) to a subroutine that expects REAL*8 data. > you need to coerce all your matrices to "double" as > follows: > > storage.mode(x) <- "double" > storage.mode(y) <- "double" > storage.mode(res) <- "double" > > Finally, you can call the corrected function: > > .Fortran("mymult", x,y,res,as.integer(l),as.integer(c)) > [[1]] > [,1] [,2] [,3] [,4] > [1,] 1 > 6 11 16 > [2,] 2 > 7 12 17 > [3,] 3 > 8 13 18 > [4,] 4 > 9 14 19 > [5,] > 5 10 15 20 > > [[2]] > [,1] [,2] [,3] [,4] [,5] > [1,] 20 16 12 > 8 4 > [2,] 19 15 11 > 7 3 > [3,] 18 14 10 > 6 2 > [4,] 17 13 > 9 5 1 > > [[3]] > [,1] [,2] [,3] [,4] [,5] > [1,] 604 468 332 > 196 60 > [2,] 678 526 374 > 222 70 > [3,] 752 584 416 > 248 80 > [4,] 826 642 458 > 274 90 > [5,] 900 700 500 300 100 > > [[4]] > [1] 5 > > [[5]] > [1] 4 > > > All these issues are discussed in the "Writing R > Extensions" manual, > please read it carefully. > > Ciao > > Simone > > > > On Wed, Aug 12, 2009 at 1:32 PM, Fabio Mathias > Corrêa > wrote: > > I am writing a function in fortran 95, but the > intrinsic function MATMUL is not working properly. Here's an > example. > > > > SUBROUTINE mymult(x,y,res,m,n) > > IMPLICIT NONE > > INTEGER :: m,n > > REAL :: x, y, res > > DIMENSION :: x(m,n), y(n,m), res(m,m) > > res = MATMUL(x,y) > > END SUBROUTINE mymult > > > > R CMD SHLIB mat.f95 > > > > In R: > > > > dyn.load("mat.so") > > x <- matrix(1:20,5) > > l <- nrow(x) > > c <- ncol(x) > > y <- matrix(20:1,c) > > res <- matrix(0,l,l) > > dim(x) > > dim(y) > > dim(res) > > l > > c > > .Fortran("mymult", x,y,res,l,c) > > > > [[1]] > > [,1] [,2] [,3] [,4] > > [1,] 1 6 11 16 > > [2,] 2 7 12 17 > > [3,] 3 8 13 18 > > [4,] 4 9 14 19 > > [5,] 5 10 15 20 > > > > [[2]] > > [,1] [,2] [,3] [,4] [,5] > > [1,] 20 16 12 8 4 > > [2,] 19 15 11 7 3 > > [3,] 18 14 10 6 2 > > [4,] 17 13 9 5 1 > > > > [[3]] > > [,1] [,2] [,3] [,4] [,5] > > [1,] 0 0 0 0 0 > > [2,] 0 0 0 0 0 > > [3,] 0 0 0 0 0 > > [4,] 0 0 0 0 0 > > [5,] 0 0 0 0 0 > > > > [[4]] > > [1] 5 > > > > [[5]] > > [1] 4 > > > > > > Linux Ubuntu 8.04 and use compiler gfortran 4.2. > > The problem is the compiler? > > > > Thanks! > > > > Fábio Mathias Corrêa > > Estatística e Experimentação Agropecuária/UFLA > > Brazil > > > > > > > > > Veja quais são os assuntos do momento no Yahoo! > +Buscados > > http://br.maisbuscados.yahoo.com > > > > __ > > R-devel@r-project.org > mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel > > > > > > -- > __ > > Simone Giannerini > Dipartimento di Scienze Statistiche "Paolo Fortunati" > Universita' di Bologna > Via delle belle arti 41 - 40126 Bologna, ITALY > Tel: +39 051 2098262 Fax: +39 051 232153 > http://www2.stat.unibo.it/giannerini/ > __ > Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem in matrix definition?
I'm implementing a function to compute the moore-penrose inverse, using a code from the article: Fast Computation of Moore-Penrose Inverse Matrices. Neural Information Processing - Letters and Reviews. Vol.8, No.2, August 2005 However, the R presents an error message when I use the geninv. The odd thing is that the error occurs for some arrays, however they have the same size. And the R indicates the lack of compatibility between the matrix! Below is an example: Creating the function geninv geninv <- function(x) { m <- dim(x)[1] n <- dim(x)[2] tr <- 0 if(m < n) { a <- tcrossprod(x) n <- m tr <- 1 } else a <- crossprod(x) dA <- diag(a) tol=min(dA[dA>0])*1e-9 L = a*0 r = 0 for(k in 1:n){ r = r+1 L[k:n,r] = a[k:n,k]-(L[k:n,1:(r-1)]%*%(t(L[k,1:(r-1)]))) if(L[k,r] > tol){ L[k,r] <- sqrt(L[k,r]) if (k < n) L[(k+1):n,r] <- L[(k+1):n,r]/L[k,r] } else r <- r-1 } L <- L[,1:r] M <- solve(crossprod(L)) if (tr == 1) Y <- t(x)%*%L%*%M%*%M%*%t(L) else Y <- L%*%M%*%M%*%t(L)%*%t(x) return(Y) } # Perfect result! This result is identical of the function ginv! library(MASS) mp <- 10 np <- 5 a <- matrix(c(1:mp*np),mp,np) dim(a) # 10,5 geninv(a) ginv(a) # Problem a <- matrix(c(1:50),mp,np) # The difference is the vector (1:50) dim(a) # 10,5 geninv(a) Error in L[k:n, 1:(r - 1)] %*% (t(L[k, 1:(r - 1)])) : arguments are not compatible The problem this in matrix definition? Thanks 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Problem in matrix definition?
The problem is that arrays are the same size. The only difference is how they were built! The way to build the matrix should not influence in the outcome! Below is the commented code in MatLab! Neural Information Processing - Letters and Reviews Vol.8, No.2, August 2005 function Y = geninv(G) % Returns the Moore-Penrose inverse of the argument % Transpose if m < n [m,n]=size(G); transpose=false; if m0))*1e-9; L=zeros(size(A)); r=0; for k=1:n r=r+1; L(k:n,r)=A(k:n,k)-L(k:n,1:(r-1))*L(k,1:(r-1))'; % Note: for r=1, the substracted vector is zero if L(k,r)>tol L(k,r)=sqrt(L(k,r)); if khttp://br.maisbuscados.yahoo.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Problem in matrix definition?
Thanks 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Compiling with High Performance Fortran
Dear, I looked in the list something on as to compile a code with access the High Performance FORTRAN using R CMD SHLIB, but I did not find. Would like to know if the accepted R this type of language? Thanks! 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Changing options in R CMD SHLIB
Dear, When trying to use directive OpenMP in my code, I observed that the directive ones were being considered as commentaries. Compiling with command R CMD SHLIB xxx.f95 - fopenmp and calling the function in the R verified that threads was not being considered. I was to observe the options of the compiler R CMD SHLIB --help Usage: R CMD SHLIB [options] files | linker options Build a shared library for dynamic loading from the specified source or object files (which are automagically made from their sources) or linker options. If not given via '--output', the name for the shared library is determined from the first source or object file. Options: -h, --help print short help message and exit -v, --version print version info and exit -o, --output=LIB use LIB as (full) name for the built library -c, --clean remove files created during compilation --preclean remove files created during a previous run -n, --dry-run dry run, showing commands that would be used Windows only: -d, --debug build a debug DLL How can I enable -fopenmp for use with R CMD SHLIB? 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Changing options in R CMD SHLIB
I use linux Mint and R.2.9.2 Thank you! Fábio Mathias Corrêa Estatística e Experimentação Agropecuária/UFLA --- Em ter, 20/10/09, Prof Brian Ripley escreveu: > De: Prof Brian Ripley > Assunto: Re: [Rd] Changing options in R CMD SHLIB > Para: "Fabio Mathias Corrêa" > Cc: r-devel@r-project.org > Data: Terça-feira, 20 de Outubro de 2009, 5:08 > Please see the manual -- 'Writing R > Extensions'. If you want to use > custom compiler flags, you use a Makevars or personal > .Makevars file. > Something like > > PKG_FCFLAGS=-fopenmp > > (you haven't told us your OS or version of R). > > On Mon, 19 Oct 2009, Fabio Mathias Corrêa wrote: > > > Dear, > > > > When trying to use directive OpenMP in my code, I > observed that the directive ones were being considered as > commentaries. > > Compiling with command R CMD SHLIB xxx.f95 - fopenmp > and calling the function in the R verified that threads was > not being considered. > > I was to observe the options of the compiler > > > > R CMD SHLIB --help > > > > Usage: R CMD SHLIB [options] files | linker options > > > > Build a shared library for dynamic loading from the > specified source or > > object files (which are automagically made from their > sources) or > > linker options. If not given via '--output', the > name for the shared > > library is determined from the first source or object > file. > > > > Options: > > -h, --help print short help message > and exit > > -v, --version print version info and > exit > > -o, --output=LIB use LIB as (full) name for > the built library > > -c, --clean remove files created > during compilation > > --preclean remove files created during > a previous run > > -n, --dry-run dry run, showing > commands that would be used > > > > Windows only: > > -d, --debug build a debug DLL > > > > > > How can I enable -fopenmp for use with R CMD SHLIB? > > > > > > Fábio Mathias Corrêa > > Estatística e Experimentação Agropecuária/UFLA > > -- > Brian D. Ripley, > rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, > Tel: +44 1865 272861 (self) > 1 South Parks Road, > +44 1865 > 272866 (PA) > Oxford OX1 3TG, UK > Fax: +44 1865 272595 Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Changing options in R CMD SHLIB
Dear, I managed to use directives OpenMP in R. To compile I used the gfortran directly. For example: gfortran-shared-O2 teste.f90-fopenmp-fPIC By using the code in R, it works perfectly! However, I need to use some specific libraries of R, for use in C functions in Fortran 95. When compiling using the command: gfortran-shared-O2-o teste.f90 myrandom.c func.out -fopenmp -fPIC However, I need to indicate the path for the compiler to use the files of the type: Rmath.h, R.h and others. I observed the project ROMP and the library Rcsdp. The developers of the library Rcsdp in the installation file present the following modification in the compiler for enable the OpenMP. CFLAGS=CFLAGS=-O3 -march=nocona -m64 -fprefetch-loop-arrays -ftree-vectorize -ftree-vectorizer-verbose=1 -fopenmp -ansi -Wall -DNOSHORTS -DBIT64 -DUSEOPENMP -I../include LIBS=LIBS=-static -L../lib -lsdp -llapack -lptf77blas -lptcblas -latlas -lgomp -lrt -lpthread -lgfortran -lm I already tried ~/Fortran/parallel/tri $ export PKG_FCFLAGS= -fopenmp bash: export: `-fopenmp': not a valid identifier I could indicate the path of the files R.h, Rmath.h and other to the gfortran? How? Thank you! 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Changing options in R CMD SHLIB
Thank you very much!!! Problem solved!! I use export PKG_FCFLAGS=-fopenmp > dyn.load("teste.so") > system.time(abc3 <- .Fortran("mxv", as.integer(m), as.integer(n), > as.double(a), b, as.double(c))) In parallel region - Thread ID1 In parallel region - Thread ID1 In parallel region - Thread ID1 In parallel region - Thread ID1 In parallel region - Thread ID1 In parallel region - Thread ID0 In parallel region - Thread ID0 In parallel region - Thread ID0 In parallel region - Thread ID0 In parallel region - Thread ID0 user system elapsed 0 0 0 Fábio Mathias Corrêa Estatística e Experimentação Agropecuária/UFLA --- Em ter, 20/10/09, Prof Brian Ripley escreveu: > De: Prof Brian Ripley > Assunto: Re: [Rd] Changing options in R CMD SHLIB > Para: "Fabio Mathias Corrêa" > Cc: r-devel@r-project.org > Data: Terça-feira, 20 de Outubro de 2009, 5:08 > Please see the manual -- 'Writing R > Extensions'. If you want to use > custom compiler flags, you use a Makevars or personal > .Makevars file. > Something like > > PKG_FCFLAGS=-fopenmp > > (you haven't told us your OS or version of R). > > On Mon, 19 Oct 2009, Fabio Mathias Corrêa wrote: > > > Dear, > > > > When trying to use directive OpenMP in my code, I > observed that the directive ones were being considered as > commentaries. > > Compiling with command R CMD SHLIB xxx.f95 - fopenmp > and calling the function in the R verified that threads was > not being considered. > > I was to observe the options of the compiler > > > > R CMD SHLIB --help > > > > Usage: R CMD SHLIB [options] files | linker options > > > > Build a shared library for dynamic loading from the > specified source or > > object files (which are automagically made from their > sources) or > > linker options. If not given via '--output', the > name for the shared > > library is determined from the first source or object > file. > > > > Options: > > -h, --help print short help message > and exit > > -v, --version print version info and > exit > > -o, --output=LIB use LIB as (full) name for > the built library > > -c, --clean remove files created > during compilation > > --preclean remove files created during > a previous run > > -n, --dry-run dry run, showing > commands that would be used > > > > Windows only: > > -d, --debug build a debug DLL > > > > > > How can I enable -fopenmp for use with R CMD SHLIB? > > > > > > Fábio Mathias Corrêa > > Estatística e Experimentação Agropecuária/UFLA > > -- > Brian D. Ripley, > rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, > Tel: +44 1865 272861 (self) > 1 South Parks Road, > +44 1865 > 272866 (PA) > Oxford OX1 3TG, UK > Fax: +44 1865 272595 Veja quais são os assuntos do momento no Yahoo! +Buscados http://br.maisbuscados.yahoo.com __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Error when compiling code in C
Dear, I used the command in the terminal to compile code FORTRAN with directive OpenMP export PKG_FCFLAGS=-fopenmp It functioned perfectly for pure code FORTRAN. However, when I call a function in C in code FORTRAN, the function in C is not compiled. The following error appears ~/Fortran/parallel $ R CMD SHLIB para.f95 myrandom.c -o func.so -fopenmp gfortran -fopenmp -fpic -g -O -c para.f95 -o para.o gcc -std=gnu99 -I/usr/share/R/include -fpic -g -O2 -c myrandom.c -o myrandom.c@ gfortran -shared -o func.so para.o myrandom.o -fopenmp -L/usr/lib64/R/lib -lR gfortran: myrandom.o: No such file or directory make: *** [func.so] Error 1 When compile only the function in code FORTRAN. The archive is compiled! If compile only the function in C, the error I appear! What it is occurring is that instead of generating an archive myrandom.o the compiler is generating an archive myrandom.c@ What I must make? 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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel