On a virtual machine under some conditions, the detectCores() function in TERR's "parallel" package can incorrectly return a value of 1 when there are actually more cores available.

On a virtual machine under some conditions, the detectCores() function in TERR's "parallel" package can incorrectly return a value of 1 when there are actually more cores available.

book

Article ID: KB0078700

calendar_today

Updated On:

Products Versions
Spotfire Enterprise Runtime for R All supported versions

Description

Under some circumstances on a virtual machine, the parallel::detectCores() function in TIBCO Enterprise Runtime for R (TERR) can incorrectly return a value of 1 when there are actually more cores available.
 

Issue/Introduction

On a virtual machine under some conditions, the detectCores() function in TERR's "parallel" package can incorrectly return a value of 1 when there are actually more cores available.

Environment

All supported environments

Resolution

The example code shown here illustrates one way to work around this issue.

(1) The following command captures the result from the call to TERR's detectCores() function:

  NumberOfCores <- parallel::detectCores()

(2) The following code tests for the problem, then corrects the problem by using the REvaluate() function from TERR's built-in "RinR" package to send the parallel::detectCores() call out for processing by an open-source R instance (which you have downloaded from the open-source R community's CRAN repository and installed on the same server):

#-----
if(NumberOfCores == 1)
{
  NumberOfCores <- 
    RinR::REvaluate(
      expr = 
      {
        if( ! "parallel" %in% rownames(installed.packages()) ) 
        {
          install.packages("parallel")  
        }
        NumberOfCores <- parallel::detectCores()
      }
    )
}
#-----



(3) The following shows an example of its use, in which the value of the 'NumberOfCores' test object has been deliberately set to 1:


=====
TIBCO Software Inc. Confidential Information
Copyright (C) 2011-2018 TIBCO Software Inc. ALL RIGHTS RESERVED
TIBCO Enterprise Runtime for R version 4.5.0 for Microsoft Windows 64-bit

Type 'help()' for help.
Type 'q()' to quit.
>
>
>
> ActualPathToOpenSourceR <- "C:/Program Files/R/R-3.4.4/bin/R.exe"
>
> options(RinR_R_FULL_PATH = ActualPathToOpenSourceR)
>
> getOption("RinR_R_FULL_PATH")
[1] "C:/Program Files/R/R-3.4.4/bin/R.exe"
>
>
> file.exists( getOption("RinR_R_FULL_PATH") )
[1] TRUE
>
>
> NumberOfCores <- 1
>
> NumberOfCores
[1] 1
>
>
> #-----
> if(NumberOfCores == 1)
  {
    NumberOfCores <-
      RinR::REvaluate(
        expr =
        {
          if( ! "parallel" %in% rownames(installed.packages()) )
          {
            install.packages("parallel")
          }
          NumberOfCores <- parallel::detectCores()
        }
      )
  }
> #-----
>
>
> NumberOfCores
[1] 8
>
>
=====


Disclaimer:
The code in this article is only a sample to be used as a reference. It is not intended to be used "As Is" in a Production environment. Always test in a Development environment. Make modifications to the code in accordance with your implementation specifications that best suit your business requirements. Refer to the reference(s) cited in this article for usage of the functions and methods used in the code.


Important note on use of CRAN packages:

User-contributed R packages from the open-source R community's CRAN repository (https://cran.r-project.org/) are available under separate open source software license terms and are not part of the TIBCO Spotfire product line. As such, user-contributed CRAN packages are not within the scope of your license for any TIBCO Spotfire product. User-contributed CRAN packages are not supported, maintained, or warranted in any way by TIBCO Software Inc. Download and use of CRAN packages is solely at your own discretion and subject to the free open source license terms applicable to each individual package.

 

Additional Information

The following public knowledge base article may be helpful when setting up the environment for use of the REvaluate() function:

  https://support.tibco.com/s/article/How-to-use-the-data-and-expr-arguments-in-the-REvaluate-function-from-TERR-s-RinR-package-to-send-data-and-expressions-out-to-an-open-source-R-session