My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
HowDoesRFortranWork  
Explains how RFortran Works
Updated Jun 3, 2009 by mleon...@civeng.adelaide.edu.au

How the RDCOM Module was created

The module 'rdcom' in the file RFortran_COMInterface_IVF.f90 was created by pointing the 'Fortran Module Wizard' in Compaq to the file StatConnectorSrv.exe which was located in the installation directory of the rdcom server found here. The code generated respectively by the Intel and Compaq wizards is slightly different and as a result a tweak has been made to the IStatConnector_SetSymbol function so that it avoids a serious complication when using the Intel compiler. The reason for this module is to make sure that Fortran correctly passes information to the COM server - i.e. the module is a 'wrapper'. It is the lowest level module in the Fortran code. Many additional routines created by the Module Wizard were removed as they are not used.

RDCOM and RCOM

There are two separate implementations in RFortran, one is referred to as RCOM and the other RDCOM, confusing, but it is not our terminology.

  1. com is a package inside R so that RFortran will open the program Rgui.exe and the R command prompt will be visible and can be querieid. This has been set as the detault mechanism for RFortran since most users will use the command prompt to debug or inspect output.
  2. nother implementation is RDCOM, but access to this feature has been activated in the current implementation. When the RDCOM server is invoked, it runs StatConnectorSrv.exe, which is a full implementation of R that is hidden in the background. In other words, there is no gui or no mechanism for interacting with the program from the R environment. As this feature does not allow debugged from within R it has not been activated. It might be useful for deploying mature code where the developers do not wish the user to see the R prompt.

Rput and Rget

Another module, called RFortran_Rput_Rget, has been written on top of the rdcom wrapper module. The purpose of the RFortran_base module is to provide convenience for accessing R so the the user only needs to use the functions Rput(), Rget() and does not have to bother with details on how to pass different types of data. This module overloads the Rput and Rget functions so that a large variety of data types and shapes can be passed into R. There is a fair degree of complication in passing data into R, because it uses objects called 'variants' to pass any type of data. This is useful as it allows one interface to handle any type of data, but it means that the user has to package the data into the variant before passing it and then unpack it after retrieving data from R ... which is precisely what this module does. Support for Complex(4) complex(8) data types and array sizes above 3D is planned for the future. Please contact us if you require these features.

Overhead penalties

Because data must be packed into variant objects, there are overhead penalties, a speed penalty and a memory penalty. The memory penalty of an Rput routine causes 2 additional copies of the array:

  1. he first copy is made to pack the data into a the variant object (inside a safearray). This procedure cannot be done by reference.
  2. creates a copy of this array and stores it within its environment. This second copy of the data is out of our hands. When R has finished, the Rput routine destroys its copy and returns control to the main program.
As a result, one array resides in the main Fortran program (the original) and a copy resides in R. It is important to point out the presence of the additional copy since for a short period of time 3 versions of the array will exist in memory which for large arrays may push a program to use virtual memory.

Bstrings and Safearrays

There is a complication in that Fortran strings and arrays are not conformable to the COM standard for strings and arrays, so functions have to be used to convert strings into Bstrings and arrays into safearrays before they are then packed into the variant object and passed over to R. The functions for Bstrings and safearrays (as well as variants) are located in the built-in modules dfcom/dfwinty (Compaq) ifcom/ifwinty (Intel) ... which is the reason why RFortran is restricted to these compilers. If you would like to know more about these features, then there is an excellent library of information on the web provided by a company called Canaima.

Global Variables

The R object and the variant data type used for passing are made global in the RFortran_base module, this means that only one copy of the R server can be used at any one time. If you have a need for multiple copies of R servers, please indicate this to us and we will address it.


Sign in to add a comment
Powered by Google Project Hosting