CS 294-73 Software Engineering For Scientific Computing Lecture 12: Particle Methods Homework 3
CS 294-73 Software Engineering For Scientific Computing Lecture 12: Particle Methods Homework 3
3
Cost of PP calculation: O(N )N = O(N 2 3 )
Issues:
• How to implement ?
• Approach: basic particle representation from PIC doesn’t change - only
force calculation does.
• What is the error ?
• This is only a question about the error in the PIC calculation - the
decomposition and the PP calculation are exact.
• Error analysis is tricky, since the number of particles is fixed.
F~ig = rg ( g )i
X g
F~P M,k = F~i (xk ihg )
i
What happens for many particles - some nearby, some farther away ?
X ⇣ hP ⌘
g
✏= qk O
max(|x xk |, )P +1
k
X ⇣ hP ⌘
2
= O P +1
q̄ (r )
r
(r )
⇣ hPP X R
1 ⌘ ⇣ ⇣ h ⌘P 2 ⌘
g 2 g
=O
= O PP 22 P
P 11
= O h g
r>0
r
r=1
q
✏ = O(C )
compile the 'naive' makefile target and execute and capture the output in a file named
'naive.out' which you check into the repo
2. change the compiler flags from the default '-g -Wall' flags to '-O3'. i.e., turn on compiler
optimization. build 'naive' again, and produce a 'naive_opt.out' output.
3. implement a version of this function in a file named dgemm-blas.cpp with a call to cblas
third party library. Build the 'blas' makefile target. run the code and create a 'blas.out'
output for your problem to submit.
#include “fftw3.h”
...
{
fftw_complex *in, *out;
fftw_plan p; ... in = (fftw_complex*)
fftw_malloc(sizeof(fftw_complex) * N);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE); ...
fftw_execute(p);
/* repeat as needed */ ...
fftw_destroy_plan(p);
fftw_free(in);
fftw_free(out);
}
• Need to go to the fftw site and install fftw on your own machine.
• You won’t use this approach from the FFTW document. fftw needs to have its own view of the data
– you will alias your own complex data to fftw’s data, as indicated in the last lecture.
In $(HOME)/GNUmakefile:
LIBS_LOCAL = $(HOME)/lib
LIB_FLAGS:= -L$(LIBS_LOCAL) -L$(FFTW_HOME)/lib -lfftw3 -lfft1D
What is libfft1D.a ?
• Collection of binaries (.o files), assembled into an archive (.a)
• Unix utilities for building archives: ar (Linux), libTool (Mac).
• You’ve already been accessing such archives (part of the compilation system).
- /usr/lib , /usr/local/lib
• Compiler / linker told where to look for them through -L , -l flags.
- -L<dir_name> : search this directory for .a files.
- -l<root> : look for library name of the form lib<root>.a
In hw3/GNUmakefile:
$(LIBS_LOCAL)/libfft1D.a:$(wildcard $(FFT_HOME)/*.{H,cpp} ) GNUmakefile
cd $(FFT_HOME);make clean;make libfft1D.a DIM=1 CXX=$(CXX)
if (fft_string == "Recursive")
{
// Uncomment and delete the abort when ready to test.
// shared_ptr<FFT1DRecursive> p_fft1dR
// =shared_ptr<FFT1DRecursive>(new FFT1DRecursive(M));
// p_fft = dynamic_pointer_cast<FFT1D >(p_fft1dR);
cout << "this one is for the students to do" << endl;
abort();
}
else if (fft_string == "BRI")
{
shared_ptr<FFT1DBRI> p_fft1dBRI =
shared_ptr<FFT1DBRI>(new FFT1DBRI(M));
p_fft = dynamic_pointer_cast<FFT1D >(p_fft1dBRI);
}
cout << "this one is for the students to do" << endl;
abort();
}
else
{cout << "invalid input - should use BRI, Recursive or FFTW as name
for FFT implementation to be tested" << endl;
abort();}
sscanf(argv[1],"%d",&M);
dynamic_pointer_cast<FFT1D >(shared_ptr<FFTW1D>(new FFTW1D(M)));
FFTMD fftmd(p_fft);
double error = test(fftmd,time);
cout << "test 1: error in Gaussian = " << error << endl;
cout << "time in FFTMD = " << time << " seconds" << endl;
};