[Swift-user] Dynamic For Loops from Input File

Matthew Shaxted Matthew.Shaxted at som.com
Wed Aug 20 17:51:09 CDT 2014


Hi Mihael,

This looks like it may work well - many thanks for the quick response.

I'll see if I can integrate this into my existing sweep scripts now.

Thanks again,
Matthew


MATTHEW SHAXTED
SKIDMORE, OWINGS & MERRILL LLP
224 SOUTH MICHIGAN AVENUE
CHICAGO, IL 60604
T  (312) 360-4368
MATTHEW.SHAXTED at SOM.COM


The information contained in this communication may be confidential, is intended only for the use of the recipient(s) named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication, or any of its contents, is strictly prohibited and may be unlawful. If you have received this communication in error, please return it to the sender immediately and delete the original message and any copy of it from your computer system. If you have any questions concerning this message, please contact the sender.



-----Original Message-----
From: Mihael Hategan [mailto:hategan at mcs.anl.gov] 
Sent: Wednesday, August 20, 2014 5:41 PM
To: Matthew Shaxted
Cc: swift-user at ci.uchicago.edu; Jason Kirkpatrick
Subject: Re: [Swift-user] Dynamic For Loops from Input File

Hi Matthew,

I'm thinking something like this:

type var {
  string name;
  float[] values;
}

(float[] r) extend(float[] a, float v, int lastIndex) {
  foreach ov, i in a {
    r[i] = a[i];
  }
  r[lastIndex] = v;
}

doSomething(float[] a) {
  trace(a);
}

dynamicFor(var[] vars, float[] values, int index, int len) {
  if (index < len) {
    tracef("Iterating over %s\n", vars[index].name);
    foreach v in vars[index].values {
      dynamicFor(vars, extend(values, v, index), index + 1, len);
    }
  }
  else {
    doSomething(values);
  }
}

var[] vars;
vars[0].name = "a";
vars[0].values = [0.1, 0.2, 0.3];
vars[1].name = "b";
vars[1].values = [0.4, 0.5];

float[] empty;

dynamicFor(vars, empty, 0, 2);

Mihael


On Wed, 2014-08-20 at 17:59 -0400, Matthew Shaxted wrote:
> Hi Swift Users,
> 
> I have a swift script that reads an input file of parameters and variables, and iterates through the variables in one for loop per parameter:
> 
> Input Sweep File Example:
> pnum    pname                                  pvals
> 1              InfilRate                               0.0015,0.025
> 2              PreheatCoilSetpoint       15,15.5,16.0
> 3              KitchenGasPD                   200,250
> 
> Swift File For Loops:
> foreach v0 in pval[0] {
> foreach v1 in pval[1] {
> foreach v2 in pval[2] {
> 
> As of now, I need to hard code in the number of for loops in the Swift script to match those of the input file parameters, and I'm thinking there must be a better way.
> 
> I'm wondering if there is a more dynamic way to have Swift loop through the parameters without having to hard code in the for loops? For example, if I define 5 parameters in the input file, the Swift script would automatically know to add 5 for loops.
> 
> I was thinking I could create a shell script to read the input file and dynamically create the swift script with the correct number of for loops before running swift, but perhaps there is a better way?
> 
> Thanks,
> Matthew
> 
> 
> MATTHEW SHAXTED
> SKIDMORE, OWINGS & MERRILL LLP
> 224 SOUTH MICHIGAN AVENUE
> CHICAGO, IL 60604
> T  (312) 360-4368
> MATTHEW.SHAXTED at SOM.COM<mailto:MATTHEW.SHAXTED at SOM.COM>
> 
> [cid:image004.png at 01CFBC98.297A1030]<http://www.som.com/>
> The information contained in this communication may be confidential, is intended only for the use of the recipient(s) named above, and may be legally privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution, or copying of this communication, or any of its contents, is strictly prohibited and may be unlawful. If you have received this communication in error, please return it to the sender immediately and delete the original message and any copy of it from your computer system. If you have any questions concerning this message, please contact the sender.
> 
> [cid:image003.gif at 01CFBC96.E755A620]
> 
> _______________________________________________
> Swift-user mailing list
> Swift-user at ci.uchicago.edu
> https://lists.ci.uchicago.edu/cgi-bin/mailman/listinfo/swift-user




More information about the Swift-user mailing list