How to output data from different procedures on single line

Anything that doesn't fit elsewhere.
Post Reply
JohnAnderson
Posts: 8
Joined: Sun Jun 12, 2005 10:41 am
Location: University of North Florida

How to output data from different procedures on single line

Post by JohnAnderson » Thu Oct 06, 2011 10:54 am

I am running a simulation repeatedly with different input each time. In each run, different procedures in the hoc file generate nearly 100 data items, some of which are strings and some of which are numbers. The program writes the items both to the standard output and to an output file as they are generated, but I'd also like to have each run append all of them in a single record to a CSV file for later analysis of the entire collection of runs. I have considered using sprint to convert those items that aren't strings into strings, and then using sprint again at the end of the run to put them all together into a megastring that could then be appended to the CSV file (opened with aopen), but that seems awfully clunky. Is there a more elegant way to do this?

ted
Site Admin
Posts: 5567
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: How to output data from different procedures on single l

Post by ted » Thu Oct 06, 2011 11:24 pm

Forget about building a big string. Just defer printing of \n until after "the last variable on the line" has been printed. Or, simpler yet, omit \n from the format strings of all existing procs that print to the output file, and after the last one has been called, terminate the line by executing a single File.printf("\n") statement.

Truth be told, however, it is not terribly efficient to run
a simulation repeatedly with different input each time. In each run, different procedures in the hoc file generate nearly 100 data items, some of which are strings and some of which are numbers. The program writes the items both to the standard output and to an output file as they are generated
because the overall task appears to be "embarrasingly parallel." With bulletin-board-style parallelization, you should be able to achieve significant speedup on a multicore Mac or PC, a workstation cluster, or a parallel supercomputer--see
ParallelContext
http://www.neuron.yale.edu/neuron/stati ... arcon.html
You'd want the master to be the processor that writes results to output, to avoid race conditions.

Post Reply