Dear Martin,

Many thanks. This is very useful, much appreciated.

Regards,
Tolga




Martin Morgan <[EMAIL PROTECTED]> 
08/09/2008 19:08

To
[EMAIL PROTECTED]
cc
r-help@r-project.org
Subject
Re: [R] RMPI Question






Hi Tolga --

[EMAIL PROTECTED] writes:

> Dear R Users,
>
> I have a relatively simple rmpi question. 
>
> My configation is:
> - R version 2.7.2
> - rmpi 0.5-6
> - Deino MPI 1.1.0
> - Windows XP SP2
>
> After succesfully spawning slaves, I am trying to assign values to 
> variables in the environment of each slave and run some simple calcs. 
This 
> appears to fail, as below: my assignment of value "1" to variable "a" 
> appears to come back OK, but then when I try and retrieve it, it fails. 
>
> Could someone please point out what I might be doing wrong ? 
>
> I spawn 8 slaves below, but have deleted the output from slaves 3-7 just 

> to save space and make the output easier to read.
>
>> mpi.spawn.Rslaves() 
>         8 slaves are spawned successfully. 0 failed.
> master (rank 0, comm 1) of size 9 is running on: Personal 
> slave1 (rank 1, comm 1) of size 9 is running on: Personal 
> slave2 (rank 2, comm 1) of size 9 is running on: Personal 
> ...
> slave8 (rank 8, comm 1) of size 9 is running on: Personal 
>> mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size())) 
> $slave1
> [1] "I am 1 of 9"
>
> $slave2
> [1] "I am 2 of 9"
> ...
> $slave8
> [1] "I am 8 of 9"
>
>> mpi.remote.exec(eval(assign("a","1")))
> $slave1
> [1] "1"
>
> $slave2
> [1] "1"
> ...
> $slave8
> [1] "1"
>

mpi.remote.exec can be thought of as evaluating each command in a new
environment. so once mpi.remote.exec returns, the environment (and any
side effects like assignment) disappear.

You could:

> mpi.remote.exec(a <<- 2)
  X1 X2
1  2  2
> mpi.remote.exec(a)
  X1 X2
1  2  2

the <<- forces assignment to the first 'a' found in the scope of the
invoking function, or in .GlobalEnv if no variable 'a' currently
exists. mpi.remote.exec(a) looks for a variable named a, first in the
environment where the remote request is being evaluated, and
eventually in the global environment. The <<- is dangerous because you
could accidentally clobber other variables named 'a' that exist before
the global environment is found. I think mpi.remote.exec is meant to
be used to evaluate a command that has no side effects (like variable
assignmnet).

On the other hand,

> mpi.bcast.cmd(a <- 1)
> mpi.remote.exec(a)
  X1 X2
1  1  1

Here mpi.bcast.cmd is arranging to evaluate the expression in the
global environment, and so this is more like interacting at the
command prompt. mpi.remote.exec 'works' because R does not find the
variable 'a' until it reaches the global environment. A more reliable
solution would be

> mpi.remote.exec(get("a", .GlobalEnv))
  X1 X2
1  1  1

Martin


>> mpi.remote.exec(eval(assign("b","2")))
> $slave1
> [1] "2"
>
> $slave2
> [1] "2"
> ...
> $slave8
> [1] "2"
>
>> mpi.remote.exec(a)
> $slave1
> [1] "Error in eval(expr, envir, enclos) : object \"a\" not found\n"
> attr(,"class")
> [1] "try-error"
>
> $slave2
> [1] "Error in eval(expr, envir, enclos) : object \"a\" not found\n"
> attr(,"class")
> [1] "try-error"
> ...
> $slave8
> [1] "Error in eval(expr, envir, enclos) : object \"a\" not found\n"
> attr(,"class")
> [1] "try-error"
>
>
> Thanks in advance,
> Tolga
>
> Generally, this communication is for informational purposes only
> and it is not intended as an offer or solicitation for the purchase
> or sale of any financial instrument or as an official confirmation
> of any transaction. In the event you are receiving the offering
> materials attached below related to your interest in hedge funds or
> private equity, this communication may be intended as an offer or
> solicitation for the purchase or sale of such fund(s).  All market
> prices, data and other information are not warranted as to
> completeness or accuracy and are subject to change without notice.
> Any comments or statements made herein do not necessarily reflect
> those of JPMorgan Chase & Co., its subsidiaries and affiliates.
>
> This transmission may contain information that is privileged,
> confidential, legally privileged, and/or exempt from disclosure
> under applicable law. If you are not the intended recipient, you
> are hereby notified that any disclosure, copying, distribution, or
> use of the information contained herein (including any reliance
> thereon) is STRICTLY PROHIBITED. Although this transmission and any
> attachments are believed to be free of any virus or other defect
> that might affect any computer system into which it is received and
> opened, it is the responsibility of the recipient to ensure that it
> is virus free and no responsibility is accepted by JPMorgan Chase &
> Co., its subsidiaries and affiliates, as applicable, for any loss
> or damage arising in any way from its use. If you received this
> transmission in error, please immediately contact the sender and
> destroy the material in its entirety, whether in electronic or hard
> copy format. Thank you.
> Please refer to http://www.jpmorgan.com/pages/disclosures for
> disclosures relating to UK legal entities.
>                [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M2 B169
Phone: (206) 667-2793



Generally, this communication is for informational purposes only
and it is not intended as an offer or solicitation for the purchase
or sale of any financial instrument or as an official confirmation
of any transaction. In the event you are receiving the offering
materials attached below related to your interest in hedge funds or
private equity, this communication may be intended as an offer or
solicitation for the purchase or sale of such fund(s).  All market
prices, data and other information are not warranted as to
completeness or accuracy and are subject to change without notice.
Any comments or statements made herein do not necessarily reflect
those of JPMorgan Chase & Co., its subsidiaries and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.
Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to UK legal entities.
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to