Problem with correct installation of rstan - installation

I'm using R 4.2.2, RTools 42, both installed in D:, and tried to install Rstan and bmrs to solve problems of a Bayesian stat course. I have also a "Makevar" file in ~\.R folder containing:
CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function
Honestly, I don't know what the above code does!
I tried to run the following code:
fit_press <- brm(rt ~ 1,
data = df_spacebar,
family = gaussian(),
prior = c(
prior(uniform(0, 60000), class = Intercept, lb = 0, ub = 60000),
prior(uniform(0, 2000), class = sigma, lb = 0, ub = 2000)
),
chains = 4,
iter = 2000,
warmup = 1000
)
and got the following Error:
Compiling Stan program...
Error in compileCode(f, code, language = language, verbose = verbose) :
In addition: Warning message:
In system2(cmd, args = paste(" CMD SHLIB", basename(libCFile)), :
'CreateProcess' failed to run 'D:\Program Files\R\R-4.2.2\bin\x64\R.exe CMD SHLIB file1ec818233.cpp'
Error in sink(type = "output") : invalid connection
Any suggestions?
Thank you very much in advance.

Related

OpenMP parameter sweep parallel

I am new to OpenMP. I want to solve a stiff ODE system for a range of parameter values using parallel do loops. I use the following code in Fortran given below. However, I do not know whether calling a stiff solver(as a subroutine) inside a parallel do loop is allowed or not? Also, I want to write the time series data into files with filenames such as "r_value_s__value.txt" in the subroutine before the return to the main program. Can anyone help. Below is the code and the error. I used gfortran with flags -fopenmp to compile.
PROGRAM OPENMP_PARALLEL_STIFF
USE omp_lib
IMPLICIT NONE
INTEGER :: I, J
INTEGER, PARAMETER :: RTOT=10, STOT=15
INTEGER :: TID
INTEGER, PARAMETER :: NUM_THREADS=8
DOUBLE PRECISION :: T_INITIAL, T_FINAL
CALL OMP_SET_NUM_THREADS(NUM_THREADS)
CALL CPU_TIME(T_INITIAL)
PRINT*, "TIME INITIAL ",T_INITIAL
!$OMP PARALLEL DO PRIVATE(I,J,TID)
DO I=1,RTOT
DO J=1,STOT
TID=OMP_GET_THREAD_NUM()
CALL STIFF_DRIVER(TID,I,J,RTOT,STOT)
END DO
END DO
!$OMP END PARALLEL DO
CALL CPU_TIME(T_FINAL)
PRINT*, "TIME FINAL ",T_FINAL
PRINT*, "TIME ELAPSED ",(T_FINAL-T_INITIAL)/NUM_THREADS
END PROGRAM OPENMP_PARALLEL_STIFF
SUBROUTINE STIFF_DRIVER(TID,II,JJ,RTOT,STOT)
USE USEFUL_PARAMETERS_N_FUNC
USE DVODE_F90_M
! Type declarations:
IMPLICIT NONE
! Number of odes for the problem:
INTEGER :: SERIAL_NUMBER, TID
INTEGER :: II, JJ, RTOT, STOT, IND
INTEGER :: J, NTOUT
INTEGER :: ITASK, ISTATE, ISTATS, I
! parameters : declaration
DOUBLE PRECISION, PARAMETER :: s0=0.450D0, dr=1.0D-4, ds=1.0D-2
DOUBLE PRECISION, DIMENSION(NEQ) :: Y, YOUT
DOUBLE PRECISION :: ATOL, RTOL, RSTATS, T, TOUT, EPS, TFINAL, DELTAT
DIMENSION :: RSTATS(22), ISTATS(31)
DOUBLE PRECISION :: bb, cc, ba, ba1, eta
CHARACTER(len=45) :: filename
TYPE (VODE_OPTS) :: OPTIONS
SERIAL_NUMBER=3011+II+(JJ-1)*RTOT
IND=TID+3011+II+(JJ-1)*RTOT
WRITE (*,12)SERIAL_NUMBER,TID
12 FORMAT ("SL. NO. ",I5," THREAD NO.",I3)
r=(II-1)*dr
s=s0+JJ*ds
EPS = 1.0D-9
! Open the output file:
WRITE (filename,93)r,s
93 FORMAT ("r_",f6.4,"_s_",f4.2,".txt")
OPEN (UNIT=IND,FILE=filename,STATUS='UNKNOWN',ACTION='WRITE')
! Parameters for the stiff ODE system
q0 = 0.60D0; v = 3.0D0
Va = 20.0D-4; Vs = 1.0D-1
e1 = 1.0D-1; e2 = 1.10D-5; e3 = 2.3D-3; e4=3.0D-4
del = 1.7D-4; mu = 5.9D-4
al = 1.70D-4; be = 8.9D-4; ga = 2.5D-1
! S and r dependent parameters
e1s = e1/s; e2s = e2/(s**2); e3s = e3/s; e4s = e4/s
dels = del*s; rs = r*s
e1v = e1/v; e2v = e2/(v**2); e3v = e3/v; e4v = e4/v
delv = del*v; rv = r*v
! SET INITIAL PARAMETERS for INTEGRATION ROUTINES
T = 0.0D0
TFINAL = 200.0D0
DELTAT = 0.10D0
NTOUT = INT(TFINAL/DELTAT)
RTOL = EPS
ATOL = EPS
ITASK = 1
ISTATE = 1
! Set the initial conditions: USING MODULE USEFUL_PARAMETERS_N_FUNC
CALL Y_INITIAL(NEQ,Y)
! Set the VODE_F90 options:
OPTIONS = SET_OPTS(DENSE_J=.TRUE.,USER_SUPPLIED_JACOBIAN=.FALSE., &
RELERR=RTOL,ABSERR=ATOL,MXSTEP=100000)
! Integration:
DO I=1,NTOUT
TOUT = (I-1)*DELTAT
CALL DVODE_F90(F_FUNC,NEQ,Y,T,TOUT,ITASK,ISTATE,OPTIONS)
! Stop the integration in case of an error
IF (ISTATE<0) THEN
WRITE (*,*)"ISTATE ", ISTATE
STOP
END IF
! WRITE DATA TO FILE
WRITE (IND,*) TOUT,T, Y(NEQ-2)
END DO
CLOSE(UNIT=IND)
RETURN
END SUBROUTINE STIFF_DRIVER
At line ** of file openmp_parallel_stiff.f90 (unit = 3013)
Fortran runtime error: File already opened in another unit
The issue is the format that you chose: f6.4 for r will overflow for r>=10. Then, the output will be six asterisks ****** (depending on the compiler) for all values of r>=10 on all threads. The same holds true for s.
I would suggest to either limit/check the range of these values or extend the format to honor more digits.
As #francescalus mentioned, another possibility is hit a combination of II and JJ where r and s are identical.
Just for the fun of it - let's do the math:
r=(II-1)*dr
s=s0+JJ*ds
From r=s follows
(II-1)*dr = s0+JJ*ds
or
II = 1 + s0/dr + JJ*ds/dr
Using the constants s0=0.450D0, dr=1.0D-4, ds=1.0D-2 yields
II = 4501 + JJ*10
So, whenever this combination is true for two (or more) threads at a time, you run into the observed issue.
Simple solution for this case: add the thread number to the file name.

Error in rstudio coding

I running my corpus in Rstudio, it runs first and second line coding but generating error on third row.
s<- Corpus(DirSource("C:/Users/mazhar/Documents/Sindhicorpus", pattern = "*.txt")
Word <- wordcloud(words = names(term.freq),
freq = term.freq, min.freq = 1, random.order = F, colors = brewer.pal(8, "Dark2"))
The error is
Error: unexpected ',' in "freq = term.freq,"

How do I pretty-print Rust structures in GDB?

How do I pretty-print structures (specifically Vecs) in rust-gdb or plain gdb? Whenever I call p some_vector I get this result:
collections::vec::Vec<usize> = {buf = alloc::raw_vec::RawVec<usize> = {ptr = core::ptr::Unique<usize> = {pointer = core::nonzero::NonZero<*const usize> = {
0x7ffff640d000}, _marker = core::marker::PhantomData<usize>}, cap = 16}, len = 10}
This is just unreadable. Is there any way to get a result showing the contents of the Vec? I am using Rust 1.12 and GDB 7.12.

Debugging/Stepping into a package module via cabal repl

So I have the following code from Preventing caching of computation in Criterion benchmark and my aim is to be able to step from main directly into the function defaultMain in Criterion.Main :
{-# OPTIONS -fno-full-laziness #-}
{-# OPTIONS_GHC -fno-cse #-}
{-# LANGUAGE BangPatterns #-}
module Main where
import Criterion.Main
import Data.List
num :: Int
num = 100000000
lst :: a -> [Int]
lst _ = [1,2..num]
myadd :: Int -> Int -> Int
myadd !x !y = let !result = x + y in
result
mysum = foldl' myadd 0
main :: IO ()
main = defaultMain [
bgroup "summation"
[bench "mysum" $ whnf (mysum . lst) ()]
]
and the cabal file is :
name: test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
executable test
main-is: Main.hs
build-depends: base >=4.8 && <4.9,
criterion==1.1.0.0
default-language: Haskell2010
ghc-options: "-O3"
(using ghc 7.10.1 and cabal 1.22.0.0).
If from within cabal repl I try to set a breakpoint in criterion I get the following error :
*Main> :break Criterion.Main.defaultMain
cannot set breakpoint on defaultMain: module Criterion.Main is not interpreted
Furthermore if I try to add the package I get the following error :
*Main> :add *Criterion
<no location info>: module ‘Criterion’ is a package module
Failed, modules loaded: Main.
If I do within the directory git clone https://github.com/bos/criterion
and then add the following two lines to my cabal file :
other-modules: Criterion
hs-source-dirs: .
./criterion
then upon doing cabal build I get the following errors :
criterion/Criterion/IO.hs:23:0:
error: missing binary operator before token "("
#if MIN_VERSION_binary(0, 6, 3)
so I suspect that I have to do a full on merge of the criterion cabal
file with my cabal file above, which feels a bit excessive.
Is there an easier way for me to go about setting a breakpoint
in Criterion, so that I can step (when debugging in cabal repl/ghci) directly from my source into criterion's source? Thanks
p.s. There is a related question at Debugging IO in a package module inside GHCi but unfortunately it did not help.
This is how I managed to achieve the desired goal of being able to step (within cabal repl) from my code into the criterion source :
First do :
mkdir /tmp/testCrit
cd /tmp/testCrit
Download criterion-1.1.0.0.tar.gz
Unzip into /tmp/testCrit, so we should have /tmp/testCrit/criterion-1.1.0.0. In this directory we have Criterion.hs etc.
Then jump into the folder containing the criterion source and do :
cd /tmp/testCrit/criterion-1.1.0.0
cabal sandbox init
cabal install -j
Note that this creates a directory : /tmp/testCrit/criterion-1.1.0.0/dist/dist-sandbox-782e42f0/build/autogen which we shall use later
Back in /tmp/testCrit create a Main.hs file containing the benchmark code above and also the cabal file above, but merge it with the criterion cabal file contained in /tmp/testCrit/criterion-1.1.0.0 in the following way. Note the main new additions are the lines :
cc-options: -fPIC
which allows one to run it in cabal repl, and the following
lines :
hs-source-dirs:
./
./criterion-1.1.0.0
./criterion-1.1.0.0/dist/dist-sandbox-782e42f0/build/autogen
The full cabal file should then look like :
name: test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.10
executable test
main-is: Main.hs
build-depends:
base >=4.8 && <4.9,
aeson >= 0.8,
ansi-wl-pprint >= 0.6.7.2,
base >= 4.5 && < 5,
binary >= 0.5.1.0,
bytestring >= 0.9 && < 1.0,
cassava >= 0.3.0.0,
containers,
deepseq >= 1.1.0.0,
directory,
filepath,
Glob >= 0.7.2,
hastache >= 0.6.0,
mtl >= 2,
mwc-random >= 0.8.0.3,
optparse-applicative >= 0.11,
parsec >= 3.1.0,
statistics >= 0.13.2.1,
text >= 0.11,
time,
transformers,
transformers-compat >= 0.4,
vector >= 0.7.1,
vector-algorithms >= 0.4
default-language: Haskell2010
ghc-options: "-O3"
c-sources:
./criterion-1.1.0.0/cbits/cycles.c
./criterion-1.1.0.0/cbits/time-posix.c
hs-source-dirs:
./
./criterion-1.1.0.0
./criterion-1.1.0.0/dist/dist-sandbox-782e42f0/build/autogen
cc-options: -fPIC
Then in the main directory do :
cd /tmp/testCrit/
cabal sandbox init
cabal install -j
Then we can spin up a cabal repl and step directly into
criterion from our Main.hs code :
*Main> :break Criterion.Main.defaultMain
Breakpoint 0 activated at criterion-1.1.0.0/Criterion/Main.hs:79:15-43
*Main> main
Stopped at criterion-1.1.0.0/Criterion/Main.hs:79:15-43
_result :: [Benchmark] -> IO () = _
[criterion-1.1.0.0/Criterion/Main.hs:79:15-43] *Main> :step
Stopped at criterion-1.1.0.0/Criterion/Main.hs:(131,1)-(147,39)
_result :: IO () = _
[criterion-1.1.0.0/Criterion/Main.hs:(131,1)-(147,39)] *Main> :step
Stopped at criterion-1.1.0.0/Criterion/Main.hs:(131,29)-(147,39)
_result :: IO () = _
bs :: [Benchmark] = [_]
defCfg :: Criterion.Types.Config = _
[criterion-1.1.0.0/Criterion/Main.hs:(131,29)-(147,39)] *Main> :step
Stopped at criterion-1.1.0.0/Criterion/Main.hs:132:10-37
_result :: IO Criterion.Main.Options.Mode = _
defCfg :: Criterion.Types.Config = _

Compile errors with Fortran90

All, I've been fighting these errors for hours, here's my code:
program hello
implicit none
integer :: k, n, iterator
integer, dimension(18) :: objectArray
call SetVariablesFromFile()
do iterator = 1, 18
write(*,*) objectArray(iterator)
end do
contains
subroutine SetVariablesFromFile()
IMPLICIT NONE
integer :: status, ierror, i, x
open(UNIT = 1, FILE = 'input.txt', &
ACTION = 'READ',STATUS = 'old', IOSTAT = ierror)
if(ierror /= 0) THEN
write(*, *) "Failed to open input.txt!"
stop
end if
do i = 1, 18
objectArray(i) = read(1, *, IOSTAT = status) x
if (status > 0) then
write(*,*) "Error reading input file"
exit
else if (status < 0) then
write(*,*) "EOF"
exit
end if
end do
close(1)
END subroutine SetVariablesFromFile
end program hello
I'm getting compile errors:
make: * [hello.o] Error1
Syntax error in argument list at (1)
I read online that the latter error could be due to a long line of code exceeding 132 characters, which doesn't appear to be the problem.I have no where to begin on the first error... any help would be much appreciated!
This,
objectArray(i) = read(1, *, IOSTAT = status) x
is not valid Fortran. You need to write it as,
read(1,*,iostat=status) objectArray(i)
Setting it in this correct form, I received no compiler errors with ifort 12.1, nor with gfortran 4.4.3

Resources