|
RInside Version 0.2.10
|
00001 // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8; -*- 00002 // 00003 // Simple example showing in R console information about current node 00004 // 00005 // This file was contributed by Jianping Hua 00006 // 00007 // Copyright (C) 2010 - 2011 Jianping Hua, Dirk Eddelbuettel and Romain Francois 00008 // 00009 // GPL'ed 00010 00011 #include <mpi.h> // mpi header 00012 #include <RInside.h> // for the embedded R via RInside 00013 00014 int main(int argc, char *argv[]) { 00015 00016 // mpi related 00017 int myrank, nodesize; // node information 00018 MPI_Init(&argc,&argv); // mpi initialization 00019 MPI_Comm_rank(MPI_COMM_WORLD, &myrank); // obtain current node rank 00020 MPI_Comm_size(MPI_COMM_WORLD, &nodesize); // obtain total nodes running. 00021 00022 RInside R(argc, argv); // create an embedded R instance 00023 00024 std::stringstream txt; 00025 txt << "Hello from node " << myrank // node information 00026 << " of " << nodesize << " nodes!" << std::endl; 00027 00028 R["txt"] = txt.str(); // assign string var to R variable 'txt' 00029 00030 R.parseEvalQ("cat(txt)"); // eval init string, ignoring any returns 00031 00032 MPI_Finalize(); // mpi finalization 00033 00034 exit(0); 00035 }