Rmpi program hangs after producing correct output. How do I exit programatically? - r

The code I am using is:
library(Rmpi)
mpi.spawn.Rslaves(nslaves=mpi.universe.size()-1)
mpi.remote.exec(paste(--))
mpi.close.Rslaves()
mpi.quit()
I tried mpi.exit() but still, it hangs.

Related

How to quit R script when an error occurred

I am writing an R script as a command to run in terminal, and I found if an error happen when running this script, the command still returns a normal exit signal. So I cannot check the running results by checking [ $? -ne 0 ], it just returns succeed.
This is because R will continue running the next command when it encounters an error in previous command. Is there any way to solve this situation?
Best,
Shixiang
I combine tryCatch() and quit() to solve this problem. I firstly wrap my main function to tryCatch structure to let it detect if an error occurred, once an error is detected, I print the error message and call quit("no", -1) to quit R with exit status signature -1.

Unable to run Rmpi and spawn slaves

I'm really naive and know almost nothing about MPI. I'm trying to do some analyses in R that require Rmpi package. But I'm stuck with this problem:
Version of R 3.2.5 (x64) on Windows 10
I installed MPICH2
Added proper addresses on PATH environment variables
Successfully set smpd and mpiexec registration
Installed Rmpi using Rgui
If I call Rmpi using normal Rterm it is loaded. But when I try
mpi.spawn.Rslaves(), it returns :
Error in mpi.spawn.Rslaves() : Spawning is not implemented. Please use mpiexec with Rprofile.*
so I run on prompt :
mpiexec -n 2 "C:\Program Files\R\R-3.2.5\bin\x64\Rterm.exe" --no-save –q
So far so good.
I can load any package without problems but when it comes to call Rmpi library I get this error message:
Aborting: mpi appplication on DESKTOP-0UI5TAT is unable to connect to the smpd manager on (null):57362 error 1722
job aborted:
[ranks] message
[0] fatal error
Fatal error in MPI_Init: Other MPI error, error stack:
MPI_Init(argc_p=0x0018FA44, argv_p=0x0018FA48) failed
The RPC server is unavailable. (errno 1722)*
Even using the more recent MS-MPI software, when I call Rmpi it simply starts a new line without any prompt > and so it remains
I deep searched on the whole internet and tried several options but it's still not working
you have to create a shortcut that Rstudio is lunched by mpiexec ,otherwise the Rstudio doesn't know Mpi
follow instruction here
http://www.stats.uwo.ca/faculty/yu/Rmpi/

Can R interpret a SIGINT/SIGTERM and execute a process as a result?

Is there anyway to capture a SIGINT or SIGTERM from the shell in R so that I can try to execute some graceful exit code?
So far, I haven't found anything in my search.

RStudio cannot find any package after laptop restart

My R script worked fine in RStudio (Version 0.98.1091) on Windows 7. Then I restarted my laptop, entered again in RStudio and now it provides the following error messages each time I want to execute my code:
cl <- makeCluster(mc); # build the cluster
Error: could not find function "makeCluster"
> registerDoParallel(cl)
Error: could not find function "registerDoParallel"
> fileIdndexes <- gsub("\\.[^.]*","",basename(SF))
Error in basename(SF) : object 'SF' not found
These error messages are slightly different each time I run the code. It seems that RStudio cannot find any function that is used in the code.
I restarted R Session, cleaned Workspace, restarted RStudio. Nothing helps.
It must be noticed that after many attempts to execute the code, it finally was initialized. However, after 100 iterations, it crashed with the message related to unavailability of localhost.
Add library(*the package needed/where the function is*) for each of the packages you're using.

How to stop entire script from running when certain condition met without error in R

i=14
l=8
if(i>l){q()}
print(i)
print(l)
above code is what I simplfied and when I run code above, it ends up with " R session aborted. R encountered a fatal error"
pls advise me way to avoid this error
Calling q() inside an if block from a script in the editor pane of RStudio crashes my RStudio in a similar manner, with a fatal error dialog box. I suspect this is an RStudio bug and should be reported if it recurs with the latest RStudio.
Just putting q() in a script not in an if block quits RStudio as expected, without error messages.
The correct way to terminate a script without killing R in any way is to use stop("why").
if(1>0)stop("am stopping")
print("No")

Resources