On Jun 10, 2008, at 2:10 PM, Andreas Unger wrote:
> (define defaultport (current-output-port))
> (define port1 (open-output-file "filename.txt"))
> (set-current-output-port port1)
>
> (display-fluxes fluxInside ScatOutside AbsInside)
>
> (set-current-output-port defaultport)
> (close-output-port port1)
>
> This procedure opens a file, set the output port to this file and
> prints
> the fluxes with display-fluxes. Then it sets the output port back to
> default and closes the file. It works also well with meep-mpi. It
> can be
> used also to print other stuff to a file.
Andreas, that code has something of a race condition with MPI, because
it calls (open-output-file ...) on every process.
You can use the variable print-ok?, which is true only on the "master"
process, to decide whether to create a file. (Or you can use (= (meep-
am-master) 1), which amounts to the same thing.)
The only catch is that you need to call display-fluxes from all the
processes (although it will only print from the master process),
because hidden inside display-fluxes is a collective operation (it has
to sum the flux over all processes). So, you would do something like
this:
(define defaultport (current-output-port)
(define port1 (if print-ok? (open-output-file "filename.txt") false)
(if port1 (set-current-output-port port1)
(display-fluxes fluxInside ScatOutside AbsInside)
(set-current-output-port defaultport)
(if port1 (close-output-port port1))
However, I would never do any of this myself. What I always do is to
just pipe *all* of the output to a file, and then grep for what I want
afterwards. i.e.
meep foo.ctl > foo.out
grep flux1: foo.out > flux.out
The same thing works with MPI, too. This way, you can decide
afterwards what data you want to plot, etcetera. This is the whole
point of the way Meep's text output works (it's why the flux output
lines are all prefixed with "flux1:" etc.)
Regards,
Steven G. Johnson
_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss