--- trunk/src/minimizers/PRCG.cpp 2005/02/13 19:10:25 324 +++ trunk/src/minimizers/PRCG.cpp 2006/05/17 21:51:42 963 @@ -1,4 +1,4 @@ - /* +/* * Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a @@ -42,64 +42,64 @@ namespace oopse { #include "minimizers/PRCG.hpp" namespace oopse { -void PRCGMinimizer::init(){ + void PRCGMinimizer::init(){ - calcG(); + calcG(); - for(int i = 0; i < direction.size(); i++){ - direction[i] = -curG[i]; + for(int i = 0; i < direction.size(); i++){ + direction[i] = -curG[i]; + } + } -} - -int PRCGMinimizer::step(){ - int lsStatus; + int PRCGMinimizer::step(){ + int lsStatus; - prevF = curF; - prevG = curG; - prevX = curX; + prevF = curF; + prevG = curG; + prevX = curX; - //optimize along the search direction and reset minimum point value + //optimize along the search direction and reset minimum point value lsStatus = doLineSearch(direction, stepSize); - if (lsStatus < 0) - return -1; - else - return 1; -} + if (lsStatus < 0) + return -1; + else + return 1; + } -void PRCGMinimizer::prepareStep(){ - std::vector deltaGrad; - double beta; - size_t i; + void PRCGMinimizer::prepareStep(){ + std::vector deltaGrad; + RealType beta; + size_t i; - deltaGrad.resize(ndim); + deltaGrad.resize(ndim); - //calculate the new direction using Polak-Ribiere Conjugate Gradient + //calculate the new direction using Polak-Ribiere Conjugate Gradient - for(i = 0; i < curG.size(); i++) - deltaGrad[i] = curG[i] - prevG[i]; + for(i = 0; i < curG.size(); i++) + deltaGrad[i] = curG[i] - prevG[i]; #ifndef IS_MPI - beta = dotProduct(deltaGrad, curG) / dotProduct(prevG, prevG); + beta = dotProduct(deltaGrad, curG) / dotProduct(prevG, prevG); #else - double localDP1; - double localDP2; - double globalDP1; - double globalDP2; + RealType localDP1; + RealType localDP2; + RealType globalDP1; + RealType globalDP2; - localDP1 = dotProduct(deltaGrad, curG); - localDP2 = dotProduct(prevG, prevG); + localDP1 = dotProduct(deltaGrad, curG); + localDP2 = dotProduct(prevG, prevG); - MPI_Allreduce(&localDP1, &globalDP1, 1, MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); - MPI_Allreduce(&localDP2, &globalDP2, 1, MPI_DOUBLE,MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&localDP1, &globalDP1, 1, MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(&localDP2, &globalDP2, 1, MPI_REALTYPE,MPI_SUM, MPI_COMM_WORLD); - beta = globalDP1 / globalDP2; + beta = globalDP1 / globalDP2; #endif - for(i = 0; i < direction.size(); i++) - direction[i] = -curG[i] + beta * direction[i]; + for(i = 0; i < direction.size(); i++) + direction[i] = -curG[i] + beta * direction[i]; -} + } }