[Rcpp-commits] r2473 - in pkg/RcppParDE: scripts src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Nov 20 19:14:36 CET 2010


Author: edd
Date: 2010-11-20 19:14:35 +0100 (Sat, 20 Nov 2010)
New Revision: 2473

Removed:
   pkg/RcppParDE/src/evaluate.cpp
Modified:
   pkg/RcppParDE/scripts/openmp.r
   pkg/RcppParDE/src/Makevars
   pkg/RcppParDE/src/devol.cpp
   pkg/RcppParDE/src/permute.cpp
Log:
committing current (not entirely working) state of things
evaluate.cpp replaced by class in evaluate.h


Modified: pkg/RcppParDE/scripts/openmp.r
===================================================================
--- pkg/RcppParDE/scripts/openmp.r	2010-11-20 18:10:55 UTC (rev 2472)
+++ pkg/RcppParDE/scripts/openmp.r	2010-11-20 18:14:35 UTC (rev 2473)
@@ -66,12 +66,14 @@
                  '
 
 create_xptr <- cxxfunction(signature(funname="character"), body=src.xptr, inc=inc, plugin="Rcpp")
-xptr <- create_xptr("rastrigin")
-func <- Rastrigin
+#xptr <- create_xptr("genrose")
+#func <- Genrose
+xptr <- create_xptr("wild")
+func <- Wild
 #maxIt <- 500                           # not excessive but so that we get some run-time on simple problems
 #n <- 40
 maxIt <- 1000
-n <- 20
+n <- 40
 
 set.seed(42)
 print(system.time( {

Modified: pkg/RcppParDE/src/Makevars
===================================================================
--- pkg/RcppParDE/src/Makevars	2010-11-20 18:10:55 UTC (rev 2472)
+++ pkg/RcppParDE/src/Makevars	2010-11-20 18:14:35 UTC (rev 2473)
@@ -1,8 +1,11 @@
 ## Hey Emacs make this a -*- mode: makefile; -*- file 
 ##
-## -- for OpenMP (with -D macro to switch to OpenMP enabled source file)
-PKG_CXXFLAGS=-fopenmp -DUSE_OPENMP
+## -- compiling for OpenMP 
+PKG_CXXFLAGS=-fopenmp
+##
+## -- linking for OpenMP
 PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
 ##
-## -- for Google Perftools profiling
-PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lprofiler
+## -- linking for OpenMP and Google Perftools profiling
+#PKG_LIBS= -fopenmp -lgomp $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()") $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -lprofiler
+

Modified: pkg/RcppParDE/src/devol.cpp
===================================================================
--- pkg/RcppParDE/src/devol.cpp	2010-11-20 18:10:55 UTC (rev 2472)
+++ pkg/RcppParDE/src/devol.cpp	2010-11-20 18:14:35 UTC (rev 2473)
@@ -7,27 +7,21 @@
 // and based on DE-Engine v4.0, Rainer Storn, 2004  
 // (http://www.icsi.berkeley.edu/~storn/DeWin.zip)
 
-#ifdef USE_OPENMP
 #include <RcppArmadillo.h>	// declarations for both Rcpp and RcppArmadillo offering Armadillo classes
 #include <omp.h>		// OpenMP for compiler-generated multithreading
 #include "evaluate.h"		// simple function evaluation framework
+#include <google/profiler.h>
 
 void permute(int ia_urn2[], int i_urn2_depth, int i_NP, int i_avoid, int ia_urntmp[]);
 
-inline double drndu(void) {
-#ifdef USE_OPENMP
+inline double drndu(void) {	// simple wrapper around double uniform_random() to make it indepedent of R
     return arma::randu();
-#else
-    return ::unif_rand();
-#endif
+    // return ::unif_rand();
 }
 
-inline int irndu(const double val) {
-#ifdef USE_OPENMP
+inline int irndu(const double val) {	// simple wrapper around int uniform_random() to make it indepedent of R
     return static_cast<int>(arma::randu() * val);
-#else
-    return static_cast<int>(::unif_rand() * val);
-#endif
+    // return static_cast<int>(::unif_rand() * val);
 }
 
 void devol(double VTR, double f_weight, double f_cross, int i_bs_flag,
@@ -40,7 +34,7 @@
            arma::mat &d_pop, Rcpp::List &d_storepop, arma::mat & d_bestmemit, arma::colvec & d_bestvalit,
            int & i_iterations, double i_pPct, long & l_nfeval) {
 
-    //ProfilerStart("/tmp/RcppDE.prof");
+    ProfilerStart("/tmp/RcppParDE.prof");
     Rcpp::DE::EvalBase *ev = NULL; 		// pointer to abstract base class
     if (TYPEOF(fcall) == EXTPTRSXP) { 		// non-standard mode: we are being passed an external pointer
 	ev = new Rcpp::DE::EvalCompiled(fcall); // so assign a pointer using external pointer in fcall SEXP
@@ -112,6 +106,7 @@
 	    rsort_with_index( temp_oldC.memptr(), sortIndex.begin(), i_NP );  	// to use sortIndex later 
 	}
 
+	omp_set_num_threads(1); //FIXME!!
 #pragma omp parallel for shared(ia_urn2,ta_oldP,ta_newP,ta_newC,t_tmpP,ia_urntmp) schedule(static,1)
 	for (int i = 0; i < i_NP; i++) {	// ----start of loop through ensemble------------------------
 
@@ -293,6 +288,5 @@
     i_iterations = i_iter;    
     l_nfeval = ev->getNbEvals();
     //PutRNGstate();   
-    // ProfilerStop();
+    ProfilerStop();
 }
-#endif

Deleted: pkg/RcppParDE/src/evaluate.cpp
===================================================================
--- pkg/RcppParDE/src/evaluate.cpp	2010-11-20 18:10:55 UTC (rev 2472)
+++ pkg/RcppParDE/src/evaluate.cpp	2010-11-20 18:14:35 UTC (rev 2473)
@@ -1,25 +0,0 @@
-// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
-//
-// Port of DEoptim (2.0.7) by Ardia et al to Rcpp/RcppArmadillo/Armadillo
-// Copyright (C) 2010  Dirk Eddelbuettel <edd at debian.org>
-//
-// DEoptim is Copyright (C) 2009 David Ardia and Katharine Mullen
-#if 0
-#ifdef USE_OPENMP
-#include <RcppArmadillo.h>
-
-// Slighly accelerated version of evaluate to evaluate function fcall with parameters param in environment env
-// Uses externally allocated par() vector into which param are copied
-double evaluate(long &l_nfeval, const double *param, SEXP par, SEXP fcall, SEXP env) {
-    memcpy(REAL(par), param, Rf_nrows(par) * sizeof(double));      // -- faster: direct access _assuming_ numeric vector
-    Rcpp::NumericVector x(par);
-    int n = x.size();
-    double sum = 1.0;
-    for (int i=1; i<n; i++) {
-	sum += 100*( pow(x[i-1]*x[i-1] - x[i], 2)) + (x[i] - 1)*(x[i] - 1);
-    }
-    l_nfeval++;  						   // increment function evaluation count 
-    return(sum);
-}
-#endif
-#endif

Modified: pkg/RcppParDE/src/permute.cpp
===================================================================
--- pkg/RcppParDE/src/permute.cpp	2010-11-20 18:10:55 UTC (rev 2472)
+++ pkg/RcppParDE/src/permute.cpp	2010-11-20 18:14:35 UTC (rev 2473)
@@ -7,7 +7,6 @@
 // and based on DE-Engine v4.0, Rainer Storn, 2004  
 // (http://www.icsi.berkeley.edu/~storn/DeWin.zip)
 
-#ifdef USE_OPENMP
 #include <RcppArmadillo.h>	// declarations for both Rcpp and RcppArmadillo offering Armadillo classes
 #include <omp.h>		// OpenMP for compiler-generated multithreading
 
@@ -47,4 +46,3 @@
     }
     //PutRNGstate();
 }
-#endif



More information about the Rcpp-commits mailing list