31
CS 294-73 Software Engineering for Scientific Computing Lecture 12

CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

CS 294-73 Software Engineering for

Scientific Computing

Lecture 12

Page 2: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Doolittle’s Method for LU Decomposition

2

A(1) =

0

BBB@

a11 a12 . . . a1N0 a(1)22 . . ....

. . .

0 a(1)N2 . . . a(1)NN

1

CCCA= L(1)A(0) , L(1) =

0

BBBB@

1 0 . . . 0�l121 1 . . . 0... 0

. . . 0

�l1N1 0. . . 1

1

CCCCA, l(1)n1 =

a(0)n1

a(0)11

A =

0

B@a11 a12 . . . a1N...

. . ....

aN1 aNN

1

CA = A(0)

A(n) = L(n)A(n�1) , L(n) =

0

BBBBBBBBB@

1 0 . . . 0

0. . .

. . . 01

... �l(n)n+1 n

......

. . .

0 �l(n)Nn 1

1

CCCCCCCCCA

, l(1)ni =a(n�1)ni

a(n�1)nn

l(n)kn =a(n�1)kn

a(n�1)nn

, k > n

Page 3: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Doolittle’s Method for LU Decomposition

3

(L(n))�1 =

0

BBBBBBBBB@

1 0 . . . 0

0. . .

. . . 01

... l(n)n+1 n

......

. . .

0 l(n)Nn 1

1

CCCCCCCCCA

U = A(N) = L(N) . . . L(1)A

A = LU = (L(1))�1 . . . (L(N))�1U

L =

0

BBBBBBBBB@

1 0 . . . 0

l(1)21

. . .. . . 01

... l(n)n+1 n

......

. . .

l(1)N1 l(n)Nn 1

1

CCCCCCCCCA

This continues to work if we replace aij by bxb blocks. Then etc.

an1a11

! an1a�111

Page 4: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Sparse Matrix Class

4

Represent matrix using unsigned int m_m, m_n;

double m_zero;

vector<vector<double> > m_data;

vector<vector<int> > m_colIndex;

m_data and m_colIndex are of length m_m; the ith element contains the description of the ith row the matrix with the zeros compressed out: Ai,m_colIndex[i][j] = m_data[i][j] if that entry is nonzero; otherwise the entry is assumed to be zero.

Page 5: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Sparse Matrix Class

5

unsigned int m_m, m_n; double m_zero; vector<vector<double> > m_data; vector<vector<int> > m_colIndex;

A[tuple] = ...(non-const indexing operator).If there is an entry for tuple[0],tuple[1], returns a reference to the correct element of m_data[tuple[0]]; If not, add a new element to m_data[tuple[0]] and m_colIndex[tuple[0]]Using push_back. In either case, you need to search through m_colIndex[tuple[0]] to see whether you have a nonzero in columm tuple[1].

Note that the columms are not sorted in any particular order. This is ok, because matrix multiplication is given by v[i] = \sum_q m_data[i][q] w[colIndex[i][q]]

Why might this be an acceptable strategy from a performance standpoint ?

Page 6: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Recursion

6

Long long factorial(int n){ if (n > 1)

{ return n*factorial(n-1);}else if (n == 1){return 1;}else{

... // error condition.}

};

Page 7: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

What is a function?

7

Set of instructions: •  Operations on POD. •  Control flow, including calls to other functions. •  Local variables. •  Input arguments. •  Return value. Old days: a single chunk of memory was allocated for a function that contained everything – instructions and local data. However, you can’t perform recursive calls to a function using such an approach – the local variables get overwritten. Solution: organize things so that the storage for local data is managed separately from the storage for the instructions.

Page 8: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Call Stack / Stack Frame

8

What happens when you call a function ? •  Jump to address of the function. •  Set up storage for local scope.

This is put on the call stack •  Values of the arguments. •  Storage for local variables. Size is known at compile time.

•  The reason this is a stack is that the corresponding values for the calling function are also stored there, ready to be used when the current function finishes and returns control to the calling function.

•  The reason recursion works is that each successive call generates a new stack frame.

Page 9: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Call Stack / Stack Frame

9

Enables inheritance: •  Jump to address of the function (fft1d*). •  Set up storage for local scope.

•  Values of the arguments (depends on the base calls definition) •  Storage for local variables (depends on the derived function, not

known to the calling function). Size is known at compile time.

Enables debugging tools •  At any given point in the program, the entire (POD) data state of the

program at that time is stored in the call stack. That includes the values of pointer variables so you can look at your memory-managed data. Traverse the calling stack using “up”, “down”.

•  The calling stack can be quite deep, particularly when using libraries.

Page 10: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

What about member functions of an object ?

10

void FFT::applyFFT(vector<complex<double> >& a_fhat, const vector<complex<double> >& a_f, int a_level)

{...applyFFT(fEven,fHatHalfEven,level-1);applyFFT(fOdd,fHatHalfOdd,level-1);...}•  applyFFT(...) <-> (*this).applyFFT(...)•  Calling a member function is the same as calling a function with this as an

additional argument (i.e. a pointer to the member data). •  Class = functions + C Struct ;

Page 11: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

FFTW: http://www.fftw.org/

11

•  Open-source tuned FFT. •  Based on split-radix formalism. with highly-optimized,

machine-generated codelets written in C to implement short FFTs with non-unit stride.

•  De-facto standard. •  Next-generation version based on CMU’s Spiral framework.

268 P. Duhamel, M. Vetterli / A tutorial on fast Fourier transforms

x 6 / x3 x( x 7 / x4 x 1 x 8

lx0x3x6xgX12 Xx9 Xl/,

x 4

- - Xl 0

Fig. 1. 2-D view of the length-15 Cooley-Tukey FFT.

o) N1 =3,N2=S I Xo Xl ............. X13 X1/., [

Xo X3 X6 X9 X12 X 1 X/., X 7 X10X13 X 2 X 5 X 8 Xll Xl/.,

b) Nl=5,N2 =3

X 0 X 5 Xl 0 X 1 X 6 Xll X 2 X7 X12

X 3 X 8 iX13 X/., X 9 'X14

Fig. 2. Cooley-Tukey mapping. (a) N t = 3, N 2 = 5; (b) N 1 = 5, N2=3.

has been chosen. Thus, in Fig. 2(a), one has to begin with the DFTs on the rows of the matrix. Choosing N1 = 5, N2 = 3 would lead to the matrix of Fig. 2(b), which is obviously different from just transposing the matrix of Fig. 2(a). This shows again that the mapping does not lead to a true two-dimensional transform (in that case, the order of row and column would not have any importance). Signal Processing

4.2. Radix-2 and radix-4 algorithms

The algorithms suited for lengths equal to powers of 2 (or 4) are quite popular since sequen- ces of such lengths are frequent in signal processing (they make full use of the addressing capabilities of computers or DSP systems).

We assume first that N = 2". Choosing N~ = 2 and N2 = 2 " -1= N / 2 in (9) and (10) divides the imput sequence into the sequence of even and odd numbered samples, which is the reason why this approach is called 'decimation in time' (DIT). Both sequences are decimated versions, with different phases, of the original sequence. Following (17), the output consists of N / 2 blocks of 2 values. Actually, in this simple case, it is easy to rewrite (14), (21) exhaustively:

N/2-1 w"2k2 Xk2= ~, X2n2 ,, N/2

n2=0

N/2--1 k2 wn2k2 (22a) Jr W N ~ X2n2+1 "" N/2'

.2=0

N/2--1 wn2k2 XN/2+k2 = ~ X2n2 - - N / 2

n2=0

N/2--1 k~ W "~k~ (22b) -- W N Y~ X2"2+I "" N/2"

n2=O

Thus, X,, and XN/E+m are obtained by 2-point DTFs on the outputs of the l eng th -N/2 DFTs of the even and odd-numbered sequences, one of which is weighted by twiddle factors. The structure

Page 12: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Using FFTW

12

FFTW uses an explicit mapping of the addresses in the inputs / outputs. The information is stored in “plans”, that are explicitly created / destroyed. Two modes: estimated tuning, and run-time tuning.

“include fftw3.h”fftw_plan forward,reverse;fftw_complex* in; fftw_complex* out;vector<complex<double> > vec_in(N), vec_out(N); in = reinterpret_cast<fftw_complex*>(&(vec_in[0]));out = reinterpret_cast<fftw_complex*>(&(vec_out[0]));

forward= fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);inverse= fftw_plan_dft_1d(N, in, out, FFTW_BACKWARD, FFTW_ESTIMATE); ...fftw_execute(forward);fftw_execute(reverse);...fftw_destroy_plan(forward);fftw_destroy_plan(reverse);

Page 13: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Looking at codelets

13

!  cd codelets!  ls!  n1_10.c n1_11.c n1_12.c n1_13.c n1_14.c ... !  t1_10.c t1_12.c t1_15.c t1_16.c t1_2.c t1_20.c t1_25.c …

Page 14: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Looking at codelets

14

n1_4.c

.../* * This function contains 16 FP additions, 0 FP multiplications, * (or, 16 additions, 0 multiplications, 0 fused multiply/add), * 13 stack variables, 0 constants, and 16 memory accesses */...

(5 n log2(n) = 40, 8*n2 = 128. About 100 LOC).

2

664

1 1 1 1◆ �1 �◆ 1�1 1 �1 1�◆ �1 ◆ 1

3

775

Page 15: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Looking at codelets

15

n1_8.c

.../* * This function contains 52 FP additions, 8 FP multiplications, * (or, 44 additions, 0 multiplications, 8 fused multiply/add), * 36 stack variables, 1 constants, and 32 memory accesses */...

(5 n log_2(n) = 120 , 8n2 = 512. About 200 LOC)

2

666666666664

1 1 1 1 1 1 1 1◆p2+

p2

2 ◆ ◆p2�

p2

2 �1 � ◆p2+

p2

2 �◆ � ◆p2�

p2

2 1◆ �1 �◆ 1 ◆ �1 �◆ 1

◆p2�

p2

2 �◆ ◆p2+

p2

2 �1 � ◆p2�

p2

2 ◆ � ◆p2+

p2

2 1�1 1 �1 1 �1 1 �1 1

� ◆p2+

p2

2 ◆ � ◆p2�

p2

2 �1 ◆p2+

p2

2 �◆ ◆p2�

p2

2 1�◆ �1 ◆ 1 �◆ �1 ◆ 1

� ◆p2�

p2

2 �◆ � ◆p2+

p2

2 �1 ◆p2�

p2

2 ◆ ◆p2+

p2

2 1

3

777777777775

(1)

Page 16: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Looking at codelets

16

n1_13.c

.../* * This function contains 176 FP additions, 114 FP multiplications, * (or, 62 additions, 0 multiplications, 114 fused multiply/add), * 87 stack variables, 25 constants, and 52 memory accesses */...

(5 n log2(n) = 241 , 8n2 = 1352. About 650 LOC.)

Page 17: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Looking at codelets

17

n1_64.c

.../* * This function contains 912 FP additions, 392 FP multiplications, * (or, 520 additions, 0 multiplications, 392 fused multiply/add), * 202 stack variables, 15 constants, and 256 memory accesses */...

(5 n log2(n) = 1920 , 8n2 = 32768. About 2950 LOC.)

Page 18: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Standard Template Library containers.

Predefined classes: aggregates that are templated on the type being held. Example of a namespace. The names of these classes are std::className.We use the command using namespace std; in global scope to tell compiler to look for functions of the form std::className. Some authorities view this as bad form. http://www.cplusplus.com/ NB: C++11 standard.

18

Page 19: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Various choices in container templates

Container templates in the STL -  C arrays as first-class objects (array),

-  dynamic arrays (vector),

-  queues (queue),

-  stacks (stack),

-  heaps (priority_queue),

-  linked lists (list),

-  trees (set),

-  associative arrays (map)

•  They are distinguished by the kinds of access they provide and the complexity of their operations.

•  To use these, you need to include the appropriate header file, e.g. #include <array>

19

Page 20: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

std::vector<T>

unsigned int size();

push_back(const T&);

pop_back(const T&);

T& back();

T& front();

operator[ ](int);

Vector<T>::iterator begin()•  Looks like a 1D array: can index any element by an integer less than size() . •  Can add, delete elements at the end of an array. •  Fast access: data stored in contiguous locations in memory (just as if you had used new. In fact, you can access the underlying contiguous storage as an ordinary 1D array. 20

Page 21: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

How do remove an element from a vector ? • Can do this at the end easily, but in general

-  find the element you wish to remove -  make a whole new vector 1 smaller than the original -  copy all but the excluded object to the new vector

• But we have already been doing something almost as awful with the push_back function of vector

-  grow vector length by one -  copy all elements to the new vector with length+=1 -  copy the new element on the end -  (in reality vector is doing a version of doubling it’s size when it runs of

of room and keeps track of it’s “real” size and it’s size() )

• Vectors are good at: -  Accessing individual elements by their position index (constant time). -  Iterating over the elements in any order (linear time). -  Add and remove elements from its end (constant amortized time).

21

Page 22: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

list<T> •  std::list provides the following features

-  Efficient insertion and removal of elements anywhere in the container (constant time).

-  Efficient moving elements and block of elements within the container or even between different containers (constant time).

-  Iterating over the elements in forward or reverse order (linear time).

•  What list is not good at is random access. -  ie. if you wanted to access the 35th entry in a list, you need to walk

down the linked list to the 35th entry and return it.

22

Page 23: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

list<T> unsigned int size();

push_back(const T&);

pop_back(const T&);

T& front();

T& back();

insert(list<T>::iterator ,const T&);

erase(list<T>::iterator );

list<T>::iterator begin(); But no indexing operator ! However, insertion / deletion is cheap once you find the location you want to insert or delete at.

23

Page 24: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Why list instead of vector ? •  erase, insert, splice, merge are O(1) complexity •  remove, unique are O(linear) complexity.

void removeBoundary(std::list<Node>& a_nodes, std::list<Node>& a_boundary)

{

std::list<Node>::iterator it;

for(it=a_nodes.begin(); it!=a_nodes.end(); ++it)

{

if(!it->isInterior())

{

a_boundary.splice(a_boundary.start(), a_nodes, it);

}

}

Executes in linear time, and Node is never copied.

24

Page 25: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

<map> : an associative container • Stores elements formed by the combination of a key

value and a mapped value.

• You index into a map with the key, you get back out the value.

-  You could consider vector a simple map where the key is an unsigned integer, and the value is the template class, but that imposes the constraint that they keys are the continuous interval [0,size-1]

-  but what if your keys don’t have this nice simple property ?

• map take two template arguments, one for the key, and one for the value

• The key class needs to implement the operator< -  Strict Weak Ordering

-  if a<b and b<c, then a<c -  if a<b then !(b<a) -  if !(a<b) and !(b<a) then a == b

25

Page 26: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Map<Key,T> unsigned int size();

insert(pair<Key,T>); insert(map<Key,T>::iterator ,const T&);

erase(map<Key,T>::iterator );erase(const Key K&);

T& front();T& back();

map<Key,T>::iterator begin();operator[](const Key K&);

26

Page 27: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

A simple dictionary object #include <map>

#include <string>

#include <iostream>

using namespace std;

void fillDictionary(map<string,string>& a_dictionary, const string& filename);

int main(int argc, char* argv[])

{

map<string, string> dictionary;

string key;

fillDictionary(dictionary, argv[1]);

while(true)

{

cout<<"query :";

cin>>key;

if(key.size()==0) return 0;

map<string,string>::iterator val = dictionary.find(key);

if(val==dictionary.end())

cout<<"\n did not find that word in the dictionary "<<endl;

else

cout<<"\n"<<val->second<<endl;

}

} 27

Page 28: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

parse a simple input file void fillDictionary(map<string,string>& a_dictionary, const string& filename)

{

ifstream f(filename.c_str()); string key, value; char buffer[2048];

bool next=true; char token[] =":";

while(f.getline(buffer,2048, token[0]))

{

if(next)

{

key = string(buffer); next = !next;

}

else

{

value = string(buffer); a_dictionary[key]=value; next=!next;

}

}

}

28

Access with operator[ ] keys are unique if not found, makes new entry

Page 29: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

std::unordered_map •  Same Interface as std::map, but this is a hash table •  Optimized for fast lookup

-  std::map is O(logN) insertion and lookup, std::unordered_map is O(logN) insertion and O(1) lookup (average).

•  Implementation generally uses more memory to speed up lookup (one or two levels of binning)

•  Relies on the concept of hashing -  Turn Key type into a size_t integer.

std::size_t h = std::hash<Bob>(myBob);

-  A good hash has few if any collisions -  A good container hash even density

•  Not a good choice if your access pattern is visiting every member

29

Page 30: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Hierarchical use of BoxDatamap<Point,int> m_getContents;int k = m_getContents[pt];

30

RectMDArray<bool> m_bitmap;

vector<list<Particle > > m_particles;vector<BoxData<T,N> > m_refGrids;

Page 31: CS 294-73 Software Engineering for Scientific Computing ...cs294-73/fa19/slides/Lecture11... · 10/3/2019 CS294-73 Lecture 11 What is a function? 7 Set of instructions: • Operations

10/3/2019 CS294-73 Lecture 11

Hierarchical use of BoxData/// Boolean-valued BoxData. Defines which Boxes are members of the domain.

BoxData<bool> m_bitmap;

/// Vector of Points each of which is associated with a data in the region defined by a Point: a refined patch of grid, a collection of particles.vector<T> m_stuff;

/// Maps Points to an index into m_stuff. map<Point, int > m_getPatches;

Why do we use this extra level of indirection? •  Indexing [.] creates a new entry if one is not there. •  We could get rid of m_bitmap by using map::find. (Warning: average cost smaller than worst-case).

Why don’t we store the elements of m_stuff directly in the map ? Answer: one copy of metadata for multiple data holders.

31