<div dir="ltr"><div><div><div><div>Hi Tim,<br> It's possible if you reformulate the problem in terms of data flow- there's no direct way in Swift to ask "is the loop finished" - but there is a way to ask "is the data being computed by the loop finished".<br><br>The "wait" construct - it lets you execute a block of code after a bit of data is assigned.<br><br></div>E.g. a trivial example is<br><br></div><span style="font-family:monospace,monospace">int x = do_some_computation();<br></span></div><span style="font-family:monospace,monospace">wait (x) {<br></span></div><span style="font-family:monospace,monospace"> trace("x is done!");<br></span><div><div><span style="font-family:monospace,monospace">}</span><br><br></div><div>If you're building an array of files or similar, it's a little more complicated:<br><br><span style="font-family:monospace,monospace">import io;<br>import files;<br><br>file x[];<br><br>wait deep (x) {<br> trace("Done");<br>}<br><br>foreach i in [1:10] {<br> file tmp<"/tmp/swift-tmp-" + i + ".txt">;<br><br> tmp = write("");<br><br> x[i] = tmp;<br>}</span><br><br></div><div>This only prints "Done" once all of the files have been written. The wait deep ensures that everything in the array is completely built. <br><br></div><div>I'm also not sure about your use case, but Swift has some built-in support for generating temporary files - Justin Wozniak was recently working on improving that.<br><br></div><div>- Tim<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 17 March 2015 at 15:08, Timothy Stitt (TGAC) <span dir="ltr"><<a href="mailto:Timothy.Stitt@tgac.ac.uk" target="_blank">Timothy.Stitt@tgac.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word;color:rgb(0,0,0);font-size:14px;font-family:Candara,sans-serif">
<div>Hi all,</div>
<div><br>
</div>
<div>Is there a way to add explicit blocking to the end of the foreach construct? I have the following logic which doesn't work right now as the delete_files() routine is assumed to be concurrent with the foreach block when I want it to execute after the foreach
block is completed for all workers:</div>
<div><br>
</div>
<div>foreach { do some work creating temp files}</div>
<div>delete_files() // delete temp files using an app function</div>
<div><br>
</div>
<div>Thanks,</div>
<div><br>
</div>
<div>Tim.</div>
<div>
<p style="font-size:12px;margin:0px;font-family:Verdana">---</p>
<p style="margin:0px;font-family:Verdana"><span style="font-size:10px"><b>Timothy Stitt PhD</b> / Head of Scientific Computing</span></p>
<p style="margin:0px;font-family:Verdana"><span style="font-size:10px">The Genome Analysis Centre (TGAC)</span></p>
<p style="margin:0px;font-family:Verdana;color:rgb(4,46,238)"><span style="text-decoration:underline;font-size:10px"><a href="http://www.tgac.ac.uk/" target="_blank">http://www.tgac.ac.uk/</a></span></p>
<p style="margin:0px;font-family:Cambria;min-height:19px"><span style="font-size:10px"><br>
</span></p>
<p style="margin:0px;font-family:Verdana"><span style="font-size:10px">p: <a href="tel:%2B44%201603%20450378" value="+441603450378" target="_blank">+44 1603 450378</a></span></p>
<p style="margin:0px;font-family:Verdana;color:rgb(13,102,213)"><span style="color:rgb(0,0,0);font-size:10px">e: <a href="mailto:timothy.stitt@tgac.ac.uk" target="_blank">timothy.stitt@tgac.ac.uk</a></span></p>
</div>
</div>
<br>_______________________________________________<br>
ExM-user mailing list<br>
<a href="mailto:ExM-user@lists.mcs.anl.gov">ExM-user@lists.mcs.anl.gov</a><br>
<a href="https://lists.mcs.anl.gov/mailman/listinfo/exm-user" target="_blank">https://lists.mcs.anl.gov/mailman/listinfo/exm-user</a><br>
<br></blockquote></div><br></div>