#include
"Gravitational N-Body Problem" task.
Parallel implementation.
---------------------------------------
---------------------------------------
---------------------------------------
#include
#include
#include
#include
#include "mpi.h"
int len,pid,pnr;
int ln,rn,un,dn;
MPI_Status status;
int AnzahlKoerper=3;
int KR=2;
const double G=2.959122083e-04;
double AlleR[100000][3]; //body's koordinats
double AlleV[100000][3]; //velocity
double AlleA[100000][3];
double Massen[100000];
double T,dt;
int driver,mode;
FILE *super_file;
void Linearebewegung(double *R, double *V, double *A, double dt, double *R1, double *V1);
double SQR(double x);
void A_Berechen();
void Integrationsschritt(double dt);
void initialisierung();
void Zeichne();
float supertime[4] = {0,0,0,0};
void Linearebewegung(double *R, double *V, double *A, double dt, double *R1, double *V1)
{
int i;
if ((pid>0)&&(pid<=pnr))
for (i=0; i<3; i++)
{
R1[i]=R[i] + V[i]*dt + 0.5*dt*dt*A[i];
V1[i]=V[i] + A[i]*dt;
}
}
double SQR(double x)
{
return x*x;
}
void A_Berechen()
{
int i,k,kk,kkk,j;
double d;
double Massen_new;
double AlleR_new[3];
double s_buffer[500000];
double r_buffer[500000];
float time;
for (i=0;i= 1390) AlleV[k][0] = -AlleV[k][0];
if (y >= 990) AlleV[k][1] = -AlleV[k][1];
if (x <= 10) AlleV[k][0] = -AlleV[k][0];
if (y <= 10) AlleV[k][1] = -AlleV[k][1];
send_buffer[i]=x;
i++;
send_buffer[i]=y;
i++;
}
MPI_Gather(send_buffer, KR*2, MPI_INT, buffer_xy, KR*2, MPI_INT, 0, MPI_COMM_WORLD);
if (pid==0)
for (i=KR*2 ; i <= (AnzahlKoerper+1)*2 ; i+=2)
putpixel(buffer_xy[i],buffer_xy[i+1]);
}
int main(int argc, char **argv)
{
int i=0,j=1;
float time;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&pnr);
MPI_Comm_rank(MPI_COMM_WORLD,&pid);
initialisierung();
// MPI_Barrier(MPI_COMM_WORLD);
// if (pid == 0) time = MPI_Wtime();
for ( i=0;i