<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ahay.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sripanichy</id>
	<title>Madagascar - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://ahay.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Sripanichy"/>
	<link rel="alternate" type="text/html" href="https://ahay.org/wiki/Special:Contributions/Sripanichy"/>
	<updated>2026-04-29T12:53:06Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.7</generator>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2967</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2967"/>
		<updated>2014-08-01T20:31:57Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* Parallel Flow() using split and reduce */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct].  Note that Madagascar has a requirement that all internally-executing MPI programs must contain string &#039;mpi&#039; in the program name as it is needed for SCons to switch to a mpi compiler such as mpicc.&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables and how to run===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or avoid specifying the environment variables altogether by using,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Parallel Flow() using split and reduce===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc. Examples can be found in [http://www.ahay.org/RSF/book/rsf/school/data.html $RSFSRC/book/rsf/school/data/SConstruct] and $RSFSRC/book/trip/pscons/SConstruct.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2966</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2966"/>
		<updated>2014-08-01T19:39:15Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* Parallel Flow() using split and reduce */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct].  Note that Madagascar has a requirement that all internally-executing MPI programs must contain string &#039;mpi&#039; in the program name as it is needed for SCons to switch to a mpi compiler such as mpicc.&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables and how to run===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or avoid specifying the environment variables altogether by using,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Parallel Flow() using split and reduce===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc. An example can be found in [http://www.ahay.org/RSF/book/rsf/school/data.html $RSFSRC/book/rsf/school/data/SConstruct].&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2965</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2965"/>
		<updated>2014-08-01T18:58:43Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* MPI (internal) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct].  Note that Madagascar has a requirement that all internally-executing MPI programs must contain string &#039;mpi&#039; in the program name as it is needed for SCons to switch to a mpi compiler such as mpicc.&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables and how to run===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or avoid specifying the environment variables altogether by using,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Parallel Flow() using split and reduce===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2964</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2964"/>
		<updated>2014-08-01T18:42:20Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* Setting the environment variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables and how to run===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or avoid specifying the environment variables altogether by using,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Parallel Flow() using split and reduce===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2963</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2963"/>
		<updated>2014-08-01T18:40:32Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* The split and reduce options in Flow() */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or avoid specifying the environment variables altogether by using,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===Parallel Flow() using split and reduce===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2962</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2962"/>
		<updated>2014-08-01T18:37:58Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* Setting the environment variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or avoid specifying the environment variables altogether by using,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===The split and reduce options in Flow()===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2961</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2961"/>
		<updated>2014-08-01T18:36:21Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* pscons */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To execute using this method, one can then use the command &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; or if the environment variables aren&#039;t specified,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
scons -j 26 CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
===The split and reduce options in Flow()===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2960</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2960"/>
		<updated>2014-08-01T18:24:12Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP and MPI==&lt;br /&gt;
&lt;br /&gt;
===OpenMP (internal)===&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
===OpenMP (external)===&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===MPI (internal)===&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
===MPI (external)===&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
===MPI + OpenMP (both external)===&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The split and reduce options in Flow()===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2959</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2959"/>
		<updated>2014-08-01T16:06:57Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* OpenMP (external) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP (internal)==&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
==OpenMP (external)==&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=number of threads&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==MPI (internal)==&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
==MPI (external)==&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
==MPI + OpenMP (both external)==&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The split and reduce options in Flow()===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
	<entry>
		<id>https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2958</id>
		<title>Parallel Computing</title>
		<link rel="alternate" type="text/html" href="https://ahay.org/index.php?title=Parallel_Computing&amp;diff=2958"/>
		<updated>2014-08-01T15:45:25Z</updated>

		<summary type="html">&lt;p&gt;Sripanichy: /* OpenMP (external) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Image:Cluster.jpg|right|frame|[http://www.freedigitalphotos.net/images/view_photog.php?photogid=1152 Image: jscreationzs / FreeDigitalPhotos.net]]]&lt;br /&gt;
Many of the data processing operations are &#039;&#039;&#039;data-parallel&#039;&#039;&#039;: different traces, shot gathers, frequency slices, etc. can be processed independently. Madagascar provides several mechanisms for handling this type of embarrassingly parallel applications on computers with multiple processors. &lt;br /&gt;
&lt;br /&gt;
==OpenMP (internal)==&lt;br /&gt;
[https://secure.wikimedia.org/wikipedia/en/wiki/OpenMP OpenMP] is a standard framework for parallel applications on &#039;&#039;&#039;shared-memory&#039;&#039;&#039; systems. It is supported by the latest versions of [http://gcc.gnu.org/ GCC] and by some other compilers.&lt;br /&gt;
&lt;br /&gt;
To use OpenMP in your program, you do not need to add anything to your SConstruct. Just make sure the OMP libraries are installed on your system before you configure Madagascar, (or -- reinstall them and rerun the configuration command). Of course, you need to use the appropriate pragmas in your code. To find Madagascar programs that use OpenMP and that you can take as a model, run the following command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
grep &amp;quot;pragma omp&amp;quot; $RSFSRC/*/*/M*.c |\&lt;br /&gt;
awk -F &#039;:&#039; &#039;{ print $1 }&#039; |\&lt;br /&gt;
uniq |\&lt;br /&gt;
awk -F &#039;/&#039; &#039;{ print $NF }&#039; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
On the last check (2014-02-09), 139 standalone programs (approximately 11% of Madagascar programs) were using OMP. Running a similar command in the directory &amp;lt;tt&amp;gt;$RSFSRC/api/c&amp;lt;/tt&amp;gt; will yield a few library functions parallelized with OMP.&lt;br /&gt;
&lt;br /&gt;
==OpenMP (external)==&lt;br /&gt;
&lt;br /&gt;
To run on a multi-core shared-memory machine a data-parallel process that does not contain OpenMP calls, use &amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt;. Thus, a call like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
becomes&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
sfomp sfradon np=100 p0=0 dp=0.01 &amp;lt; inp.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&amp;lt;tt&amp;gt;sfomp&amp;lt;/tt&amp;gt; splits the input along the slowest axis (presumed to be data-parallel) and runs it through parallel threads. The number of threads is set by the &amp;lt;tt&amp;gt;OMP_NUM_THREADS&amp;lt;/tt&amp;gt; environmental variable or (by default) by the number of available CPUs. For example,&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export OMP_NUM_THREADS=&amp;lt;number of threads&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==MPI (internal)==&lt;br /&gt;
[http://www.mcs.anl.gov/research/projects/mpi/ MPI] (Message-Passing Interface) is the dominant standard framework for parallel processing on different computer architectures including &#039;&#039;&#039;distributed-memory&#039;&#039;&#039; systems. Several MPI implementations (such as [http://www.open-mpi.org/ Open MPI] and [http://www.mcs.anl.gov/research/projects/mpich2/ MPICH2]) are available.&lt;br /&gt;
&lt;br /&gt;
An example of compiling a program with &amp;lt;tt&amp;gt;mpicc&amp;lt;/tt&amp;gt; and running it under &amp;lt;tt&amp;gt;mpirun&amp;lt;/tt&amp;gt; can be found in [http://www.ahay.org/RSF/book/rsf/bash/mpi.html $RSFSRC/book/rsf/bash/mpi/SConstruct]&lt;br /&gt;
&lt;br /&gt;
==MPI (external)==&lt;br /&gt;
To parallelize a data-parallel task using MPI but without including MPI calls in your source code, try &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;, as follows:&lt;br /&gt;
&amp;lt;bash&amp;gt;&lt;br /&gt;
mpirun -np 8 sfmpi sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf split=2&lt;br /&gt;
&amp;lt;/bash&amp;gt;&lt;br /&gt;
where the argument after &amp;lt;tt&amp;gt;-np&amp;lt;/tt&amp;gt; specifies the number of processors involved. sfmpi will use this number to split the input along the slowest axis (presumed to be data-parallel) and to run it through parallel threads. Notice that the keywords &amp;lt;tt&amp;gt;input&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;output&amp;lt;/tt&amp;gt;, and &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; are specific to &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt;. They are used to specify the standard input and output streams of your program and the input axis to split.&lt;br /&gt;
&lt;br /&gt;
Some older MPI implementations do not support system calls implemented in &amp;lt;tt&amp;gt;sfmpi&amp;lt;/tt&amp;gt; and therefore may not support this feature.&lt;br /&gt;
&lt;br /&gt;
==MPI + OpenMP (both external)==&lt;br /&gt;
&lt;br /&gt;
It is possible to combine the advantages of shared-memory and distributed-memory architectures by using OpenMP and MPI together.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
mpirun -np 32 sfmpi sfomp sfradon np=100 p0=0 dp=0.01 input=inp.rsf output=out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
will distribute the job on 32 nodes and split it again on each node using shared-memory threads.&lt;br /&gt;
&lt;br /&gt;
==pscons==&lt;br /&gt;
To get SCons to cut your inputs into slices, run in parallel on one multi-cpu workstation or on multiple cluster nodes and then collect, use the &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; wrapper to &amp;lt;tt&amp;gt;scons&amp;lt;/tt&amp;gt;. Unlike the OpenMP or MPI utilities, this has fault tolerance -- in case of a node failing, restarting the job will allow it to complete.&lt;br /&gt;
&lt;br /&gt;
Simply running pscons with no special environment variable set is equivalent to running &amp;lt;tt&amp;gt;scons -j nproc&amp;lt;/tt&amp;gt;, where &amp;lt;tt&amp;gt;nproc&amp;lt;/tt&amp;gt; is the auto-detected number of threads on your system. To fully use the potential of &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; for running on a distributed-memory computer, you need to set the environment variables &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt;, and to use &amp;lt;tt&amp;gt;split&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;reduce&amp;lt;/tt&amp;gt; arguments in your SConstruct Flow statements where appropriate.&lt;br /&gt;
&lt;br /&gt;
===Setting the environment variables===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; variable holds, for each node, the name or IP address of that node (in a format that can be used by ssh), followed by the number of threads on the node. For example, creating 26 threads and sending them on 4 nodes, using respectively 6 CPUs on the first node, 4 CPUs on the second, and 8 CPUs on each of the last two nodes:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_CLUSTER=&#039;140.168.1.236 6 140.168.1.235 4 140.168.1.234 8 140.168.1.233 8&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; variable holds the sum of the numbers of threads on all nodes, i.e.:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export RSF_THREADS=26&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
If &amp;lt;tt&amp;gt;RSF_CLUSTER&amp;lt;/tt&amp;gt; is not defined, &amp;lt;tt&amp;gt;RSF_THREADS&amp;lt;/tt&amp;gt; can be used to override the auto-detected number of threads used on the local host. This can be useful in the case of processes using a large amount of memory.&lt;br /&gt;
&lt;br /&gt;
In Beowulf-type clusters in which communication of the processor with the local disk is much faster than with the shared network storage, it is important to set in the shell resource file the temporary file location to a local disk, and the &amp;lt;tt&amp;gt;DATAPATH&amp;lt;/tt&amp;gt; variable to a network-visible location for global collection of results, i.e.:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
export DATAPATH=/disk1/data/myname/&lt;br /&gt;
export TMPDATAPATH=/tmp/&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===The split and reduce options in Flow()===&lt;br /&gt;
The split option specifies the number of the axis to be split and the size of that axis. For an axis 3 of length 1000 on the standard in file, and collection by concatenation:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;radon&#039;,&#039;spike&#039;,&#039;radon adj=y p0=-4 np=200 dp=0.04&#039;,split=[3,1000],reduce=&#039;cat&#039;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Concatenation on the same axis as specified by &amp;lt;tt&amp;gt;split=&amp;lt;/tt&amp;gt; is the default reduction method. Possible other valid options are &amp;lt;tt&amp;gt;reduce=&#039;add&#039;&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;reduce=&#039;cat axis=1&#039;&amp;lt;/tt&amp;gt;, etc.&lt;br /&gt;
&lt;br /&gt;
If flows that are run by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; contain both serial and parallel targets, care must be exercised in order to not create bottlenecks, in which tasks are distributed to multiple nodes, but the nodes sit idle while waiting for other nodes to finish computing dependencies. Tasks that are not explicitly parallelized will be sped up by &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; if they are independent from each other. For example, compiling Madagascar itself with &amp;lt;tt&amp;gt;pscons&amp;lt;/tt&amp;gt; instead of scons results in a visible speedup on a multithreaded machine.&lt;br /&gt;
&lt;br /&gt;
=== Computing on the local node only by using the option local=1 ===&lt;br /&gt;
&lt;br /&gt;
By default, with &#039;&#039;&#039;pscons&#039;&#039;&#039;, SCons attempts to run all the commands of the &amp;lt;tt&amp;gt;SConstruct&amp;lt;/tt&amp;gt; file in parallel.&lt;br /&gt;
The option &#039;&#039;&#039;local=1&#039;&#039;&#039; forces SCons to compute locally on the head node of the cluster. It can be useful for preventing serial&lt;br /&gt;
parts of your python script to be distributed across multiple nodes.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;spike&#039;,None,&#039;spike n1=100 n2=300 n3=1000&#039;,local=1)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===What to expect at runtime===&lt;br /&gt;
SCons will create intermediate input and output slices in the current directory. For example, for&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
Flow(&#039;out&#039;,&#039;inp&#039;,&#039;radon np=100 p0=0 dp=0.01&#039;,split=[3,256])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
and&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
RSF_THREADS=8&lt;br /&gt;
RSF_CLUSTER=&#039;localhost 4 node1.utexas.edu 4&#039;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
the SCons output will look like:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=0 squeeze=n &amp;gt; inp__0.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=42 squeeze=n &amp;gt; inp__1.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=84 squeeze=n &amp;gt; inp__2.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=126 squeeze=n &amp;gt; inp__3.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp.rsf /RSFROOT/bin/sfwindow n3=42 f3=168 squeeze=n &amp;gt; inp__4.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp.rsf /RSFROOT/bin/sfwindow f3=210 squeeze=n &amp;gt; inp__5.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__0.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__0.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; /bin/env &amp;lt; inp__1.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__1.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__3.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__3.rsf&lt;br /&gt;
&lt;br /&gt;
/usr/bin/ssh node1.utexas.edu &amp;quot;cd /home/test ; &amp;lt; spike__4.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__4.rsf &amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__2.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__2.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; inp__5.rsf /RSFROOT/bin/sfradon p0=0 np=100 dp=0.01 &amp;gt; out__5.rsf&lt;br /&gt;
&lt;br /&gt;
&amp;lt; out__0.rsf /RSFROOT/bin/sfcat axis=3 out__1.rsf out__2.rsf out__3.rsf out__4.rsf out__5.rsf &amp;gt; out.rsf&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that operations were sent for execution in parallel, but the display is necessarily serial.&lt;br /&gt;
&lt;br /&gt;
Runtime job monitoring can be achieved with &#039;&#039;&#039;sftop&#039;&#039;&#039;. To kill a distributed job, use &#039;&#039;&#039;sfkill&#039;&#039;&#039;.&lt;/div&gt;</summary>
		<author><name>Sripanichy</name></author>
	</entry>
</feed>