Tim,
 
Thanks for your reply.
 
One clarification please.
 
I am using R 2.10.0 on Windows XP, Intel(R) Core(TM) 2 Duo CPU E8400 @3.00GHz 2.99GHz, 1.96 of RAM.
I have checked that Windows binary of doMC is not available. Any advice.
 
Once again, thank you very much for the time you have given.

Regards,

Deb

>>> Tim Triche <tim.triche@gmail.com> 10/12/2009 3:54 am >>>
library(foreach)
library(doMC) # or doWhatever, take your pick
registerDoMC(4)

results <- foreach( j=1:itermax ) %dopar% {

# stuff
if( converged ) break

}

The details are up to you. I don't remember how best to break out of a foreach loop, try help('foreach').
Have fun. It's pretty straightforward once you get used to foreach() behavior, less so up to that point. 
But it's a really useful tool to have in your arsenal for the problem you describe. Try to loop over the biggest chunks of processing you can get away with, as fork()ing processes has some consequences.



On Tue, Dec 8, 2009 at 8:02 PM, Debabrata Midya <Debabrata.Midya@services.nsw.gov.au> wrote:



Dear hpc users,

Thanks in advance.

I am using R 2.10.0 on Windows XP, Intel(R) Core(TM) 2 Duo CPU E8400 @3.00GHz 2.99GHz, 1.96 of RAM.

I like to have a parallel version of the code below. This is an example code only.

A: cursol contains values of x[1], x[2], x[3] and minimum value from func using x's.

###########
# Code starts
###########

func <- function(x)
{
10 * x[1] - 11 * x[2] + 12 * x[3]
}

main <- function(xl, xu)
{
checkval <- function(x, xl, xu)
{
i <- 1
while (i <= 3)
{
if (x[i] < xl[i]) x[i] <- xl[i]
if (x[i] > xu[i]) x[i] <- xu[i]
i <- i + 1
}
x
}

itermax <- 50

j <- 1
while (j <= itermax)
{
# trainX is a matrix of 3 x 3
trainX <- matrix(rep(xl, 3), 3, 3, byrow=TRUE) + matrix(runif(9, 0, 1), 3, 3)
trainX
trainX <- t(apply(trainX, 1, checkval, xl, xu))
trainX
sold <- apply(trainX, 1, func)
osold <- cbind(1:3, sold)
osold <- osold[order(osold[, 2]), ]
osold

if (j > 1)
{
if (osold[1, 2] < cursol[1, 4])
{
cursol <- matrix(c(trainX[osold[1,1], ], osold[1,2]), 1, 4)
}
else
{
cursol <- cursol
}
}

if (j <= 1)
{
cursol <- matrix(c(trainX[osold[1,1], ], osold[1,2]), 1, 4)
}

cursol
j <- j + 1
}

cursol
}

xl <- c(1, 2, 3)
xu <- c(2, 3, 4)

cursol <- main(xl, xu)
cursol


###########
# Code ends
###########

Once again, thank you very much for the time you have given.

I am looking forward for your reply.

Regards,

Deb


[[alternative HTML version deleted]]

_______________________________________________
R-sig-hpc mailing list
R-sig-hpc@r-project.org 
https://stat.ethz.ch/mailman/listinfo/r-sig-hpc 




-- 
Absolute certainty is the privilege of mathematicians and madmen. 
It is, for scientists, an unobtainable ideal. 
--Cassius J. Keyser

	[[alternative HTML version deleted]]

