# Multicore physics

## Multicore physics

Hi all,

I'm invited to give a lecture in a Scat workshop http://www.scat.bristol.ac.uk/meetings_and_events/meet9/ in multicore programing for physics.

I pretend to use almost all of the first three presentation from "Introduction to Parallel Programming" as an introduction. After that, I want to make a lab session with a system of uncoupled harmonic oscillators integrated using Verlet and where one want to measure the total kinetic energy and center of mass of the system. My idea is that the attendant be able to identify and code with OpenMP the places where parallelization is feasible.

The public of this lectures are scientist, grad and undergrad physics students with background in numerical simulation and maybe MPI.

I'll post here my code for the harmonic oscillators asap, and would like some feedback from you. Maybe there are better case studies than that, I don't know. But the idea is to show something familiar to physicist, something I don't have seen here.

So, if you have any comments, or want to help me to make a courseware for physicist I'd be glad.

Sebastian

tsuresuregusa [at] gmail

4 posts / 0 new
For more complete information about compiler optimizations, see our Optimization Notice.

Sebastian -

Your lab session example (the "harmonicoscillator" and"kinetic energy" thing-a-mabob)certainly is a mouthful.Since I'm not a physicist, I can't comment directly on the appropriateness of your proposed example. However, in the years I've been doing workshops and teaching classes, I've found that you want to make sure your source code or example problem is small enough to be easily understood by your audience without much explanation. For this reason, we (Intel Software College) have traditionally used small "toy" problems like finding prime numbers by brute force or the midpoint-rectangle-rule numerical integration to approximate pi. When I was teaching Fortran programming during my first academic stint, I took a simple distance computation in 2-D and spun it into an application that could sort pairs of a number of cities by distance (using longitude and latitude for an approximation of 2-D coordinates). This was done over the course of the quarter and each new feature of the language was the impetus to add a new feature to the application example.

On their own, these aren't all that exciting, but we're not trying to teach an exciting application.We're trying to teach a new programming concept (i.e., parallel programming). Thus, we don't want to confuse our students or waste their time with an overly complex example. If you can explain the main computational kernel of the application in 1-2 slides and a 1 minute code inspection will give students all they need to know about the application, that is the right size for an in-lecture lab.It will depend upon how much time you have for the students to work on the application, too. If they've got an hour, a more complex example could be used.

The best example is to use the student's own code. Before I joined Intel, we would put on "Bring Your Own Code" workshops. We would spend 2-3 days teaching some parallel programming and parallel tools topics.Then take another day or so to work with the students on their own applications to apply the lessons we were trying to impart. Parallelizing their code was the ultimate goal of the course and this should be a code the students were intimately familiar with. Doing BYOC takes some dedicated time by the lecturer to put together, and I suspect that this would be out of the question for your SCAT workshop and the time you have.

I guess I just wanted you to be sure that the time you do have for your workshop is sufficient for the complexity of the application you are hoping to use for practice by the participants.

Good luck.

--clay

P.S.I thought you were going to be giving your lecture in the UK since this is where the URL pointed.I see that this is a Latin America based meeting to be held in Chile.

I have 3 sessions of 60 to 90 minutes, it depends in how much I want to show.

I'm thinking in use the harmonic badabu in the third day. The code is attached, are 80 lines (less than a matrix multiplication) and I need to add a little more yet. (don't look at this page http://en.wikipedia.org/wiki/Caldeira-Leggett_model unless you try to understand it) I assume that the participants are used to verlet algorithm and stuff like that.

So, do you think that in 200 minutes I can see something like this?

The idea of BYOC is really good, I'm going to see if I can do it here.

thanks,

p.s. if anyone want to come to chile, you're welcome :)

p.p.s: The server is down, so I'll past the code here :S

#include

#include

#include

#include

#include

#define TOLERANCE (1e-10)

#define SQR(x) ((x)*(x))

#define N 1000

double h;

double X,V;

double x[N],v[N],c[N],m[N],k[N];

//The total force in the particle i:

// k_i is the harmonic term, and c_i is the coupling

double Force(double x_i,double k_i, double c_i,double x )

{

return -k_i*x_i - c_i*x;

}

//integrate the small particles using velocity verlet

void integrate(double x_i, double v_i,double c_i,double k_i,double h, double x)

{

double f = Force(x_i,k_i,c_i,x);

x_i += (v_i + 0.5*f*h)*h;

double a = Force(x_i,k_i,c_i,x);

v_i += 0.5*(a+f)*h;

}

int main(int argc, char **argv)

{

int j,i;

double h=0.001,t;

double a,f,sum,sum2,aux;

double K=1.0,Keff=0.0;

//Thermal bath initial state

#pragma omp parallel for private(i)

for(i=0;i x[i] = 0.5 - drand48();

v[i] = 0.5 - drand48();

c[i] = 2.0 + drand48();

m[i] = 1.0;

k[i] = 1.0 + drand48();

}

//Big oscillator initial conditions

X = 10.0;

V = 1.0;

i = 0;

//Effective Force

for(j=0;j Keff += SQR(c[j])/k[j];

for(t=0;t sum = sum2 = 0;

//We nedd the coupling at step n

#pragma omp parallel for reduction(+:sum) private(j)

for(j=0;j sum += c[j]*x[j];

f = -(K + Keff)*X - sum;

X += (V + 0.5*f*h)*h;

#pragma omp parallel for private(j)

for(j=0;j integrate(x[j],v[j],c[j],k[j],h,X);

}

//We nedd the coupling at step n+1

#pragma omp parallel for reduction(+:sum2) private(j)

for(j=0;j sum2 += c[j]*x[j];

a = -(K + Keff)*X - sum2;

V += (f + a)*0.5*h;

if(i++%1000==0)

printf("%lf %lf %lf
",t,X,V);

}

return 0;

}

Hi there,

Am an MSc student of the University of Ibadan,

I want to ask,how can we get a Multi core course in our department.

Thanks.