Manual Patch: Programs
Jeffrey
oldham at mail.codesourcery.com
Thu Jan 31 22:25:50 UTC 2002
The files containing the DocBook annotations for programs included in
the POOMA manual got mangled. Hopefully, the attached changes ensured
every file appears exactly once.
Sorry,
Jeffrey D. Oldham
oldham at codesourcery.com
-------------- next part --------------
? programs-2002Jan31.patch
Index: Makefile
===================================================================
RCS file: Makefile
diff -N Makefile
*** /dev/null Fri Mar 23 21:37:44 2001
--- Makefile Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,15 ----
+ ### Oldham, Jeffrey D.
+ ### 2001Nov27
+ ### Pooma
+ ###
+ ### Produce Annotated Source Code
+
+ ## These rules combine executable code, which can be compiled and run,
+ ## with DocBook annotations used in the manual to explain the code.
+
+ all: array-copy-annotated.cpp dynamicarray-annotated.cpp \
+ initialize-finalize-annotated.cpp \
+ pairs-templated-annotated.cpp pairs-untemplated-annotated.cpp
+
+ %-annotated.cpp: %-annotated.patch %.cpp
+ patch -o $@ < $<
Index: array-copy-annotated.patch
===================================================================
RCS file: array-copy-annotated.patch
diff -N array-copy-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- array-copy-annotated.patch Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,78 ----
+ *** array-copy.cpp Thu Jan 24 11:12:23 2002
+ --- array-copy-annotated.cpp Thu Jan 31 09:22:57 2002
+ ***************
+ *** 1,8 ****
+ #include "Pooma/Pooma.h"
+ #include "Pooma/Arrays.h"
+ ! #include <iostream>
+
+ // Changes the Array value at index (0,0).
+ ! void changeValue(Array<2,int,Brick>& z)
+ { z(0,0) = 6; }
+
+ --- 1,9 ----
+ + <programlisting id="array-copy-program" linenumbering="numbered" format="linespecific">
+ #include "Pooma/Pooma.h"
+ #include "Pooma/Arrays.h"
+ ! #include <iostream>
+
+ // Changes the Array value at index (0,0).
+ ! void changeValue(Array<2,int,Brick>& z)
+ { z(0,0) = 6; }
+
+ ***************
+ *** 11,35 ****
+ Pooma::initialize(argc,argv);
+
+ ! Array<2,int,Brick> a(3,4, ModelElement<int>(4));
+ ! std::cout << "Initial value:\n";
+ ! std::cout << "a: " << a(0,0) << std::endl;
+
+ // Array copies share the same underlying values.
+
+ ! // Explicit initialization uses reference semantics so changing the
+ ! // copy's value at (0,0) also changes the original's value.
+ ! Array<2,int,Brick> b(a);
+ b(0,0) = 5;
+ ! std::cout << "After explicit initialization.\n";
+ ! std::cout << "a: " << a(0,0) << std::endl;
+ ! std::cout << "b: " << b(0,0) << std::endl;
+ !
+ ! // Initialization of function arguments also uses reference semantics.
+ ! std::cout << "After function call:\n";
+ changeValue(a);
+ ! std::cout << "a: " << a(0,0) << std::endl;
+ ! std::cout << "b: " << b(0,0) << std::endl;
+
+ Pooma::finalize();
+ return 0;
+ }
+ --- 12,39 ----
+ Pooma::initialize(argc,argv);
+
+ ! Array<2,int,Brick> a(3,4, ModelElement<int>(4));
+ ! std::cout &openopen; "Initial value:\n";
+ ! std::cout &openopen; "a: " &openopen; a(0,0) &openopen; std::endl;
+
+ // Array copies share the same underlying values.
+
+ ! // Explicit initialization uses reference semantics
+ ! // so changing the copy's value at (0,0) also
+ ! // changes the original's value.
+ ! Array<2,int,Brick> b(a);
+ b(0,0) = 5;
+ ! std::cout &openopen; "After explicit initialization.\n";
+ ! std::cout &openopen; "a: " &openopen; a(0,0) &openopen; std::endl;
+ ! std::cout &openopen; "b: " &openopen; b(0,0) &openopen; std::endl;
+ !
+ ! // Initialization of function arguments also uses
+ ! // reference semantics.
+ ! std::cout &openopen; "After function call:\n";
+ changeValue(a);
+ ! std::cout &openopen; "a: " &openopen; a(0,0) &openopen; std::endl;
+ ! std::cout &openopen; "b: " &openopen; b(0,0) &openopen; std::endl;
+
+ Pooma::finalize();
+ return 0;
+ }
+ + </programlisting>
Index: array-size-annotated.patch
===================================================================
RCS file: array-size-annotated.patch
diff -N array-size-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- array-size-annotated.patch Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,80 ----
+ *** array-size.cpp Tue Jan 15 13:30:53 2002
+ --- array-size-annotated.cpp Thu Jan 31 09:24:16 2002
+ ***************
+ *** 1,25 ****
+ #include "Pooma/Pooma.h"
+ #include "Pooma/Arrays.h"
+ ! #include <iostream>
+
+ // Print an Array's Size
+
+ ! // This program illustrates using the Array member functions.
+ ! // computeArraySize's computation is redundant because Array's size()
+ ! // function computes the same value, but it illustrates using Array
+ // member functions.
+
+ ! template <int Dim, typename Type, typename EngineTag>
+ inline
+ ! long computeArraySize(const Array<Dim,Type,EngineTag>& a)
+ {
+ ! const Loc<Dim> fs = a.firsts();
+ ! const Loc<Dim> ls = a.lasts();
+ ! const Loc<Dim> lens = a.lengths();
+ long size = 1;
+ ! for (int d = 0; d < Dim; ++d) {
+ ! size *= lens[d].first();
+ // Check that lengths() and our computed lengths agree.
+ ! PAssert((ls[d] - fs[d] + 1).first() == a.length(d));
+ }
+ return size;
+ --- 1,27 ----
+ + <programlisting id="array-size-program" linenumbering="numbered" format="linespecific">
+ #include "Pooma/Pooma.h"
+ #include "Pooma/Arrays.h"
+ ! #include <iostream>
+
+ // Print an Array's Size
+
+ ! // This program illustrates using the Array member
+ ! // functions. computeArraySize's computation is
+ ! // redundant because Array's size() function computes
+ ! // the same value, but it illustrates using Array
+ // member functions.
+
+ ! template <int Dim,typename Type,typename EngineTag> <co id="arrays-arrays_use-members-example-template_parameters"></co>
+ inline
+ ! long computeArraySize(const Array<Dim,Type,EngineTag>& a)
+ {
+ ! const Loc<Dim> fs = a.firsts(); <co id="arrays-arrays_use-members-example-function_call"></co>
+ ! const Loc<Dim> ls = a.lasts();
+ ! const Loc<Dim> lens = a.lengths();
+ long size = 1;
+ ! for (int d = 0; d < Dim; ++d) {
+ ! size *= lens[d].first(); <co id="arrays-arrays_use-members-example-loc_use"></co>
+ // Check that lengths() and our computed lengths agree.
+ ! PAssert((ls[d]-fs[d]+1).first()==a.length(d)); <co id="arrays-arrays_use-members-example-check_length"></co>
+ }
+ return size;
+ ***************
+ *** 30,38 ****
+ Pooma::initialize(argc,argv);
+
+ ! Array<3,int,Brick> a(3,4,5, ModelElement<int>(4));
+ ! PAssert(computeArraySize(a) == a.size());
+ ! std::cout << "The array's size is " << a.size() << ".\n";
+
+ Pooma::finalize();
+ return 0;
+ }
+ --- 32,42 ----
+ Pooma::initialize(argc,argv);
+
+ ! Array<3,int,Brick> a(3,4,5, ModelElement<int>(4));
+ ! PAssert(computeArraySize(a) == a.size()); <co id="arrays-arrays_use-members-example-compare_size"></co>
+ ! std::cout &openopen;
+ ! "The array's size is " &openopen; a.size() &openopen; ".\n";
+
+ Pooma::finalize();
+ return 0;
+ }
+ + </programlisting>
Index: dynamicarray-annotated.patch
===================================================================
RCS file: dynamicarray-annotated.patch
diff -N dynamicarray-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- dynamicarray-annotated.patch Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,80 ----
+ *** dynamicarray.cpp Mon Jan 21 17:29:38 2002
+ --- dynamicarray-annotated.cpp Tue Jan 22 07:06:15 2002
+ ***************
+ *** 1,5 ****
+ #include "Pooma/Pooma.h"
+ ! #include "Pooma/DynamicArrays.h"
+ ! #include <iostream>
+
+ // Demonstrate using DynamicArrays.
+ --- 1,6 ----
+ + <programlisting id="dynamicarray-program" linenumbering="numbered" format="linespecific">
+ #include "Pooma/Pooma.h"
+ ! #include "Pooma/DynamicArrays.h" <co id="arrays-dynamic_arrays-example-header"></co>
+ ! #include <iostream>
+
+ // Demonstrate using DynamicArrays.
+ ***************
+ *** 9,38 ****
+ Pooma::initialize(argc,argv);
+
+ ! // Create a DynamicArray with one element.
+ ! DynamicArray<> d0(1);
+ ! DynamicArray<double> d01(1);
+ ! DynamicArray<double, Dynamic> d02(1);
+
+ ! // Add five more elements.
+ d0.create(5);
+ // Store values in the array.
+ ! for (int i = d0.domain().first(); i <= d0.domain().last(); ++i)
+ ! d0(i) = i;
+
+ ! // Delete every other element.
+ ! d0.destroy(Range<1>(d0.domain().first(),d0.domain().last(),2), BackFill());
+
+ // Print the resulting array.
+ ! std::cout << d0 << std::endl;
+
+ // Use the iterator form of 'destroy.'
+ ! DynamicArray<> d1(6);
+ for (int i = d1.domain().first(); i <= d1.domain().last(); ++i)
+ d1(i) = i;
+ ! int killList[] = { 0, 2, 4 };
+ d1.destroy(killList, killList+3);
+ ! std::cout << d1 << std::endl;
+
+ Pooma::finalize();
+ return 0;
+ }
+ --- 10,40 ----
+ Pooma::initialize(argc,argv);
+
+ ! // Create a DynamicArray with one element. <co id="arrays-dynamic_arrays-example-identical_declarations"></co>
+ ! DynamicArray<> d0(1);
+ ! DynamicArray<double> d01(1);
+ ! DynamicArray<double, Dynamic> d02(1);
+
+ ! // Add five more elements. <co id="arrays-dynamic_arrays-example-extension"></co>
+ d0.create(5);
+ // Store values in the array.
+ ! for (int i = d0.domain().first(); i <= d0.domain().last(); ++i)
+ ! d0(i) = i; <co id="arrays-dynamic_arrays-example-access"></co>
+
+ ! // Delete every other element. <co id="arrays-dynamic_arrays-example-destroy_range"></co>
+ ! d0.destroy(Range<1>(d0.domain().first(),d0.domain().last(),2), BackFill());
+
+ // Print the resulting array.
+ ! std::cout &openopen; d0 &openopen; std::endl;
+
+ // Use the iterator form of 'destroy.'
+ ! DynamicArray<> d1(6);
+ for (int i = d1.domain().first(); i <= d1.domain().last(); ++i)
+ d1(i) = i;
+ ! int killList[] = { 0, 2, 4 }; <co id="arrays-dynamic_arrays-example-destroy_iterators"></co>
+ d1.destroy(killList, killList+3);
+ ! std::cout &openopen; d1 &openopen; std::endl;
+
+ Pooma::finalize();
+ return 0;
+ }
+ + </programlisting>
Index: initialize-finalize-annotated.patch
===================================================================
RCS file: initialize-finalize-annotated.patch
diff -N initialize-finalize-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- initialize-finalize-annotated.patch Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,20 ----
+ *** initialize-finalize.cpp Thu Jan 24 11:14:13 2002
+ --- initialize-finalize-annotated.cpp Thu Jan 24 11:14:17 2002
+ ***************
+ *** 1,4 ****
+ #include "Pooma/Pooma.h"
+ ! #include <iostream>
+
+ int main(int argc, char *argv[])
+ --- 1,5 ----
+ + <programlisting id="initialize-finalize-program" linenumbering="numbered" format="linespecific">
+ #include "Pooma/Pooma.h"
+ ! #include <iostream>
+
+ int main(int argc, char *argv[])
+ ***************
+ *** 11,12 ****
+ --- 12,14 ----
+ return 0;
+ }
+ + </programlisting>
Index: pairs-templated-annotated.patch
===================================================================
RCS file: pairs-templated-annotated.patch
diff -N pairs-templated-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- pairs-templated-annotated.patch Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,38 ----
+ *** pairs-templated.cpp Mon Jan 7 16:11:56 2002
+ --- pairs-templated-annotated.cpp Thu Jan 31 08:44:35 2002
+ ***************
+ *** 1,15 ****
+ ! // Declare a template class storing a pair of values with the same type.
+ ! template <typename T>
+ struct pair {
+ ! pair(const int& left, const int& right)
+ : left_(left), right_(right) {}
+
+ ! T left_;
+ T right_;
+ };
+
+ ! // Define a class storing a pair of integers.
+ ! pair<int> pair1;
+
+ ! // Define a class storing a pair of doubles;
+ ! pair<double> pair2;
+ --- 1,18 ----
+ ! <programlisting id="template_programming-template_use-templated_pair_program" linenumbering="numbered" format="linespecific">
+ ! // Declare a template class storing a pair of values
+ ! // with the same type.
+ ! template <typename T> // <co id="template_programming-template_use-templated_pair_program-template_declaration"></co>
+ struct pair {
+ ! pair(const T& left, const T& right) // <co id="template_programming-template_use-templated_pair_program-constructor"></co>
+ : left_(left), right_(right) {}
+
+ ! T left_; // <co id="template_programming-template_use-templated_pair_program-members"></co>
+ T right_;
+ };
+
+ ! // Use a class storing a pair of integers. <co id="template_programming-template_use-templated_pair_program-use"></co>
+ ! pair<int> pair1;
+
+ ! // Use a class storing a pair of doubles;
+ ! pair<double> pair2;
+ ! </programlisting>
Index: pairs-untemplated-annotated.patch
===================================================================
RCS file: pairs-untemplated-annotated.patch
diff -N pairs-untemplated-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- pairs-untemplated-annotated.patch Thu Jan 31 15:19:46 2002
***************
*** 0 ****
--- 1,35 ----
+ *** pairs-untemplated.cpp Wed Dec 26 13:48:10 2001
+ --- pairs-untemplated-annotated.cpp Wed Dec 26 14:02:58 2001
+ ***************
+ *** 1,5 ****
+ // Declare a class storing a pair of integers.
+ struct pairOfInts {
+ ! pairOfInts(const int& left, const int& right)
+ : left_(left), right_(right) {}
+
+ --- 1,6 ----
+ + <programlisting id="template_programming-template_use-untemplated_pair_program" linenumbering="numbered" format="linespecific">
+ // Declare a class storing a pair of integers.
+ struct pairOfInts {
+ ! pairOfInts(const int& left, const int& right)
+ : left_(left), right_(right) {}
+
+ ***************
+ *** 10,14 ****
+ // Declare a class storing a pair of doubles.
+ struct pairOfDoubles {
+ ! pairOfDoubles(const double& left, const double& right)
+ : left_(left), right_(right) {}
+
+ --- 11,15 ----
+ // Declare a class storing a pair of doubles.
+ struct pairOfDoubles {
+ ! pairOfDoubles(const double& left, const double& right)
+ : left_(left), right_(right) {}
+
+ ***************
+ *** 16,17 ****
+ --- 17,19 ----
+ double right_;
+ };
+ + </programlisting>
-------------- next part --------------
Index: Doof2d-Array-distributed-annotated.patch
===================================================================
RCS file: Doof2d-Array-distributed-annotated.patch
diff -N Doof2d-Array-distributed-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-Array-distributed-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,251 ----
+ *** Doof2d-Array-distributed.cpp Mon Jan 28 20:35:07 2002
+ --- Doof2d-Array-distributed-annotated.cpp Thu Jan 31 09:12:19 2002
+ ***************
+ *** 1,6 ****
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h" // has POOMA's Array declarations
+
+ ! // Doof2d: POOMA Arrays, stencil, multiple processor implementation
+
+ // Define the stencil class performing the computation.
+ --- 1,10 ----
+ ! <programlisting id="tutorial-array_distributed-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h"
+ ! // has POOMA's Array declarations
+
+ ! // Doof2d: POOMA Arrays, stencil, multiple
+ ! // processor implementation
+
+ // Define the stencil class performing the computation.
+ ***************
+ *** 11,26 ****
+ DoofNinePt() : weight(1.0/9.0) {}
+
+ ! // This stencil operator is applied to each interior domain position
+ ! // (i,j). The "C" template parameter permits use of this stencil
+ // operator with both Arrays and Fields.
+ ! template <class C>
+ inline
+ typename C::Element_t
+ ! operator()(const C& x, int i, int j) const
+ ! {
+ ! return ( weight *
+ ! ( x.read(i+1,j+1) + x.read(i+1,j ) + x.read(i+1,j-1) +
+ ! x.read(i ,j+1) + x.read(i ,j ) + x.read(i ,j-1) +
+ ! x.read(i-1,j+1) + x.read(i-1,j ) + x.read(i-1,j-1) ) );
+ }
+
+ --- 15,31 ----
+ DoofNinePt() : weight(1.0/9.0) {}
+
+ ! // This stencil operator is applied to each interior
+ ! // domain position (i,j). The "C" template
+ ! // parameter permits use of this stencil
+ // operator with both Arrays and Fields.
+ ! template <class C>
+ inline
+ typename C::Element_t
+ ! operator()(const C& x, int i, int j) const {
+ ! return
+ ! weight *
+ ! (x.read(i+1,j+1)+x.read(i+1,j)+x.read(i+1,j-1) +
+ ! x.read(i ,j+1)+x.read(i ,j)+x.read(i ,j-1) +
+ ! x.read(i-1,j+1)+x.read(i-1,j)+x.read(i-1,j-1));
+ }
+
+ ***************
+ *** 39,52 ****
+ Pooma::initialize(argc,argv);
+
+ ! // Since multiple copies of this program may simultaneously run, we
+ ! // cannot use standard input and output. Instead we use command-line
+ ! // arguments, which are replicated, for input, and we use an Inform
+ ! // stream for output.
+ Inform output;
+
+ ! // Read the program input from the command-line arguments.
+ if (argc != 4) {
+ // Incorrect number of command-line arguments.
+ ! output << argv[0] << ": number-of-processors number-of-averagings number-of-values" << std::endl;
+ return EXIT_FAILURE;
+ }
+ --- 44,63 ----
+ Pooma::initialize(argc,argv);
+
+ ! // Since multiple copies of this program may simul-
+ ! // taneously run, we cannot use standard input and
+ ! // output. Instead we use command-line arguments,
+ ! // which are replicated, for input, and we use an
+ ! // Inform stream for output. <co id="tutorial-array_distributed-doof2d-io"></co>
+ Inform output;
+
+ ! // Read the program input from the command-line
+ ! // arguments.
+ if (argc != 4) {
+ // Incorrect number of command-line arguments.
+ ! output &openopen;
+ ! argv[0] &openopen;
+ ! ": number-of-processors number-of-averagings"
+ ! &openopen; " number-of-values"
+ ! &openopen; std::endl;
+ return EXIT_FAILURE;
+ }
+ ***************
+ *** 55,112 ****
+ // Determine the number of processors.
+ long nuProcessors;
+ ! nuProcessors = strtol(argv[1], &tail, 0);
+
+ // Determine the number of averagings.
+ long nuAveragings, nuIterations;
+ ! nuAveragings = strtol(argv[2], &tail, 0);
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! n = strtol(argv[3], &tail, 0);
+ ! // The dimension must be a multiple of the number of processors
+ ! // since we are using a UniformGridLayout.
+ ! n = ((n+nuProcessors-1) / nuProcessors) * nuProcessors;
+
+ // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<2> interiorDomain(I,I);
+
+ // Create the distributed arrays.
+ ! // Partition the arrays' domains uniformly, i.e., each patch has the
+ ! // same size. The first parameter tells how many patches for each
+ ! // dimension. Guard layers optimize communication between patches.
+ ! // Internal guards surround each patch. External guards surround
+ ! // the entire array domain.
+ ! UniformGridPartition<2> partition(Loc<2>(nuProcessors, nuProcessors),
+ ! GuardLayers<2>(1), // internal
+ ! GuardLayers<2>(0)); // external
+ ! UniformGridLayout<2> layout(vertDomain, partition, DistributedTag());
+ !
+ ! // The Array template parameters indicate 2 dimensions and a 'double'
+ ! // value type. MultiPatch indicates multiple computation patches,
+ ! // i.e., distributed computation. The UniformTag indicates the
+ ! // patches should have the same size. Each patch has Brick type.
+ ! Array<2, double, MultiPatch<UniformTag, Remote<Brick> > > a(layout);
+ ! Array<2, double, MultiPatch<UniformTag, Remote<Brick> > > b(layout);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+
+ // Create the stencil performing the computation.
+ ! Stencil<DoofNinePt> stencil;
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a.
+ a(interiorDomain) = stencil(b, interiorDomain);
+
+ --- 66,137 ----
+ // Determine the number of processors.
+ long nuProcessors;
+ ! nuProcessors = strtol(argv[1], &tail, 0);
+
+ // Determine the number of averagings.
+ long nuAveragings, nuIterations;
+ ! nuAveragings = strtol(argv[2], &tail, 0);
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along
+ ! // one dimension of the grid.
+ long n;
+ ! n = strtol(argv[3], &tail, 0);
+ ! // The dimension must be a multiple of the number
+ ! // of processors since we are using a
+ ! // UniformGridLayout.
+ ! n=((n+nuProcessors-1)/nuProcessors)*nuProcessors;
+
+ // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1)
+ ! // for computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<2> interiorDomain(I,I);
+
+ // Create the distributed arrays.
+ !
+ ! // Partition the arrays' domains uniformly, i.e.,
+ ! // each patch has the same size. The first para-
+ ! // meter tells how many patches for each dimension.
+ ! // Guard layers optimize communication between
+ ! // patches. Internal guards surround each patch.
+ ! // External guards surround the entire array
+ ! // domain. <co id="tutorial-array_distributed-doof2d-layout"></co>
+ ! UniformGridPartition<2>
+ ! partition(Loc<2>(nuProcessors, nuProcessors),
+ ! GuardLayers<2>(1), // internal
+ ! GuardLayers<2>(0)); // external
+ ! UniformGridLayout<2> layout(vertDomain, partition,
+ ! DistributedTag());
+ !
+ ! // The Array template parameters indicate 2 dims
+ ! // and a 'double' value type. MultiPatch indicates
+ ! // multiple computation patches, i.e, distributed
+ ! // computation. The UniformTag indicates the
+ ! // patches should have the same size. Each patch
+ ! // has Brick type. <co id="tutorial-array_distributed-doof2d-remote"></co>
+ ! Array<2, double, MultiPatch<UniformTag,
+ ! Remote<Brick> > > a(layout);
+ ! Array<2, double, MultiPatch<UniformTag,
+ ! Remote<Brick> > > b(layout);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes
+ ! // before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+
+ // Create the stencil performing the computation.
+ ! Stencil<DoofNinePt> stencil;
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a. <co id="tutorial-array_distributed-doof2d-first_write"></co>
+ a(interiorDomain) = stencil(b, interiorDomain);
+
+ ***************
+ *** 116,121 ****
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate(); // Ensure all computation has finished.
+ ! output << (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2)) << std::endl;
+
+ // The arrays are automatically deallocated.
+ --- 141,149 ----
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate();
+ ! // Ensure all computation has finished.
+ ! output &openopen;
+ ! (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2))
+ ! &openopen; std::endl;
+
+ // The arrays are automatically deallocated.
+ ***************
+ *** 125,126 ****
+ --- 153,155 ----
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Doof2d-Array-element-annotated.patch
===================================================================
RCS file: Doof2d-Array-element-annotated.patch
diff -N Doof2d-Array-element-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-Array-element-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,149 ----
+ *** Doof2d-Array-element.cpp Wed Jan 23 19:18:17 2002
+ --- Doof2d-Array-element-annotated.cpp Thu Jan 31 08:55:57 2002
+ ***************
+ *** 1,5 ****
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h" // has POOMA's Array declarations
+
+ // Doof2d: POOMA Arrays, element-wise implementation
+ --- 1,7 ----
+ ! <programlisting id="tutorial-array_elementwise-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h"
+ ! // has POOMA's Array declarations <co id="tutorial-array_elementwise-doof2d-header"></co>
+
+ // Doof2d: POOMA Arrays, element-wise implementation
+ ***************
+ *** 7,37 ****
+ int main(int argc, char *argv[])
+ {
+ ! // Prepare the POOMA library for execution.
+ Pooma::initialize(argc,argv);
+
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout << "Please enter the number of averagings: ";
+ ! std::cin >> nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! std::cout << "Please enter the array size: ";
+ ! std::cin >> n;
+
+ ! // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+ !
+ ! // Create the arrays.
+ ! // The Array template parameters indicate 2 dimensions, a 'double' value
+ // type, and ordinary 'Brick' storage.
+ ! Array<2, double, Brick> a(vertDomain);
+ ! Array<2, double, Brick> b(vertDomain);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ for (int j = 1; j < n-1; j++)
+ for (int i = 1; i < n-1; i++)
+ --- 9,42 ----
+ int main(int argc, char *argv[])
+ {
+ ! // Prepare the POOMA library for execution. <co id="tutorial-array_elementwise-doof2d-pooma_initialize"></co>
+ Pooma::initialize(argc,argv);
+
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout &openopen; "Please enter the number of averagings: ";
+ ! std::cin &closeclose; nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along
+ ! // one dimension of the grid.
+ long n;
+ ! std::cout &openopen; "Please enter the array size: ";
+ ! std::cin &closeclose; n;
+
+ ! // Specify the arrays' domains [0,n) x [0,n). <co id="tutorial-array_elementwise-doof2d-domain"></co>
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+ !
+ ! // Create the arrays. <co id="tutorial-array_elementwise-doof2d-array_creation"></co>
+ ! // The Array template parameters indicate
+ ! // 2 dimensions, a 'double' value
+ // type, and ordinary 'Brick' storage.
+ ! Array<2, double, Brick> a(vertDomain);
+ ! Array<2, double, Brick> b(vertDomain);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value. <co id="tutorial-array_elementwise-doof2d-initialization"></co>
+ for (int j = 1; j < n-1; j++)
+ for (int i = 1; i < n-1; i++)
+ ***************
+ *** 43,51 ****
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ // Read from b. Write to a.
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ ! a(i,j) = weight *
+ (b(i+1,j+1) + b(i+1,j ) + b(i+1,j-1) +
+ b(i ,j+1) + b(i ,j ) + b(i ,j-1) +
+ --- 48,56 ----
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ // Read from b. Write to a.
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ ! a(i,j) = weight * <co id="tutorial-array_elementwise-doof2d-first_write"></co>
+ (b(i+1,j+1) + b(i+1,j ) + b(i+1,j-1) +
+ b(i ,j+1) + b(i ,j ) + b(i ,j-1) +
+ ***************
+ *** 53,58 ****
+
+ // Read from a. Write to b.
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ b(i,j) = weight *
+ (a(i+1,j+1) + a(i+1,j ) + a(i+1,j-1) +
+ --- 58,63 ----
+
+ // Read from a. Write to b.
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ b(i,j) = weight *
+ (a(i+1,j+1) + a(i+1,j ) + a(i+1,j-1) +
+ ***************
+ *** 62,71 ****
+
+ // Print out the final central value.
+ ! std::cout << (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2)) << std::endl;
+
+ ! // The arrays are automatically deallocated.
+
+ ! // Tell the POOMA library execution has finished.
+ Pooma::finalize();
+ return EXIT_SUCCESS;
+ }
+ --- 67,81 ----
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate();
+ ! // Ensure all computation has finished.
+ ! std::cout &openopen;
+ ! (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2))
+ ! &openopen; std::endl;
+
+ ! // The arrays are automatically deallocated. <co id="tutorial-array_elementwise-doof2d-deallocation"></co>
+
+ ! // Tell the POOMA library execution finished. <co id="tutorial-array_elementwise-doof2d-pooma_finish"></co>
+ Pooma::finalize();
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Doof2d-Array-parallel-annotated.patch
===================================================================
RCS file: Doof2d-Array-parallel-annotated.patch
diff -N Doof2d-Array-parallel-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-Array-parallel-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,128 ----
+ *** Doof2d-Array-parallel.cpp Wed Jan 23 19:18:32 2002
+ --- Doof2d-Array-parallel-annotated.cpp Mon Jan 28 20:41:18 2002
+ ***************
+ *** 1,5 ****
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h" // has POOMA's Array declarations
+
+ // Doof2d: POOMA Arrays, data-parallel implementation
+ --- 1,7 ----
+ ! <programlisting id="tutorial-array_parallel-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h"
+ ! // has POOMA's Array declarations
+
+ // Doof2d: POOMA Arrays, data-parallel implementation
+ ***************
+ *** 12,43 ****
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout << "Please enter the number of averagings: ";
+ ! std::cin >> nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! std::cout << "Please enter the array size: ";
+ ! std::cin >> n;
+
+ // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<1> J(1,n-2);
+
+ // Create the arrays.
+ ! // The Array template parameters indicate 2 dimensions, a 'double' value
+ // type, and ordinary 'Brick' storage.
+ ! Array<2, double, Brick> a(vertDomain);
+ ! Array<2, double, Brick> b(vertDomain);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+ --- 14,50 ----
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout &openopen; "Please enter the number of averagings: ";
+ ! std::cin &closeclose; nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one
+ ! // dimension of the grid.
+ long n;
+ ! std::cout &openopen; "Please enter the array size: ";
+ ! std::cin &closeclose; n;
+
+ // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1)
+ ! // for computation. <co id="tutorial-array_parallel-doof2d-innerdomain"></co>
+ ! Interval<1> I(1,n-2);
+ ! Interval<1> J(1,n-2);
+
+ // Create the arrays.
+ ! // The Array template parameters indicate 2 dimensions,
+ ! // a 'double' value
+ // type, and ordinary 'Brick' storage.
+ ! Array<2, double, Brick> a(vertDomain);
+ ! Array<2, double, Brick> b(vertDomain);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes
+ ! // before accessing a value. <co id="tutorial-array_parallel-doof2d-blockAndEvaluate"></co>
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+ ***************
+ *** 47,52 ****
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a.
+ a(I,J) = weight *
+ (b(I+1,J+1) + b(I+1,J ) + b(I+1,J-1) +
+ --- 54,59 ----
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a. <co id="tutorial-array_parallel-doof2d-first_write"></co>
+ a(I,J) = weight *
+ (b(I+1,J+1) + b(I+1,J ) + b(I+1,J-1) +
+ ***************
+ *** 62,67 ****
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate(); // Ensure all computation has finished.
+ ! std::cout << (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2)) << std::endl;
+
+ // The arrays are automatically deallocated.
+ --- 69,77 ----
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate();
+ ! // Ensure all computation has finished.
+ ! std::cout &openopen;
+ ! (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2))
+ ! &openopen; std::endl;
+
+ // The arrays are automatically deallocated.
+ ***************
+ *** 71,72 ****
+ --- 81,83 ----
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Doof2d-Array-stencil-annotated.patch
===================================================================
RCS file: Doof2d-Array-stencil-annotated.patch
diff -N Doof2d-Array-stencil-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-Array-stencil-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,181 ----
+ *** Doof2d-Array-stencil.cpp Wed Jan 23 19:18:49 2002
+ --- Doof2d-Array-stencil-annotated.cpp Thu Jan 31 09:11:12 2002
+ ***************
+ *** 1,9 ****
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h" // has POOMA's Array declarations
+
+ // Doof2d: POOMA Arrays, stencil implementation
+
+ ! // Define the stencil class performing the computation.
+ class DoofNinePt
+ {
+ --- 1,11 ----
+ ! <programlisting id="tutorial-array_stencil-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Arrays.h"
+ ! // has POOMA's Array declarations
+
+ // Doof2d: POOMA Arrays, stencil implementation
+
+ ! // Define a stencil class performing computation. <co id="tutorial-array_stencil-doof2d-stencil"></co>
+ class DoofNinePt
+ {
+ ***************
+ *** 12,30 ****
+ DoofNinePt() : weight(1.0/9.0) {}
+
+ ! // This stencil operator is applied to each interior domain position
+ ! // (i,j). The "C" template parameter permits use of this stencil
+ ! // operator with both Arrays and Fields.
+ ! template <class C>
+ inline
+ typename C::Element_t
+ ! operator()(const C& c, int i, int j) const
+ ! {
+ ! return ( weight *
+ ! ( c.read(i+1,j+1) + c.read(i+1,j ) + c.read(i+1,j-1) +
+ ! c.read(i ,j+1) + c.read(i ,j ) + c.read(i ,j-1) +
+ ! c.read(i-1,j+1) + c.read(i-1,j ) + c.read(i-1,j-1) ) );
+ }
+
+ ! inline int lowerExtent(int) const { return 1; }
+ inline int upperExtent(int) const { return 1; }
+
+ --- 14,33 ----
+ DoofNinePt() : weight(1.0/9.0) {}
+
+ ! // This stencil operator is applied to each
+ ! // interior domain position (i,j). The "C"
+ ! // template parameter permits use of this
+ ! // stencil operator with both Arrays & Fields. <co id="tutorial-array_stencil-doof2d-stencil_operator"></co>
+ ! template <class C>
+ inline
+ typename C::Element_t
+ ! operator()(const C& c, int i, int j) const {
+ ! return
+ ! weight *
+ ! (c.read(i+1,j+1)+c.read(i+1,j)+c.read(i+1,j-1)+
+ ! c.read(i ,j+1)+c.read(i ,j)+c.read(i ,j-1)+
+ ! c.read(i-1,j+1)+c.read(i-1,j)+c.read(i-1,j-1));
+ }
+
+ ! inline int lowerExtent(int) const { return 1; } <co id="tutorial-array_stencil-doof2d-stencil_extent"></co>
+ inline int upperExtent(int) const { return 1; }
+
+ ***************
+ *** 42,82 ****
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout << "Please enter the number of averagings: ";
+ ! std::cin >> nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! std::cout << "Please enter the array size: ";
+ ! std::cin >> n;
+
+ // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<2> interiorDomain(I,I);
+
+ // Create the arrays.
+ ! // The Array template parameters indicate 2 dimensions, a 'double' value
+ // type, and ordinary 'Brick' storage.
+ ! Array<2, double, Brick> a(vertDomain);
+ ! Array<2, double, Brick> b(vertDomain);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+
+ ! // Create the stencil performing the computation.
+ ! Stencil<DoofNinePt> stencil;
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a.
+ a(interiorDomain) = stencil(b, interiorDomain);
+
+ --- 45,90 ----
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout &openopen; "Please enter the number of averagings: ";
+ ! std::cin &closeclose; nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one
+ ! // dimension of the grid.
+ long n;
+ ! std::cout &openopen; "Please enter the array size: ";
+ ! std::cin &closeclose; n;
+
+ // Specify the arrays' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for
+ ! // computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<2> interiorDomain(I,I);
+
+ // Create the arrays.
+ ! // The Array template parameters indicate
+ ! // 2 dimensions, a 'double' value
+ // type, and ordinary 'Brick' storage.
+ ! Array<2, double, Brick> a(vertDomain);
+ ! Array<2, double, Brick> b(vertDomain);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes
+ ! // before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+
+ ! // Create a stencil performing the computation. <co id="tutorial-array_stencil-doof2d-stencil_creation"></co>
+ ! Stencil<DoofNinePt> stencil;
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a. <co id="tutorial-array_stencil-doof2d-first_write"></co>
+ a(interiorDomain) = stencil(b, interiorDomain);
+
+ ***************
+ *** 86,91 ****
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate(); // Ensure all computation has finished.
+ ! std::cout << (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2)) << std::endl;
+
+ // The arrays are automatically deallocated.
+ --- 94,102 ----
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate();
+ ! // Ensure all computation has finished.
+ ! std::cout &openopen;
+ ! (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2))
+ ! &openopen; std::endl;
+
+ // The arrays are automatically deallocated.
+ ***************
+ *** 95,96 ****
+ --- 106,108 ----
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Doof2d-C-element-annotated.patch
===================================================================
RCS file: Doof2d-C-element-annotated.patch
diff -N Doof2d-C-element-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-C-element-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,154 ----
+ *** Doof2d-C-element.cpp Thu Jan 31 08:46:50 2002
+ --- Doof2d-C-element-annotated.cpp Thu Jan 31 08:47:14 2002
+ ***************
+ *** 1,4 ****
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+
+ // Doof2d: C-like, element-wise implementation
+ --- 1,5 ----
+ ! <programlisting id="tutorial-hand_coded-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+
+ // Doof2d: C-like, element-wise implementation
+ ***************
+ *** 6,30 ****
+ int main()
+ {
+ ! // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout << "Please enter the number of averagings: ";
+ ! std::cin >> nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Use two-dimensional grids of values.
+ double **a;
+ double **b;
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! std::cout << "Please enter the array size: ";
+ ! std::cin >> n;
+
+ ! // Allocate the arrays.
+ typedef double* doublePtr;
+ a = new doublePtr[n];
+ b = new doublePtr[n];
+ ! for (int i = 0; i < n; i++) {
+ a[i] = new double[n];
+ b[i] = new double[n];
+ --- 7,32 ----
+ int main()
+ {
+ ! // Ask the user for the number of averagings. <co id="tutorial-hand_coded-doof2d-nuaveragings"></co>
+ long nuAveragings, nuIterations;
+ ! std::cout &openopen; "Please enter the number of averagings: ";
+ ! std::cin &closeclose; nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Use two-dimensional grids of values. <co id="tutorial-hand_coded-doof2d-array_storage"></co>
+ double **a;
+ double **b;
+
+ ! // Ask the user for the number n of values along one
+ ! // dimension of the grid. <co id="tutorial-hand_coded-doof2d-grid_size"></co>
+ long n;
+ ! std::cout &openopen; "Please enter the array size: ";
+ ! std::cin &closeclose; n;
+
+ ! // Allocate the arrays. <co id="tutorial-hand_coded-doof2d-allocation"></co>
+ typedef double* doublePtr;
+ a = new doublePtr[n];
+ b = new doublePtr[n];
+ ! for (int i = 0; i < n; i++) {
+ a[i] = new double[n];
+ b[i] = new double[n];
+ ***************
+ *** 32,49 ****
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ ! for (int j = 0; j < n; j++)
+ ! for (int i = 0; i < n; i++)
+ a[i][j] = b[i][j] = 0.0;
+ b[n/2][n/2] = 1000.0;
+
+ ! // Average using this weight.
+ const double weight = 1.0/9.0;
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a.
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ a[i][j] = weight *
+ (b[i+1][j+1] + b[i+1][j ] + b[i+1][j-1] +
+ --- 34,52 ----
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value. <co id="tutorial-hand_coded-doof2d-initialization"></co>
+ ! for (int j = 0; j < n; j++)
+ ! for (int i = 0; i < n; i++)
+ a[i][j] = b[i][j] = 0.0;
+ b[n/2][n/2] = 1000.0;
+
+ ! // Average using this weight. <co id="tutorial-hand_coded-doof2d-constants"></co>
+ const double weight = 1.0/9.0;
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a. <co id="tutorial-hand_coded-doof2d-first_write"></co>
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ a[i][j] = weight *
+ (b[i+1][j+1] + b[i+1][j ] + b[i+1][j-1] +
+ ***************
+ *** 51,57 ****
+ b[i-1][j+1] + b[i-1][j ] + b[i-1][j-1]);
+
+ ! // Read from a. Write to b.
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ b[i][j] = weight *
+ (a[i+1][j+1] + a[i+1][j ] + a[i+1][j-1] +
+ --- 54,60 ----
+ b[i-1][j+1] + b[i-1][j ] + b[i-1][j-1]);
+
+ ! // Read from a. Write to b. <co id="tutorial-hand_coded-doof2d-second_write"></co>
+ ! for (int j = 1; j < n-1; j++)
+ ! for (int i = 1; i < n-1; i++)
+ b[i][j] = weight *
+ (a[i+1][j+1] + a[i+1][j ] + a[i+1][j-1] +
+ ***************
+ *** 60,68 ****
+ }
+
+ ! // Print out the final central value.
+ ! std::cout << (nuAveragings % 2 ? a[n/2][n/2] : b[n/2][n/2]) << std::endl;
+
+ ! // Deallocate the arrays.
+ ! for (int i = 0; i < n; i++) {
+ delete [] a[i];
+ delete [] b[i];
+ --- 63,73 ----
+ }
+
+ ! // Print out the final central value. <co id="tutorial-hand_coded-doof2d-answer"></co>
+ ! std::cout &openopen;
+ ! (nuAveragings % 2 ? a[n/2][n/2] : b[n/2][n/2])
+ ! &openopen; std::endl;
+
+ ! // Deallocate the arrays. <co id="tutorial-hand_coded-doof2d-deallocation"></co>
+ ! for (int i = 0; i < n; i++) {
+ delete [] a[i];
+ delete [] b[i];
+ ***************
+ *** 73,74 ****
+ --- 78,80 ----
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Doof2d-Field-distributed-annotated.patch
===================================================================
RCS file: Doof2d-Field-distributed-annotated.patch
diff -N Doof2d-Field-distributed-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-Field-distributed-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,219 ----
+ *** Doof2d-Field-distributed.cpp Wed Jan 23 19:20:15 2002
+ --- Doof2d-Field-distributed-annotated.cpp Wed Jan 30 16:40:27 2002
+ ***************
+ *** 1,6 ****
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Fields.h" // has POOMA's Field declarations
+
+ ! // Doof2d: POOMA Fields, data-parallel, multiple processor implementation
+
+ int main(int argc, char *argv[])
+ --- 1,9 ----
+ ! <programlisting id="tutorial-field_distributed-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Fields.h"
+ ! // has POOMA's Field declarations
+
+ ! // Doof2d: POOMA Fields, data-parallel, multiple
+ ! // processor implementation
+
+ int main(int argc, char *argv[])
+ ***************
+ *** 9,16 ****
+ Pooma::initialize(argc,argv);
+
+ ! // Since multiple copies of this program may simultaneously run, we
+ ! // canot use standard input and output. Instead we use command-line
+ ! // arguments, which are replicated, for input, and we use an Inform
+ ! // stream for output.
+ Inform output;
+
+ --- 12,20 ----
+ Pooma::initialize(argc,argv);
+
+ ! // Since multiple copies of this program may
+ ! // simultaneously run, we canot use standard input
+ ! // and output. Instead we use command-line
+ ! // arguments, which are replicated, for input, and we
+ ! // use an Inform stream for output. <co id="tutorial-field_distributed-doof2d-io"></co>
+ Inform output;
+
+ ***************
+ *** 18,22 ****
+ if (argc != 4) {
+ // Incorrect number of command-line arguments.
+ ! output << argv[0] << ": number-of-processors number-of-averagings number-of-values" << std::endl;
+ return EXIT_FAILURE;
+ }
+ --- 22,29 ----
+ if (argc != 4) {
+ // Incorrect number of command-line arguments.
+ ! output &openopen; argv[0] &openopen;
+ ! ": number-of-processors number-of-averagings"
+ ! &openopen; " number-of-values"
+ ! &openopen; std::endl;
+ return EXIT_FAILURE;
+ }
+ ***************
+ *** 25,79 ****
+ // Determine the number of processors.
+ long nuProcessors;
+ ! nuProcessors = strtol(argv[1], &tail, 0);
+
+ // Determine the number of averagings.
+ long nuAveragings, nuIterations;
+ ! nuAveragings = strtol(argv[2], &tail, 0);
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! n = strtol(argv[3], &tail, 0);
+ ! // The dimension must be a multiple of the number of processors
+ ! // since we are using a UniformGridLayout.
+ n = ((n+nuProcessors-1) / nuProcessors) * nuProcessors;
+
+ // Specify the fields' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<1> J(1,n-2);
+ !
+ ! // Partition the fields' domains uniformly, i.e., each patch has the
+ ! // same size. The first parameter tells how many patches for each
+ ! // dimension. Guard layers optimize communication between patches.
+ ! // Internal guards surround each patch. External guards surround
+ ! // the entire field domain.
+ ! UniformGridPartition<2> partition(Loc<2>(nuProcessors, nuProcessors),
+ ! GuardLayers<2>(1), // internal
+ ! GuardLayers<2>(0)); // external
+ ! UniformGridLayout<2> layout(vertDomain, partition, DistributedTag());
+ !
+ ! // Specify the fields' mesh, i.e., its spatial extent, and its
+ ! // centering type.
+ ! UniformRectilinearMesh<2> mesh(layout, Vector<2>(0.0), Vector<2>(1.0, 1.0));
+ ! Centering<2> cell = canonicalCentering<2>(CellType, Continuous, AllDim);
+ !
+ ! // The Field template parameters indicate a mesh and a 'double'
+ ! // value type. MultiPatch indicates multiple computation patches,
+ ! // i.e., distributed computation. The UniformTag indicates the
+ ! // patches should have the same size. Each patch has Brick type.
+ ! Field<UniformRectilinearMesh<2>, double, MultiPatch<UniformTag,
+ ! Remote<Brick> > > a(cell, layout, mesh);
+ ! Field<UniformRectilinearMesh<2>, double, MultiPatch<UniformTag,
+ ! Remote<Brick> > > b(cell, layout, mesh);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+ --- 32,99 ----
+ // Determine the number of processors.
+ long nuProcessors;
+ ! nuProcessors = strtol(argv[1], &tail, 0);
+
+ // Determine the number of averagings.
+ long nuAveragings, nuIterations;
+ ! nuAveragings = strtol(argv[2], &tail, 0);
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along
+ ! // one dimension of the grid.
+ long n;
+ ! n = strtol(argv[3], &tail, 0);
+ ! // The dimension must be a multiple of the number of
+ ! // processors since we are using a UniformGridLayout.
+ n = ((n+nuProcessors-1) / nuProcessors) * nuProcessors;
+
+ // Specify the fields' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for
+ ! // computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<1> J(1,n-2);
+ !
+ ! // Partition the fields' domains uniformly, i.e.,
+ ! // each patch has the same size. The first parameter
+ ! // tells how many patches for each dimension. Guard
+ ! // layers optimize communication between patches.
+ ! // Internal guards surround each patch. External
+ ! // guards surround the entire field domain. <co id="tutorial-field_distributed-doof2d-layout"></co>
+ ! UniformGridPartition<2>
+ ! partition(Loc<2>(nuProcessors, nuProcessors),
+ ! GuardLayers<2>(1), // internal
+ ! GuardLayers<2>(0)); // external
+ ! UniformGridLayout<2>
+ ! layout(vertDomain, partition, DistributedTag());
+ !
+ ! // Specify the fields' mesh, i.e., its spatial
+ ! // extent, and its centering type. <co id="tutorial-field_distributed-doof2d-mesh"></co>
+ ! UniformRectilinearMesh<2>
+ ! mesh(layout, Vector<2>(0.0), Vector<2>(1.0, 1.0));
+ ! Centering<2> cell =
+ ! canonicalCentering<2>(CellType, Continuous, AllDim);
+ !
+ ! // The Field template parameters indicate a mesh and
+ ! // a 'double' value type. MultiPatch indicates
+ ! // multiple computation patches, i.e., distributed
+ ! // computation. The UniformTag indicates the patches
+ ! // should have the same size. Each patch has Brick
+ ! // type. <co id="tutorial-field_distributed-doof2d-remote"></co>
+ ! Field<UniformRectilinearMesh<2>, double,
+ ! MultiPatch<UniformTag, Remote<Brick&closecloseclose;
+ ! a(cell, layout, mesh);
+ ! Field<UniformRectilinearMesh<2>, double,
+ ! MultiPatch<UniformTag, Remote<Brick&closecloseclose;
+ ! b(cell, layout, mesh);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes
+ ! // before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+ ***************
+ *** 83,87 ****
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ // Read from b. Write to a.
+ a(I,J) = weight *
+ --- 103,107 ----
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ // Read from b. Write to a.
+ a(I,J) = weight *
+ ***************
+ *** 98,103 ****
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate(); // Ensure all computation has finished.
+ ! output << (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2)) << std::endl;
+
+ // The fields are automatically deallocated.
+ --- 118,126 ----
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate();
+ ! // Ensure all computation has finished.
+ ! output &openopen;
+ ! (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2))
+ ! &openopen; std::endl;
+
+ // The fields are automatically deallocated.
+ ***************
+ *** 107,108 ****
+ --- 130,132 ----
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Doof2d-Field-parallel-annotated.patch
===================================================================
RCS file: Doof2d-Field-parallel-annotated.patch
diff -N Doof2d-Field-parallel-annotated.patch
*** /dev/null Fri Mar 23 21:37:44 2001
--- Doof2d-Field-parallel-annotated.patch Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,144 ----
+ *** Doof2d-Field-parallel.cpp Wed Jan 23 19:20:33 2002
+ --- Doof2d-Field-parallel-annotated.cpp Thu Jan 31 09:07:32 2002
+ ***************
+ *** 1,5 ****
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Fields.h" // has POOMA's Field declarations
+
+ // Doof2d: POOMA Fields, data-parallel implementation
+ --- 1,7 ----
+ ! <programlisting id="tutorial-field_parallel-doof2d-program" linenumbering="numbered" format="linespecific">
+ ! #include <iostream> // has std::cout, ...
+ ! #include <stdlib.h> // has EXIT_SUCCESS
+ ! #include "Pooma/Fields.h"
+ ! // has POOMA's Field declarations <co id="tutorial-field_parallel-doof2d-header"></co>
+
+ // Doof2d: POOMA Fields, data-parallel implementation
+ ***************
+ *** 12,49 ****
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout << "Please enter the number of averagings: ";
+ ! std::cin >> nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2; // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along one dimension of
+ ! // the grid.
+ long n;
+ ! std::cout << "Please enter the field size: ";
+ ! std::cin >> n;
+
+ // Specify the fields' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<1> J(1,n-2);
+ !
+ ! // Specify the fields' mesh, i.e., its spatial extent, and its
+ ! // centering type.
+ ! DomainLayout<2> layout(vertDomain);
+ ! UniformRectilinearMesh<2> mesh(layout, Vector<2>(0.0), Vector<2>(1.0, 1.0));
+ ! Centering<2> cell = canonicalCentering<2>(CellType, Continuous, AllDim);
+
+ // Create the fields.
+ ! // The Field template parameters indicate a mesh, a 'double' value
+ ! // type, and ordinary 'Brick' storage.
+ ! Field<UniformRectilinearMesh<2>, double, Brick> a(cell, layout, mesh);
+ ! Field<UniformRectilinearMesh<2>, double, Brick> b(cell, layout, mesh);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+ --- 14,60 ----
+ // Ask the user for the number of averagings.
+ long nuAveragings, nuIterations;
+ ! std::cout&openopen;"Please enter the number of averagings: ";
+ ! std::cin &closeclose; nuAveragings;
+ ! nuIterations = (nuAveragings+1)/2;
+ ! // Each iteration performs two averagings.
+
+ ! // Ask the user for the number n of values along
+ ! // one dimension of the grid.
+ long n;
+ ! std::cout &openopen; "Please enter the field size: ";
+ ! std::cin &closeclose; n;
+
+ // Specify the fields' domains [0,n) x [0,n).
+ ! Interval<1> N(0, n-1);
+ ! Interval<2> vertDomain(N, N);
+
+ ! // Set up interior domains [1,n-1) x [1,n-1) for
+ ! // computation.
+ ! Interval<1> I(1,n-2);
+ ! Interval<1> J(1,n-2);
+ !
+ ! // Specify the fields' mesh, i.e., its spatial
+ ! // extent, and its centering type. <co id="tutorial-field_parallel-doof2d-mesh"></co>
+ ! DomainLayout<2> layout(vertDomain);
+ ! UniformRectilinearMesh<2>
+ ! mesh(layout, Vector<2>(0.0), Vector<2>(1.0, 1.0));
+ ! Centering<2> cell =
+ ! canonicalCentering<2>(CellType, Continuous, AllDim);
+
+ // Create the fields.
+ ! // The Field template parameters indicate a mesh, a
+ ! // 'double' value type, and ordinary 'Brick'
+ ! // storage. <co id="tutorial-field_parallel-doof2d-field_creation"></co>
+ ! Field<UniformRectilinearMesh<2>, double, Brick>
+ ! a(cell, layout, mesh);
+ ! Field<UniformRectilinearMesh<2>, double, Brick>
+ ! b(cell, layout, mesh);
+
+ // Set up the initial conditions.
+ ! // All grid values should be zero except for the
+ ! // central value.
+ a = b = 0.0;
+ ! // Ensure all data-parallel computation finishes
+ ! // before accessing a value.
+ Pooma::blockAndEvaluate();
+ b(n/2,n/2) = 1000.0;
+ ***************
+ *** 53,58 ****
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a.
+ a(I,J) = weight *
+ (b(I+1,J+1) + b(I+1,J ) + b(I+1,J-1) +
+ --- 64,69 ----
+
+ // Perform the simulation.
+ ! for (int k = 0; k < nuIterations; ++k) {
+ ! // Read from b. Write to a. <co id="tutorial-field_parallel-doof2d-first_write"></co>
+ a(I,J) = weight *
+ (b(I+1,J+1) + b(I+1,J ) + b(I+1,J-1) +
+ ***************
+ *** 68,73 ****
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate(); // Ensure all computation has finished.
+ ! std::cout << (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2)) << std::endl;
+
+ // The fields are automatically deallocated.
+ --- 79,87 ----
+
+ // Print out the final central value.
+ ! Pooma::blockAndEvaluate();
+ ! // Ensure all computation has finished.
+ ! std::cout &openopen;
+ ! (nuAveragings % 2 ? a(n/2,n/2) : b(n/2,n/2))
+ ! &openopen; std::endl;
+
+ // The fields are automatically deallocated.
+ ***************
+ *** 77,78 ****
+ --- 91,93 ----
+ return EXIT_SUCCESS;
+ }
+ + </programlisting>
Index: Makefile
===================================================================
RCS file: Makefile
diff -N Makefile
*** /dev/null Fri Mar 23 21:37:44 2001
--- Makefile Thu Jan 31 15:14:50 2002
***************
*** 0 ****
--- 1,16 ----
+ ### Oldham, Jeffrey D.
+ ### 2001Nov27
+ ### Pooma
+ ###
+ ### Produce Annotated Source Code for the POOMA Manual
+
+ ## These rules combine executable code, which can be compiled and run,
+ ## with DocBook annotations used in the manual to explain the code.
+
+ all: Doof2d-C-element-annotated.cpp Doof2d-Array-element-annotated.cpp \
+ Doof2d-Array-parallel-annotated.cpp Doof2d-Array-stencil-annotated.cpp \
+ Doof2d-Array-distributed-annotated.cpp \
+ Doof2d-Field-parallel-annotated.cpp Doof2d-Field-distributed-annotated.cpp
+
+ %-annotated.cpp: %-annotated.patch %.cpp
+ patch -o $@ < $<
More information about the pooma-dev
mailing list