Initial commit.
This commit is contained in:
Executable
+15
@@ -0,0 +1,15 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../test_jacobi
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/test_jacobi_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
extern spe_program_handle_t test_jacobi_spu;
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int t, rank, size, rl, mspu, aspu, err, stringl, nothr;
|
||||
char proc[4];
|
||||
|
||||
int n __attribute__((__aligned__(16)));
|
||||
int iterations __attribute__((__aligned__(16)));
|
||||
float omega __attribute__((__aligned__(16)));
|
||||
char string[255];
|
||||
|
||||
if (argc < 5)
|
||||
{
|
||||
printf("Usage: \"%s Matrix size Iterations Omega nothr\"\n", argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = atoi(argv[1]);
|
||||
iterations = atoi(argv[2]);
|
||||
omega = atof(argv[3]);
|
||||
nothr = atoi(argv[4]);
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// only use as many spus as specified
|
||||
aspu = nothr;
|
||||
for (t = 0; t < aspu; t++)
|
||||
MOC_Add_spu_thread(&test_jacobi_spu, NULL);
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name(proc, &rl);
|
||||
|
||||
// sending input and other runtime specific data to spes
|
||||
for (t = 0; t < aspu; t++)
|
||||
{
|
||||
err = MOC_Bsend(&n, sizeof(int), MOC_INT, t + 1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-bsend1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Bsend(&iterations, sizeof(int), MOC_INT, t + 1, 123,
|
||||
MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-bsend2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Bsend(&omega, sizeof(float), MOC_FLOAT, t + 1, 123,
|
||||
MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-bsend3: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
MOC_Finalize();
|
||||
return 0;
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := test_jacobi_spu
|
||||
LIBRARY_embed64 := test_jacobi_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/spu
|
||||
LDFLAGS = -L../../../../lib/spu
|
||||
IMPORTS = -lmoc_spu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+242
@@ -0,0 +1,242 @@
|
||||
#include <moc.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
double gettime(void)
|
||||
{
|
||||
struct timeval time;
|
||||
gettimeofday(&time, (void *) 0);
|
||||
return (double) (time.tv_sec) + (double) time.tv_usec * 1.0e-6;
|
||||
}
|
||||
|
||||
void jacobi(float f1mO, float fOd4, float **f, float **u, float **uhelp,
|
||||
int xn, int yn)
|
||||
{
|
||||
int i, j;
|
||||
for (i = 1; i < yn - 1; i++)
|
||||
{
|
||||
for (j = 1; j < xn - 1; j++)
|
||||
{
|
||||
uhelp[i][j] = f1mO * u[i][j] + fOd4 * (f[i][j] + u[i - 1][j] + u[i
|
||||
+ 1][j] + u[i][j - 1] + u[i][j + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int rank, size, rl, err, stringl;
|
||||
unsigned int off1;
|
||||
unsigned int i, j, n, xn, yn, iter, iterations, tag_id, matrix_size;
|
||||
float f1mO, fOd4, omega;
|
||||
float **f, **u, **uhelp, **utemp;
|
||||
double time;
|
||||
char string[255];
|
||||
|
||||
MOC_Status status;
|
||||
|
||||
char proc[4];
|
||||
|
||||
iter = 0;
|
||||
utemp = NULL;
|
||||
tag_id = 0;
|
||||
|
||||
MOC_Init(0, 0, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name(proc, &rl);
|
||||
|
||||
//recieve input and other runtime specific data from ppe
|
||||
err = MOC_Recv(&n, sizeof(int), MOC_INT, 0, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-initial-recv1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Recv(&iterations, sizeof(int), MOC_INT, 0, 123, MOC_COMM_WORLD,
|
||||
&status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-initial-recv2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Recv(&omega, sizeof(float), MOC_FLOAT, 0, 123, MOC_COMM_WORLD,
|
||||
&status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-initial-recv3: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//size also takes into account the ppe, not useful for calculations regarding the splitting of the workload
|
||||
size = size - 1;
|
||||
xn = n + 2;
|
||||
yn = (n / size) + 2;
|
||||
matrix_size = xn * sizeof(float);
|
||||
//constants have to be declared only once, not in every iteration
|
||||
f1mO = (1 - omega);
|
||||
fOd4 = omega * 0.25;
|
||||
|
||||
//help array for use in jacobi(...) is initialized here and apssed as argument. This is usefule for exchanging u and uhelp
|
||||
//and saves performance because of only initializing it once
|
||||
if ((f = (float**) malloc(yn * sizeof(float*))) == NULL)
|
||||
{
|
||||
printf("Error!! Array f not initialisable because: %s\n", strerror(
|
||||
errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((u = (float**) malloc(yn * sizeof(float*))) == NULL)
|
||||
{
|
||||
printf("Error!! Array u not initialisable because: %s\n", strerror(
|
||||
errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((uhelp = (float**) malloc(yn * sizeof(float*))) == NULL)
|
||||
{
|
||||
printf("Error!! Array uhelp not initialisable because: %s\n", strerror(
|
||||
errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for (i = 0; i < yn; i++)
|
||||
{
|
||||
if ((f[i] = (float*) malloc(sizeof(float) * xn)) == NULL)
|
||||
{
|
||||
printf("Error!! Array f[%d] not initialisable because: %s\n", i,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((u[i] = (float*) malloc(sizeof(float) * xn)) == NULL)
|
||||
{
|
||||
printf("Error!! Array u[%d] not initialisable because: %s\n", i,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((uhelp[i] = (float*) malloc(sizeof(float) * xn)) == NULL)
|
||||
{
|
||||
printf("Error!! Array uhelp[%d] not initialisable because: %s\n",
|
||||
i, strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//offset for calculation the position in the global array, as this determines the initialisation value
|
||||
if (rank - 1 == 0)
|
||||
off1 = i;
|
||||
else
|
||||
off1 = (i + (rank - 1) * (yn - 2));
|
||||
|
||||
for (j = 0; j < xn; j++)
|
||||
{
|
||||
f[i][j] = off1 * (off1 + 1) + j * (j + 1);
|
||||
if ((off1 == 0) || (off1 == n + 2 - 1) || (j == 0) || (j == xn - 1))
|
||||
{
|
||||
u[i][j] = f[i][j];
|
||||
uhelp[i][j] = f[i][j]; //uhelps margins have to be initialized as well because of altered exchange of u and uhelp
|
||||
}
|
||||
else
|
||||
u[i][j] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
time = gettime();
|
||||
for (iter = 0; iter < iterations; iter++)
|
||||
{
|
||||
|
||||
jacobi(f1mO, fOd4, f, u, uhelp, xn, yn);
|
||||
|
||||
//altered exchange algorithm. No backcopy, instead change pointers, far more efficient,
|
||||
//helps reducing overhead to get better speedup, only difference from original algorithm, margins in uhelp have to be initialized
|
||||
utemp = u;
|
||||
u = uhelp;
|
||||
uhelp = utemp;
|
||||
|
||||
if (iter < iterations - 1)
|
||||
{
|
||||
if (rank > 1)
|
||||
{
|
||||
err = MOC_Ssend(u[1], matrix_size, MOC_FLOAT, rank - 1, 123,
|
||||
MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-ssend1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Recv(u[0], matrix_size, MOC_FLOAT, rank - 1, 124,
|
||||
MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-recv1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (rank < size)
|
||||
{
|
||||
err = MOC_Recv(u[yn - 1], matrix_size, MOC_FLOAT, rank + 1,
|
||||
123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-recv2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Ssend(u[yn - 2], matrix_size, MOC_FLOAT, rank + 1,
|
||||
124, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, string, &stringl);
|
||||
printf("%i: ERROR-ssend2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("Time for Calculations on SPE: %d = %lf\n", rank, gettime() - time);
|
||||
|
||||
//print matrix in correct order
|
||||
/*
|
||||
sleep(1+rank);
|
||||
if(rank == 1)
|
||||
for(i=0;i<yn-1;i++)
|
||||
{
|
||||
for(j=0;j<xn;j++)
|
||||
printf("%f;",u[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
else if (rank == size)
|
||||
for(i=1;i<yn;i++)
|
||||
{
|
||||
for(j=0;j<xn;j++)
|
||||
printf("%f;",u[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
else
|
||||
for(i=1;i<yn-1;i++)
|
||||
{
|
||||
for(j=0;j<xn;j++)
|
||||
printf("%f;",u[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
*/
|
||||
|
||||
MOC_Finalize();
|
||||
return 0;
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../test_jacobi
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/test_jacobi_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
extern spe_program_handle_t test_jacobi_spu;
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
int t, rank, size, rl, mspu, aspu, err, stringl, nothr;
|
||||
char proc[4];
|
||||
|
||||
int n __attribute__((__aligned__(16)));
|
||||
int iterations __attribute__((__aligned__(16)));
|
||||
float omega __attribute__((__aligned__(16)));
|
||||
int j;
|
||||
char string[255];
|
||||
|
||||
if(argc < 5)
|
||||
{
|
||||
printf("Usage: \"%s Matrix size Iterations Omega nothr\"\n",argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
n = atoi(argv[1]);
|
||||
iterations = atoi(argv[2]);
|
||||
omega = atof(argv[3]);
|
||||
nothr = atoi(argv[4]);
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// only use as many spus as specified
|
||||
aspu=nothr;
|
||||
for (t = 0; t < aspu; t++)
|
||||
MOC_Add_spu_thread ( &test_jacobi_spu, NULL );
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name( proc, &rl);
|
||||
|
||||
// sending input and other runtime specific data to spes
|
||||
for (t = 0; t < aspu; t++)
|
||||
{
|
||||
err = MOC_Bsend(&n, sizeof(int), MOC_INT, t+1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-bsend1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Bsend(&iterations, sizeof(int), MOC_INT, t+1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-bsend2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Bsend(&omega, sizeof(float), MOC_FLOAT, t+1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-bsend3: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
for (j=0; j<3*(iterations-1); j++)
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
|
||||
MOC_Finalize();
|
||||
return 0;
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := test_jacobi_spu
|
||||
LIBRARY_embed64 := test_jacobi_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/spu
|
||||
LDFLAGS = -L../../../../lib/spu
|
||||
IMPORTS = -lmoc_spu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
+261
@@ -0,0 +1,261 @@
|
||||
#include <moc.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
double gettime(void)
|
||||
{
|
||||
struct timeval time;
|
||||
gettimeofday(&time, (void *) 0);
|
||||
return (double) (time.tv_sec) + (double) time.tv_usec * 1.0e-6;
|
||||
}
|
||||
|
||||
void jacobi(float f1mO, float fOd4, float **f, float **u, float **uhelp,
|
||||
int xn, int yn)
|
||||
{
|
||||
int i,j;
|
||||
for(i=1;i<yn-1;i++)
|
||||
{
|
||||
for(j=1;j<xn-1;j++)
|
||||
{
|
||||
uhelp[i][j] = f1mO * u[i][j] + fOd4 * ( f[i][j] + u[i-1][j] + u[i+1][j] + u[i][j-1] + u[i][j+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{int rank, size, rl, err, stringl;
|
||||
unsigned int off1;
|
||||
unsigned int i,j,n,xn,yn,iter,iterations,tag_id,matrix_size;
|
||||
float f1mO,fOd4,omega;
|
||||
float **f, **u, **uhelp, **utemp;
|
||||
double time;
|
||||
char string[255];
|
||||
char proc[4];
|
||||
uint64_t my_ls, prev_ls, next_ls;
|
||||
|
||||
MOC_Status status;
|
||||
|
||||
iter=0;
|
||||
utemp=NULL;
|
||||
tag_id=0;
|
||||
|
||||
MOC_Init( 0, 0, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name( proc, &rl);
|
||||
|
||||
err = MOC_Recv(&n, sizeof(int), MOC_INT, 0, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-initial-recv1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Recv(&iterations, sizeof(int), MOC_INT, 0, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-initial-recv2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Recv(&omega, sizeof(float), MOC_FLOAT, 0, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-initial-recv3: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//size also takes into account the ppe, not useful for calculations regarding the splitting of the workload
|
||||
size=size-1;
|
||||
xn = n+2;
|
||||
yn = (n/size)+2;
|
||||
matrix_size = xn*sizeof(float);
|
||||
//constants have to be declared only once, not in every iteration
|
||||
f1mO = (1 - omega);
|
||||
fOd4 = omega * 0.25;
|
||||
|
||||
MOC_Translate_LS_to_EA(NULL, &my_ls);
|
||||
|
||||
if(rank> 1)
|
||||
{
|
||||
err = MOC_Bsend(&my_ls, sizeof(uint64_t), MOC_UNSIGNED_LONG_LONG, rank-1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-ssend1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Recv(&prev_ls, sizeof(uint64_t), MOC_UNSIGNED_LONG_LONG, rank-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(rank < size)
|
||||
{
|
||||
err = MOC_Recv(&next_ls, sizeof(uint64_t), MOC_UNSIGNED_LONG_LONG, rank+1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
err = MOC_Bsend(&my_ls, sizeof(uint64_t), MOC_UNSIGNED_LONG_LONG, rank+1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-ssend1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//help array for use in jacobi(...) is initialized here and apssed as argument. This is usefule for exchanging u and uhelp
|
||||
//and saves performance because of only initializing it once
|
||||
if((f = (float**)malloc(yn * sizeof(float*))) == NULL)
|
||||
{
|
||||
printf("Error!! Array f not initialisable because: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if((u = (float**)malloc(yn * sizeof(float*))) == NULL)
|
||||
{
|
||||
printf("Error!! Array u not initialisable because: %s\n",strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
if((uhelp = (float**)malloc(yn * sizeof(float*))) == NULL)
|
||||
{
|
||||
printf("Error!! Array uhelp not initialisable because: %s\n",strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
for(i=0;i<yn;i++)
|
||||
{
|
||||
|
||||
if((f[i] = ( float*) malloc(sizeof(float) * xn)) == NULL)
|
||||
{
|
||||
printf("Error!! Array f[%d] not initialisable because: %s\n",i,strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((u[i] = ( float*) malloc(sizeof(float) * xn)) == NULL)
|
||||
{
|
||||
printf("Error!! Array u[%d] not initialisable because: %s\n",i,strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if((uhelp[i] = ( float*) malloc(sizeof(float) * xn)) == NULL)
|
||||
{
|
||||
printf("Error!! Array uhelp[%d] not initialisable because: %s\n",i,strerror(errno));
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
//offset for calculation the position in the global array, as this determines the initialisation value
|
||||
if(rank-1 == 0)
|
||||
off1 = i;
|
||||
else
|
||||
off1 = (i+(rank-1)*(yn-2));
|
||||
|
||||
for(j=0;j<xn;j++)
|
||||
{
|
||||
f[i][j] = off1*(off1+1)+j*(j+1);
|
||||
if((off1 == 0) || (off1 == n+2-1) || (j == 0) || (j == xn-1))
|
||||
{
|
||||
u[i][j] = f[i][j];
|
||||
uhelp[i][j] = f[i][j]; //uhelps margins have to be initialized as well because of altered exchange of u and uhelp
|
||||
}
|
||||
else
|
||||
u[i][j] = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
//initialisation phase is not included in time measurements
|
||||
|
||||
time = gettime();
|
||||
for(iter=0; iter<iterations; iter++)
|
||||
{
|
||||
|
||||
jacobi(f1mO, fOd4, f, u, uhelp, xn, yn);
|
||||
|
||||
//altered exchange algorithm. No backcopy, instead change pointers, far more efficient,
|
||||
//helps reducing overhead to get better speedup, only difference from original algorithm, margins in uhelp have to be initialized
|
||||
utemp = u;
|
||||
u = uhelp;
|
||||
uhelp = utemp;
|
||||
|
||||
//put exchange top and bottom(exceptions for first and alst thread who only have one neighbour)
|
||||
if(iter < iterations -1)
|
||||
{
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
|
||||
if(rank> 1)
|
||||
{
|
||||
|
||||
err = MOC_Put_data(u[1], prev_ls+(uint32_t)u[yn-1], matrix_size, MOC_FLOAT);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-ssend1: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
|
||||
if(rank < size)
|
||||
{
|
||||
err = MOC_Put_data(u[yn-2], next_ls+(uint32_t)u[0], matrix_size, MOC_FLOAT);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-ssend2: %s (%i)\n", rank, string, err);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printf("Time for Calculations on SPE: %d = %lf\n", rank, gettime()-time);
|
||||
|
||||
//print matrix in correct order
|
||||
/*
|
||||
sleep(1+rank);
|
||||
if(rank == 1)
|
||||
for(i=0;i<yn-1;i++)
|
||||
{
|
||||
for(j=0;j<xn;j++)
|
||||
printf("%f;",u[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
else if (rank == size)
|
||||
for(i=1;i<yn;i++)
|
||||
{
|
||||
for(j=0;j<xn;j++)
|
||||
printf("%f;",u[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
else
|
||||
for(i=1;i<yn-1;i++)
|
||||
{
|
||||
for(j=0;j<xn;j++)
|
||||
printf("%f;",u[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
*/
|
||||
|
||||
MOC_Finalize();
|
||||
return 0;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../matmult
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/matmult_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
|
||||
Executable
+263
@@ -0,0 +1,263 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
extern spe_program_handle_t matmult_spu;
|
||||
|
||||
#define MASTER 0
|
||||
|
||||
void initMatrix(double** M, int x, int y, double value)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
for (j = 0; j < y; j++)
|
||||
M[i][j] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void initMatrixInc(double** M, int x, int y, double value, int offset)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
for (j = 0; j < y; j++)
|
||||
M[i][j] = (i+1) * value +( double)offset;
|
||||
}
|
||||
}
|
||||
|
||||
int getChunkSize(int processes, int rank, int lines)
|
||||
{
|
||||
int result = lines/processes;
|
||||
|
||||
if (lines%processes > rank)
|
||||
result++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int getOffset(int processes, int rank, int lines)
|
||||
{
|
||||
int result = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rank; i++)
|
||||
result += getChunkSize(processes, i, lines);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
double vecMult(double* vec1, double* vec2, int size)
|
||||
{
|
||||
double result = 0.0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
result += vec1[i] * vec2[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void printMatrix(double** M, int from_line, int to_line, int elements, int rank)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = from_line; i <= to_line; i++)
|
||||
{
|
||||
printf("RANK[%d] line %d", rank, i);
|
||||
|
||||
for (j = 0; j < elements; j++)
|
||||
{
|
||||
printf("%6.1f ", M[i][j]);
|
||||
//printf("[(%d, %d) %f] ", i, j, M[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct timeval t;
|
||||
struct timezone z;
|
||||
|
||||
double sec = 0.0;
|
||||
|
||||
gettimeofday(&t, &z);
|
||||
sec =( double)t.tv_usec/1e6 + t.tv_sec;
|
||||
|
||||
int n, m, p; //dimensions (m x n) * (n x p) = (m x p)
|
||||
int i, j, k; //indeces
|
||||
|
||||
int offset;
|
||||
|
||||
double** A; // matrices
|
||||
double** B;
|
||||
double** C;
|
||||
|
||||
int countNode,chunklastnode;
|
||||
int testFlag;
|
||||
int np, myrank, chunksize, mspu, aspu;
|
||||
MOC_Status status;
|
||||
int sendchunksize;
|
||||
double startTime, computeTime, tmpTime, communicationTime;
|
||||
|
||||
communicationTime = 0.0;
|
||||
computeTime = 0.0;
|
||||
chunklastnode=0;
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nThere are %i of %i SPUs available.\n\n", aspu, mspu);
|
||||
|
||||
MOC_Add_spu_thread ( &matmult_spu, NULL );
|
||||
MOC_Add_spu_thread ( &matmult_spu, NULL );
|
||||
MOC_Add_spu_thread ( &matmult_spu, NULL );
|
||||
MOC_Add_spu_thread ( &matmult_spu, NULL );
|
||||
MOC_Add_spu_thread ( &matmult_spu, NULL );
|
||||
MOC_Add_spu_thread ( &matmult_spu, NULL );
|
||||
|
||||
MOC_Set_buffer_size ( 500000 );
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
startTime = MOC_Wtime();
|
||||
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &np); /*get #(processors)*/
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &myrank);/*find rank of this process*/
|
||||
|
||||
m=n=p=150;
|
||||
|
||||
// B allocation each column is a vector!!!!
|
||||
B = (double**)malloc( p * sizeof(double*) );
|
||||
|
||||
for(i = 0; i < p; i++ )
|
||||
{
|
||||
B[i] = (double*)malloc( n * sizeof(double) );
|
||||
}
|
||||
|
||||
initMatrix(B, p, n, 0.0);
|
||||
|
||||
chunksize = getChunkSize(np, myrank, m);
|
||||
|
||||
if( myrank == MASTER )///////////////////-- MASTER --////////////////////////
|
||||
|
||||
{
|
||||
|
||||
initMatrix(B, p, n, 1.0);
|
||||
printf("RANK[%d]: Adresse von b ist %d\n",myrank,B);
|
||||
|
||||
for(countNode = 1; countNode < 7;countNode++)
|
||||
{
|
||||
|
||||
for(i = 0; i < p;i++) //broadcast B to SLAVES
|
||||
|
||||
{
|
||||
tmpTime = MOC_Wtime();
|
||||
|
||||
testFlag = MOC_Send(B[i], n, MOC_DOUBLE, countNode, MASTER, MOC_COMM_WORLD);
|
||||
if(testFlag != 0)
|
||||
i--;
|
||||
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
A = (double**)malloc( m * sizeof(double*) );
|
||||
C = (double**)malloc( m * sizeof(double*) );
|
||||
|
||||
for(i = 0; i < m; i++)
|
||||
{
|
||||
A[i] = (double*)malloc( n * sizeof(double));
|
||||
C[i] = (double*)malloc( p * sizeof(double));
|
||||
}
|
||||
|
||||
initMatrixInc(A, m, n, 1.0, 0); //init A with some values
|
||||
initMatrix(C, m, p, 0.0); // init C with 0.0
|
||||
|
||||
for(i = 1; i < np; i++) // distribute A to SLAVES
|
||||
|
||||
{
|
||||
offset = getOffset(np, i, m);
|
||||
sendchunksize = getChunkSize(np, i, m);
|
||||
|
||||
for(k = 0; k < sendchunksize;k++)
|
||||
{
|
||||
tmpTime = MOC_Wtime();
|
||||
|
||||
testFlag = MOC_Send(A[k + offset], n,MOC_DOUBLE,i,i,MOC_COMM_WORLD);
|
||||
|
||||
if(testFlag != 0)
|
||||
k--;
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
}
|
||||
}
|
||||
|
||||
computeTime = MOC_Wtime();
|
||||
|
||||
for(i = 0; i < chunksize; i++) //compute
|
||||
|
||||
{
|
||||
for(j = 0; j < p; j++)
|
||||
C[i][j] = vecMult(A[i], B[j], n);
|
||||
}
|
||||
|
||||
computeTime = MOC_Wtime() - computeTime;
|
||||
|
||||
for(i = 1; i < np; i++) //gather C chunks from SLAVES
|
||||
|
||||
{
|
||||
offset = getOffset(np, i, m);
|
||||
sendchunksize = getChunkSize(np, i, m);
|
||||
|
||||
for(k = 0; k < sendchunksize;k++)
|
||||
{
|
||||
tmpTime = MOC_Wtime();
|
||||
|
||||
MOC_Recv(C[k + offset], p, MOC_DOUBLE, i, i,MOC_COMM_WORLD,&status);
|
||||
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(i = 0; i < m; i++)
|
||||
free(A[i]);
|
||||
free(A);
|
||||
|
||||
for(i = 0; i < m; i++)
|
||||
free(C[i]);
|
||||
free(C);
|
||||
|
||||
}
|
||||
|
||||
for(i = 0; i < p; i++)
|
||||
free(B[i]);
|
||||
|
||||
free(B);
|
||||
|
||||
printf("RANK[%d] Communication Time: %f\n", myrank, communicationTime);
|
||||
printf("RANK[%d] Computation Time: %f\n", myrank, computeTime);
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
gettimeofday(&t, &z);
|
||||
sec = (double)t.tv_usec/1e6 + t.tv_sec - sec;
|
||||
|
||||
printf("RANK[%d] Complete time = %f\n",myrank, sec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := matmult_spu
|
||||
LIBRARY_embed64 := matmult_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE += -I../../../../include/spu
|
||||
LDFLAGS += -L../../../../lib/spu
|
||||
IMPORTS += -lmoc_spu
|
||||
|
||||
# Only necessary if the SPU-Decrementer is used as Time-Source for the SPUs
|
||||
#LDFLAGS += -L/opt/cell/sysroot/opt/cell/sdk/prototype/usr/spu/lib
|
||||
#IMPORTS += -lsputimer
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+209
@@ -0,0 +1,209 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#define MASTER 0
|
||||
|
||||
void initMatrix(double** M, int x, int y, double value)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
for (j = 0; j < y; j++)
|
||||
M[i][j] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void initMatrixInc(double** M, int x, int y, double value, int offset)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < x; i++)
|
||||
{
|
||||
for (j = 0; j < y; j++)
|
||||
M[i][j] = (i+1) * value +( double)offset;
|
||||
}
|
||||
}
|
||||
|
||||
int getChunkSize(int processes, int rank, int lines)
|
||||
{
|
||||
int result = lines/processes;
|
||||
|
||||
if (lines%processes > rank)
|
||||
result++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int getOffset(int processes, int rank, int lines)
|
||||
{
|
||||
int result = 0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rank; i++)
|
||||
result += getChunkSize(processes, i, lines);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
double vecMult(double* vec1, double* vec2, int size)
|
||||
{
|
||||
double result = 0.0;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
result += vec1[i] * vec2[i];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
struct timeval t;
|
||||
struct timezone z;
|
||||
|
||||
double sec = 0.0;
|
||||
|
||||
gettimeofday(&t, &z);
|
||||
sec =( double)t.tv_usec/1e6 + t.tv_sec;
|
||||
|
||||
int testFlag;
|
||||
|
||||
int n, m, p; //dimensions (m x n) * (n x p) = (m x p)
|
||||
int i, j, k; //indeces
|
||||
|
||||
int offset;
|
||||
|
||||
double** A; // matrices
|
||||
double** B;
|
||||
double** C;
|
||||
|
||||
int np, myrank, chunksize;
|
||||
MOC_Status status;
|
||||
|
||||
double startTime, computeTime, tmpTime, communicationTime;
|
||||
|
||||
communicationTime = 0.0;
|
||||
computeTime = 0.0;
|
||||
|
||||
MOC_Init( 0, 0, NULL);
|
||||
|
||||
startTime = MOC_Wtime();
|
||||
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &np); /*get #(processors)*/
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &myrank);/*find rank of this process*/
|
||||
|
||||
m = n = p = 150;
|
||||
|
||||
// B allocation, each column is a vector!!!!
|
||||
B = (double**)malloc( p * sizeof(double*) );
|
||||
|
||||
for(i = 0; i < p; i++ )
|
||||
{
|
||||
B[i] = (double*)malloc( n * sizeof(double) );
|
||||
}
|
||||
|
||||
initMatrix(B, p, n, 0.0);
|
||||
|
||||
chunksize = getChunkSize(np, myrank, m);
|
||||
printf("RANK[%d] chunksize: %d\n", myrank, chunksize);
|
||||
|
||||
if(myrank > 0)
|
||||
{
|
||||
|
||||
tmpTime = MOC_Wtime();
|
||||
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
|
||||
for(i = 0; i < p;i++) //get Matrix B from MASTER
|
||||
|
||||
{
|
||||
tmpTime = MOC_Wtime();
|
||||
MOC_Recv(B[i], n ,MOC_DOUBLE,MASTER,MASTER,MOC_COMM_WORLD,&status);
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
}
|
||||
|
||||
printf("RANK[%d] has Matrix B\n", myrank);
|
||||
|
||||
A = (double**)malloc(chunksize * sizeof(double)); //a chunk of A
|
||||
for(i = 0; i < chunksize; i++)
|
||||
A[i] = (double*)malloc(n * sizeof(double));
|
||||
|
||||
C = (double**)malloc(chunksize * sizeof(double)); //a chunk of A
|
||||
for(i = 0; i < chunksize; i++)
|
||||
C[i] = (double*)malloc(p * sizeof(double));
|
||||
|
||||
offset = getOffset(np, myrank, m);
|
||||
|
||||
initMatrix(A, chunksize, n, 0.0);
|
||||
initMatrix(C, chunksize, p, 0.0);
|
||||
|
||||
printf("RANK[%d] empfange daten\n",myrank);
|
||||
|
||||
for(k=0; k < chunksize; k++) // Recv chunk of A
|
||||
|
||||
{
|
||||
tmpTime = MOC_Wtime();
|
||||
|
||||
MOC_Recv(A[k],n ,MOC_DOUBLE,MASTER,myrank,MOC_COMM_WORLD,&status);
|
||||
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
}
|
||||
|
||||
computeTime = MOC_Wtime();
|
||||
printf("RANK[%d] bearbeite daten\n",myrank);
|
||||
for(i = 0; i < chunksize; i++) // compute
|
||||
|
||||
{
|
||||
for(j = 0; j < p; j++)
|
||||
{
|
||||
C[i][j] = vecMult(A[i], B[j], n);
|
||||
}
|
||||
}
|
||||
|
||||
computeTime = MOC_Wtime() - computeTime;
|
||||
|
||||
printf("RANK[%d] sende daten\n",myrank);
|
||||
for(k = 0; k < chunksize;k++)
|
||||
{
|
||||
tmpTime = MOC_Wtime();
|
||||
|
||||
testFlag = MOC_Send(C[k], p, MOC_DOUBLE, MASTER, myrank, MOC_COMM_WORLD);
|
||||
if(testFlag != 0)
|
||||
{
|
||||
k--;
|
||||
}
|
||||
communicationTime += MOC_Wtime() - tmpTime;
|
||||
}
|
||||
|
||||
for(i = 0; i < chunksize; i++)
|
||||
free(A[i]);
|
||||
free(A);
|
||||
|
||||
for(i = 0; i < chunksize; i++)
|
||||
free(C[i]);
|
||||
free(C);
|
||||
|
||||
}
|
||||
|
||||
for(i = 0; i < chunksize; i++)
|
||||
free(B[i]);
|
||||
|
||||
free(B);
|
||||
|
||||
printf("RANK[%d] Communication Time: %f\n", myrank, communicationTime);
|
||||
printf("RANK[%d] Computation Time: %f\n", myrank, computeTime);
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
gettimeofday(&t, &z);
|
||||
sec = (double)t.tv_usec/1e6 + t.tv_sec - sec;
|
||||
|
||||
printf("RANK[%d] Complete time = %f\n",myrank, sec);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../pi
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/pi_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
|
||||
Executable
+81
@@ -0,0 +1,81 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <moc.h>
|
||||
//#include <../moc_status.h>
|
||||
#define MASTER 0
|
||||
|
||||
extern spe_program_handle_t pi_spu;
|
||||
|
||||
int main()
|
||||
{
|
||||
MOC_Status mpStatus;
|
||||
int nNP, nRank, mspu, aspu;
|
||||
double ldResult = 0.0;
|
||||
double ldReceiveResult = 0.0;
|
||||
double step;
|
||||
double i, lFrom, lTo;
|
||||
double dStart, dEnd;
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nThere are %i of %i SPUs available.\n\n", aspu, mspu);
|
||||
|
||||
MOC_Add_spu_thread ( &pi_spu, NULL );
|
||||
MOC_Add_spu_thread ( &pi_spu, NULL );
|
||||
MOC_Add_spu_thread ( &pi_spu, NULL );
|
||||
MOC_Add_spu_thread ( &pi_spu, NULL );
|
||||
MOC_Add_spu_thread ( &pi_spu, NULL );
|
||||
MOC_Add_spu_thread ( &pi_spu, NULL );
|
||||
|
||||
MOC_Set_buffer_size ( 500000);
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &nNP); /*get #(processors)*/
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &nRank);/*find rank of this process*/
|
||||
|
||||
printf("[RANK-%d] processes: %d\n", nRank, nNP);
|
||||
|
||||
dStart = MOC_Wtime();
|
||||
|
||||
// calculate range
|
||||
lFrom = (1.0*nRank)/nNP;
|
||||
lTo = lFrom + 1.0/nNP;
|
||||
step = 0.0000001;
|
||||
|
||||
// calculate pi
|
||||
for (i = lFrom; i <= lTo; i+=step)
|
||||
{
|
||||
ldResult += step * 4./(1 + ((long double)i*i));
|
||||
}
|
||||
dEnd = MOC_Wtime();
|
||||
|
||||
if (nRank==MASTER)
|
||||
{
|
||||
// receive results from slaves
|
||||
for (i = 1; i < nNP; i++)
|
||||
{
|
||||
MOC_Recv(&ldReceiveResult, sizeof(double), MOC_BYTE,MOC_ANY_SOURCE, MOC_ANY_TAG, MOC_COMM_WORLD, &mpStatus);
|
||||
ldResult += ldReceiveResult;
|
||||
}
|
||||
|
||||
dEnd = MOC_Wtime();
|
||||
printf("[RANK-%d] result %1.20f in %2.8f sec\r\n", nRank, ldResult, (dEnd-dStart));
|
||||
}
|
||||
|
||||
MOC_Finalize(); // close MPI application
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := pi_spu
|
||||
LIBRARY_embed64 := pi_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE += -I../../../../include/spu
|
||||
LDFLAGS += -L../../../../lib/spu
|
||||
IMPORTS += -lmoc_spu
|
||||
|
||||
# Only necessary if the SPU-Decrementer is used as Time-Source for the SPUs
|
||||
LDFLAGS += -L/opt/cell/sysroot/opt/cell/sdk/prototype/usr/spu/lib
|
||||
#IMPORTS += -lsputimer
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <moc.h>
|
||||
//#include <../moc_status.h>
|
||||
|
||||
#define MASTER 0
|
||||
|
||||
int main()
|
||||
{
|
||||
int nNP, nRank;
|
||||
double ldResult = 0.0;
|
||||
double step;
|
||||
double i, lFrom, lTo;
|
||||
double dStart, dEnd;
|
||||
|
||||
MOC_Init( 0, 0, NULL);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &nNP); // get #(processes)
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &nRank); // find rank of this process
|
||||
|
||||
dStart = MOC_Wtime();
|
||||
|
||||
// calculate range
|
||||
lFrom = (1.0*nRank)/nNP;
|
||||
lTo = lFrom + 1.0/nNP;
|
||||
step = 0.0000001;
|
||||
|
||||
ldResult = 0.0;
|
||||
|
||||
// calculate pi
|
||||
for (i = lFrom; i <= lTo; i+=step)
|
||||
ldResult += step * 4./(1 + ((long double)i*i));
|
||||
dEnd = MOC_Wtime();
|
||||
|
||||
if(nRank != MASTER)
|
||||
{
|
||||
// send result to master
|
||||
MOC_Send(&ldResult, sizeof(double), MOC_BYTE, MASTER, 1,MOC_COMM_WORLD);
|
||||
}
|
||||
|
||||
MOC_Finalize(); // close MPI application
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../ring_test
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/ring_test_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
|
||||
Executable
+243
@@ -0,0 +1,243 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
|
||||
|
||||
extern spe_program_handle_t ring_test_spu;
|
||||
|
||||
|
||||
int buffer_size = 16384*2+128*3+16+5;
|
||||
|
||||
int max_iterations = 100;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int rank, size, rl, mspu, aspu, err, stringl, iteration = 0;
|
||||
double start, stop;
|
||||
char proc[4], *buffer1, *buffer2;
|
||||
MOC_Status status;
|
||||
char string[255];
|
||||
int t;
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nThere are %i of %i SPUs available.\n\n", aspu, mspu);
|
||||
|
||||
for ( t = 0; t < aspu; t++)
|
||||
MOC_Add_spu_thread ( &ring_test_spu, NULL );
|
||||
|
||||
MOC_Set_buffer_size ( 500000 );
|
||||
|
||||
start = MOC_Wtime();
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name( proc, &rl);
|
||||
|
||||
|
||||
if (rank == 0)
|
||||
{
|
||||
int t, integrity = 0;
|
||||
double starttime, stoptime;
|
||||
buffer1 = _malloc_align(buffer_size, 7);
|
||||
buffer2 = _malloc_align(buffer_size, 7);
|
||||
|
||||
|
||||
printf("\nRing-Test with synchronous send starting...\n");
|
||||
|
||||
starttime = MOC_Wtime();
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
for (t = 0; t < 4; t++)
|
||||
{
|
||||
buffer1[t] = rand()%256;
|
||||
}
|
||||
err = MOC_Ssend(buffer1, 4, MOC_CHAR, 1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
err = MOC_Recv(buffer2, 4, MOC_CHAR, size-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
integrity = 0;
|
||||
for (t = 0; t < 4; t++)
|
||||
{
|
||||
if (buffer1[t] != buffer2[t])
|
||||
{
|
||||
integrity++;
|
||||
//printf("ssend: Fehler an Stelle %i\n", t);
|
||||
}
|
||||
}
|
||||
if (integrity != 0)
|
||||
printf("ssend: integrity-check failed (%i false bytes found).\n", integrity);
|
||||
}
|
||||
|
||||
stoptime = MOC_Wtime();
|
||||
printf("Ring-Test with synchronous send ended\n");
|
||||
printf("time needed for %i iterations with 4 bytes of data: %lf s\n", max_iterations, stoptime-starttime );
|
||||
|
||||
|
||||
printf("\nRing-Test with synchronous send starting...\n");
|
||||
|
||||
starttime = MOC_Wtime();
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
for (t = 0; t < buffer_size; t++)
|
||||
{
|
||||
buffer1[t] = rand()%256;
|
||||
}
|
||||
err = MOC_Ssend(buffer1, buffer_size, MOC_CHAR, 1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
err = MOC_Recv(buffer2, buffer_size, MOC_CHAR, size-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
integrity = 0;
|
||||
for (t = 0; t < buffer_size; t++)
|
||||
{
|
||||
if (buffer1[t] != buffer2[t])
|
||||
{
|
||||
integrity++;
|
||||
//printf("ssend: Fehler an Stelle %i\n", t);
|
||||
}
|
||||
}
|
||||
if (integrity != 0)
|
||||
printf("ssend: integrity-check failed (%i false bytes found).\n", integrity);
|
||||
//else
|
||||
// printf("ssend: integrity-check passed\n");
|
||||
}
|
||||
|
||||
stoptime = MOC_Wtime();
|
||||
printf("Ring-Test with synchronous send ended\n");
|
||||
printf("time needed for %i iterations with %i bytes of data: %lf s\n", max_iterations, buffer_size, stoptime-starttime );
|
||||
|
||||
|
||||
printf("\nRing-Test with buffered send starting...\n");
|
||||
|
||||
starttime = MOC_Wtime();
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
for (t = 0; t < 4; t++)
|
||||
{
|
||||
buffer1[t] = rand()%256;
|
||||
}
|
||||
err = MOC_Bsend(buffer1, 4, MOC_CHAR, 1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
err = MOC_Recv(buffer2, 4, MOC_CHAR, size-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
integrity = 0;
|
||||
for (t = 0; t < 4; t++)
|
||||
{
|
||||
if (buffer1[t] != buffer2[t])
|
||||
{
|
||||
integrity++;
|
||||
printf("Fehler an Stelle %i\n", t);
|
||||
}
|
||||
}
|
||||
if (integrity != 0)
|
||||
printf("integrity-check failed (%i false bytes found).\n", integrity);
|
||||
|
||||
}
|
||||
|
||||
stoptime = MOC_Wtime();
|
||||
printf("Ring-Test with buffered send ended\n");
|
||||
printf("time needed for %i iterations with 4 bytes of data: %lf s\n\n", max_iterations, stoptime-starttime );
|
||||
|
||||
|
||||
|
||||
printf("\nRing-Test with buffered send starting...\n");
|
||||
|
||||
starttime = MOC_Wtime();
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
integrity = 0;
|
||||
for (t = 0; t < buffer_size; t++)
|
||||
{
|
||||
buffer1[t] = rand()%256;
|
||||
}
|
||||
err = MOC_Bsend(buffer1, buffer_size, MOC_CHAR, 1, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
err = MOC_Recv(buffer2, buffer_size, MOC_CHAR, size-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
integrity = 0;
|
||||
for (t = 0; t < buffer_size; t++)
|
||||
{
|
||||
if (buffer1[t] != buffer2[t])
|
||||
{
|
||||
integrity++;
|
||||
printf("Fehler an Stelle %i\n", t);
|
||||
}
|
||||
}
|
||||
if (integrity != 0)
|
||||
printf("integrity-check failed (%i false bytes found).\n", integrity);
|
||||
|
||||
}
|
||||
|
||||
stoptime = MOC_Wtime();
|
||||
printf("Ring-Test with buffered send ended\n");
|
||||
printf("time needed for %i iterations with %i bytes of data: %lf s\n\n", max_iterations, buffer_size, stoptime-starttime );
|
||||
}
|
||||
|
||||
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
stop = MOC_Wtime();
|
||||
printf("overall-duration: %lf\n", stop-start);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := ring_test_spu
|
||||
LIBRARY_embed64 := ring_test_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE += -I../../../../include/spu
|
||||
LDFLAGS += -L../../../../lib/spu
|
||||
IMPORTS += -lmoc_spu
|
||||
|
||||
# Only necessary if the SPU-Decrementer is used as Time-Source for the SPUs
|
||||
LDFLAGS += -L/opt/cell/sysroot/opt/cell/sdk/prototype/usr/spu/lib
|
||||
#IMPORTS += -lsputimer
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+108
@@ -0,0 +1,108 @@
|
||||
|
||||
#include <moc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
|
||||
|
||||
//int buffer_size = 32933;
|
||||
int buffer_size = 16384*2+128*3+16+5;
|
||||
//int buffer_size = 4;
|
||||
|
||||
int max_iterations = 100;
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int rank, size, rl, err, stringl, iteration = 0;
|
||||
char proc[4], *buffer1;
|
||||
char string[255];
|
||||
MOC_Status status;
|
||||
|
||||
|
||||
MOC_Init( 0, 0, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name( proc, &rl);
|
||||
|
||||
//printf("Process %i from %i running on %s: Hello World!\n ", rank, size, proc);
|
||||
|
||||
|
||||
buffer1 = _malloc_align(buffer_size, 4);
|
||||
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
err = MOC_Recv(buffer1, 4, MOC_CHAR, rank-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
err = MOC_Ssend(buffer1, 4, MOC_CHAR, (rank+1) % size, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
err = MOC_Recv(buffer1, buffer_size, MOC_CHAR, rank-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
err = MOC_Ssend(buffer1, buffer_size, MOC_CHAR, (rank+1) % size, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
err = MOC_Recv(buffer1, 4, MOC_CHAR, rank-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
err = MOC_Bsend(buffer1, 4, MOC_CHAR, (rank+1) % size, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (iteration = 0; iteration < max_iterations; iteration++)
|
||||
{
|
||||
err = MOC_Recv(buffer1, buffer_size, MOC_CHAR, rank-1, 123, MOC_COMM_WORLD, &status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-recv: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
err = MOC_Bsend(buffer1, buffer_size, MOC_CHAR, (rank+1) % size, 123, MOC_COMM_WORLD);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string ( err, string, &stringl );
|
||||
printf("%i: ERROR-send: %s (%i)\n", rank, string, err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../simple_saite
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/simple_saite_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
extern spe_program_handle_t simple_saite_spu;
|
||||
|
||||
#define DELTA_X 1
|
||||
#define DELTA_T 1
|
||||
#define ITERATIONS 48000
|
||||
#define THREAD_COUNT 6
|
||||
#define ELEMENT_COUNT 1200*6+2
|
||||
|
||||
void populate_vector(double* vector)
|
||||
{
|
||||
int t;
|
||||
for (t = 0; t < ELEMENT_COUNT; t++)
|
||||
vector[t] = 0;
|
||||
vector[ELEMENT_COUNT / 2 - 2 ]= 0.2;
|
||||
vector[ELEMENT_COUNT/2-1] = 0.5;
|
||||
vector[ELEMENT_COUNT/2] = 0.8;
|
||||
vector[ELEMENT_COUNT/2+1] = 0.5;
|
||||
vector[ELEMENT_COUNT/2+2] = 0.2;
|
||||
}
|
||||
|
||||
void process_result(double* vector)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, t2, rank, size, rl, mspu, aspu, temp1;
|
||||
char proc[4];
|
||||
MOC_Status moc_status;
|
||||
double start, ende;
|
||||
|
||||
int thread_count, ept1, ept2;
|
||||
double saite1[ELEMENT_COUNT] __attribute__((__aligned__(16)));
|
||||
double saite2[ELEMENT_COUNT] __attribute__((__aligned__(16)));
|
||||
double saite3[ELEMENT_COUNT] __attribute__((__aligned__(16)));
|
||||
char param[16] __attribute__((__aligned__(16)));
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nThere are %i of %i SPUs available. nb\n\n", aspu, mspu);
|
||||
|
||||
#if (THREAD_COUNT == 0)
|
||||
for (t = 0; t < aspu; t++)
|
||||
MOC_Add_spu_thread ( &simple_saite_spu, NULL );
|
||||
thread_count = aspu;
|
||||
#else
|
||||
for (t = 0; t < THREAD_COUNT; t++)
|
||||
MOC_Add_spu_thread(&simple_saite_spu, NULL);
|
||||
thread_count = THREAD_COUNT;
|
||||
#endif
|
||||
|
||||
populate_vector(saite1);
|
||||
populate_vector(saite2);
|
||||
ept1 = (ELEMENT_COUNT - 2) / thread_count;
|
||||
if ((ELEMENT_COUNT - 2) % thread_count != 0)
|
||||
{
|
||||
ept1++;
|
||||
ept2 = (ELEMENT_COUNT - 2) - thread_count * ept1;
|
||||
}
|
||||
else
|
||||
ept2 = 0;
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name(proc, &rl);
|
||||
|
||||
printf("start\n");
|
||||
|
||||
start = MOC_Wtime();
|
||||
|
||||
temp1 = 0;
|
||||
for (t = 1; t < thread_count + 1; t++)
|
||||
{
|
||||
*((int*) (param)) = ITERATIONS;
|
||||
*((int*) (param + 4)) = DELTA_X;
|
||||
*((int*) (param + 8)) = DELTA_T;
|
||||
if (t == thread_count && ept2 != 0)
|
||||
{
|
||||
*((int*) (param + 12)) = ept2;
|
||||
MOC_Send(param, 16, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
MOC_Send(saite1 + temp1, ept2 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
MOC_Send(saite2 + temp1, ept2 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((int*) (param + 12)) = ept1;
|
||||
MOC_Send(param, 16, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
MOC_Send(saite1 + temp1, ept1 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
MOC_Send(saite2 + temp1, ept1 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
}
|
||||
temp1 += ept1;
|
||||
}
|
||||
|
||||
for (t2 = 0; t2 < ITERATIONS; t2++)
|
||||
{
|
||||
for (t = 1; t < thread_count + 1; t++)
|
||||
{
|
||||
int temp_count;
|
||||
/**
|
||||
if (t == thread_count && ept2 != 0)
|
||||
{
|
||||
MOC_Send (saite1+temp1, ept2+2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
MOC_Send (saite2+temp1, ept2+2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
}
|
||||
else
|
||||
{
|
||||
MOC_Send (saite1+temp1, ept1+2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
MOC_Send (saite2+temp1, ept1+2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
}**/
|
||||
|
||||
MOC_Probe(t, 2, MOC_COMM_WORLD, &moc_status);
|
||||
MOC_Get_count(&moc_status, MOC_DOUBLE, &temp_count);
|
||||
temp1 = (moc_status.MOC_SOURCE - 1) * ept1;
|
||||
MOC_Recv(saite3 + temp1, temp_count, MOC_DOUBLE,
|
||||
moc_status.MOC_SOURCE, 2, MOC_COMM_WORLD, &moc_status);
|
||||
}
|
||||
|
||||
process_result(saite3);
|
||||
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
}
|
||||
|
||||
ende = MOC_Wtime();
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
printf("ende ( %lf s)\n", ende - start);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := simple_saite_spu
|
||||
LIBRARY_embed64 := simple_saite_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/spu
|
||||
LDFLAGS = -L../../../../lib/spu
|
||||
IMPORTS = -lmoc_spu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
#include <moc.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc_align.h>
|
||||
#include <math.h>
|
||||
|
||||
void simulate(double *vector1, double *vector2, double *vector3, double dx,
|
||||
double dt, double cq, double delta, int e_count)
|
||||
{
|
||||
double temp1, temp2;
|
||||
int x = 1;
|
||||
for (x = 1; x < e_count + 1; x++)
|
||||
{
|
||||
temp1 = 2* vector2 [x] + vector1[x] * (delta * dt - 1);
|
||||
temp2 = pow(dt / dx, 2) * cq * (vector2[x + 1] - 2* vector2 [x]
|
||||
+ vector2[x - 1]);
|
||||
vector3[x] = (temp1 + temp2) / (1 + delta * dt);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, rank, size, rl, err, errlen;
|
||||
char proc[4];
|
||||
MOC_Status moc_status;
|
||||
MOC_Request moc_req;
|
||||
char error_msg[255];
|
||||
|
||||
double *saite1, *saite2, *saite3, *pdtemp;
|
||||
double temp_double __attribute__((__aligned__(16)));
|
||||
char param[16] __attribute__((__aligned__(16)));
|
||||
int iterations, delta_x, delta_t, e_count;
|
||||
|
||||
MOC_Init(0, 0, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name(proc, &rl);
|
||||
|
||||
MOC_Recv(param, 16, MOC_BYTE, 0, 0, MOC_COMM_WORLD, &moc_status);
|
||||
iterations = *((int*) (param));
|
||||
delta_x = *((int*) (param + 4));
|
||||
delta_t = *((int*) (param + 8));
|
||||
e_count = *((int*) (param + 12));
|
||||
saite1 = _malloc_align((e_count + 2) * sizeof(double), 4);
|
||||
saite2 = _malloc_align((e_count + 2) * sizeof(double), 4);
|
||||
saite3 = _malloc_align((e_count + 2) * sizeof(double), 4);
|
||||
|
||||
MOC_Recv(saite1, e_count + 2, MOC_DOUBLE, 0, 1, MOC_COMM_WORLD, &moc_status);
|
||||
MOC_Recv(saite2, e_count + 2, MOC_DOUBLE, 0, 1, MOC_COMM_WORLD, &moc_status);
|
||||
|
||||
for (t = 0; t < iterations; t++)
|
||||
{
|
||||
/**err = MOC_Recv (saite1, e_count+2, MOC_DOUBLE, 0, 1, MOC_COMM_WORLD, &moc_status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string (err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
err = MOC_Recv (saite2, e_count+2, MOC_DOUBLE, 0, 1, MOC_COMM_WORLD, &moc_status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string (err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}**/
|
||||
|
||||
simulate(saite1, saite2, saite3, delta_x, delta_t, 0.9, 0.01, e_count);
|
||||
|
||||
err = MOC_ISend(saite3, e_count + 2, MOC_DOUBLE, 0, 2, MOC_COMM_WORLD,
|
||||
&moc_req);
|
||||
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
if (rank > 1)
|
||||
{
|
||||
temp_double = saite3[1];
|
||||
MOC_Send(&temp_double, 1, MOC_DOUBLE, rank - 1, 3, MOC_COMM_WORLD);
|
||||
}
|
||||
if (rank < size - 1)
|
||||
{
|
||||
temp_double = saite3[e_count];
|
||||
MOC_Send(&temp_double, 1, MOC_DOUBLE, rank + 1, 3, MOC_COMM_WORLD);
|
||||
}
|
||||
if (rank > 1)
|
||||
{
|
||||
MOC_Recv(&temp_double, 1, MOC_DOUBLE, rank - 1, 3, MOC_COMM_WORLD,
|
||||
&moc_status);
|
||||
saite3[0] = temp_double;
|
||||
}
|
||||
if (rank < size - 1)
|
||||
{
|
||||
MOC_Recv(&temp_double, 1, MOC_DOUBLE, rank + 1, 3, MOC_COMM_WORLD,
|
||||
&moc_status);
|
||||
saite3[e_count + 1] = temp_double;
|
||||
}
|
||||
|
||||
err = MOC_Wait(&moc_req, &moc_status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
|
||||
pdtemp = saite1;
|
||||
saite1 = saite2;
|
||||
saite2 = saite3;
|
||||
saite3 = pdtemp;
|
||||
|
||||
}
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../simple_saite2
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/simple_saite_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
extern spe_program_handle_t simple_saite_spu;
|
||||
|
||||
#define DELTA_X 1
|
||||
#define DELTA_T 1
|
||||
#define ITERATIONS 48000
|
||||
#define THREAD_COUNT 6
|
||||
#define ELEMENT_COUNT 1200*6+2
|
||||
|
||||
void populate_vector(double* vector)
|
||||
{
|
||||
int t;
|
||||
for (t = 0; t < ELEMENT_COUNT; t++)
|
||||
vector[t] = 0;
|
||||
vector[ELEMENT_COUNT / 2 - 2 ]= 0.2;
|
||||
vector[ELEMENT_COUNT/2-1] = 0.5;
|
||||
vector[ELEMENT_COUNT/2] = 0.8;
|
||||
vector[ELEMENT_COUNT/2+1] = 0.5;
|
||||
vector[ELEMENT_COUNT/2+2] = 0.2;
|
||||
}
|
||||
|
||||
void process_result(double* vector)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, t2, rank, size, rl, mspu, aspu, temp1;
|
||||
char proc[4];
|
||||
MOC_Status moc_status;
|
||||
double start, ende;
|
||||
uint64_t test;
|
||||
|
||||
int thread_count, ept1, ept2;
|
||||
double saite1[ELEMENT_COUNT] __attribute__((__aligned__(16)));
|
||||
double saite2[ELEMENT_COUNT] __attribute__((__aligned__(16)));
|
||||
double saite3[ELEMENT_COUNT] __attribute__((__aligned__(16)));
|
||||
char param[16] __attribute__((__aligned__(16)));
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nThere are %i of %i SPUs available.\n\n", aspu, mspu);
|
||||
|
||||
#if (THREAD_COUNT == 0)
|
||||
for (t = 0; t < aspu; t++)
|
||||
MOC_Add_spu_thread ( &simple_saite_spu, NULL );
|
||||
thread_count = aspu;
|
||||
#else
|
||||
for (t = 0; t < THREAD_COUNT; t++)
|
||||
MOC_Add_spu_thread(&simple_saite_spu, NULL);
|
||||
thread_count = THREAD_COUNT;
|
||||
#endif
|
||||
|
||||
populate_vector(saite1);
|
||||
populate_vector(saite2);
|
||||
thread_count = aspu;
|
||||
ept1 = (ELEMENT_COUNT - 2) / thread_count;
|
||||
if ((ELEMENT_COUNT - 2) % thread_count != 0)
|
||||
{
|
||||
ept1++;
|
||||
ept2 = (ELEMENT_COUNT - 2) - thread_count * ept1;
|
||||
}
|
||||
else
|
||||
ept2 = 0;
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name(proc, &rl);
|
||||
|
||||
printf("start\n");
|
||||
|
||||
start = MOC_Wtime();
|
||||
|
||||
temp1 = 0;
|
||||
for (t = 1; t < thread_count + 1; t++)
|
||||
{
|
||||
*((int*) (param)) = ITERATIONS;
|
||||
*((int*) (param + 4)) = DELTA_X;
|
||||
*((int*) (param + 8)) = DELTA_T;
|
||||
if (t == thread_count && ept2 != 0)
|
||||
{
|
||||
*((int*) (param + 12)) = ept2;
|
||||
test = (uint64_t) saite3;
|
||||
MOC_Send(&test, 8, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
test = (uint64_t) saite1;
|
||||
MOC_Send(&test, 8, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
test = (uint64_t) saite2;
|
||||
MOC_Send(&test, 8, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
MOC_Send(param, 16, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
MOC_Send(saite1 + temp1, ept2 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
MOC_Send(saite2 + temp1, ept2 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
}
|
||||
else
|
||||
{
|
||||
*((int*) (param + 12)) = ept1;
|
||||
test = (uint64_t) saite3;
|
||||
MOC_Send(&test, 8, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
test = (uint64_t) saite1;
|
||||
MOC_Send(&test, 8, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
test = (uint64_t) saite2;
|
||||
MOC_Send(&test, 8, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
MOC_Send(param, 16, MOC_BYTE, t, 0, MOC_COMM_WORLD);
|
||||
MOC_Send(saite1 + temp1, ept1 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
MOC_Send(saite2 + temp1, ept1 + 2, MOC_DOUBLE, t, 1, MOC_COMM_WORLD);
|
||||
}
|
||||
temp1 += ept1;
|
||||
}
|
||||
|
||||
for (t2 = 0; t2 < ITERATIONS; t2++)
|
||||
{
|
||||
//MOC_Barrier(MOC_COMM_WORLD);
|
||||
/**for (t = 1; t < thread_count+1; t++)
|
||||
{
|
||||
int temp_count;
|
||||
MOC_Probe (t, 2, MOC_COMM_WORLD, &moc_status);
|
||||
MOC_Get_count (&moc_status, MOC_DOUBLE, &temp_count);
|
||||
temp1 = (moc_status.MOC_SOURCE-1)*ept1;
|
||||
MOC_Recv (saite3+temp1, temp_count, MOC_DOUBLE, moc_status.MOC_SOURCE,
|
||||
2, MOC_COMM_WORLD, &moc_status);
|
||||
}**/
|
||||
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
process_result(saite3);
|
||||
}
|
||||
|
||||
ende = MOC_Wtime();
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
printf("ende ( %lf s)\n", ende - start);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := simple_saite_spu
|
||||
LIBRARY_embed64 := simple_saite_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/spu
|
||||
LDFLAGS = -L../../../../lib/spu
|
||||
IMPORTS = -lmoc_spu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#include <moc.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc_align.h>
|
||||
#include <math.h>
|
||||
|
||||
void simulate(double *vector1, double *vector2, double *vector3, double dx,
|
||||
double dt, double cq, double delta, int e_count)
|
||||
{
|
||||
double temp1, temp2;
|
||||
int x = 1;
|
||||
for (x = 1; x < e_count + 1; x++)
|
||||
{
|
||||
temp1 = 2* vector2 [x] + vector1[x] * (delta * dt - 1);
|
||||
temp2 = pow(dt / dx, 2) * cq * (vector2[x + 1] - 2* vector2 [x]
|
||||
+ vector2[x - 1]);
|
||||
vector3[x] = (temp1 + temp2) / (1 + delta * dt);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, rank, size, rl, err, errlen;
|
||||
char proc[4];
|
||||
MOC_Status moc_status;
|
||||
MOC_Request moc_req;
|
||||
char error_msg[255];
|
||||
|
||||
double *saite1, *saite2, *saite3, *pdtemp;
|
||||
double temp_double __attribute__((__aligned__(16)));
|
||||
char param[16] __attribute__((__aligned__(16)));
|
||||
int iterations, delta_x, delta_t, e_count;
|
||||
uint64_t ea_saite1 __attribute__((__aligned__(16)));
|
||||
uint64_t ea_saite2 __attribute__((__aligned__(16)));
|
||||
uint64_t ea_saite3 __attribute__((__aligned__(16)));
|
||||
|
||||
MOC_Init(0, 0, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name(proc, &rl);
|
||||
|
||||
err = MOC_Recv(&ea_saite3, 8, MOC_BYTE, 0, 0, MOC_COMM_WORLD, &moc_status);
|
||||
err = MOC_Recv(&ea_saite1, 8, MOC_BYTE, 0, 0, MOC_COMM_WORLD, &moc_status);
|
||||
err = MOC_Recv(&ea_saite2, 8, MOC_BYTE, 0, 0, MOC_COMM_WORLD, &moc_status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
err = MOC_Recv(param, 16, MOC_BYTE, 0, 0, MOC_COMM_WORLD, &moc_status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
iterations = *((int*) (param));
|
||||
delta_x = *((int*) (param + 4));
|
||||
delta_t = *((int*) (param + 8));
|
||||
e_count = *((int*) (param + 12));
|
||||
saite1 = _malloc_align((e_count + 2) * sizeof(double), 4);
|
||||
saite2 = _malloc_align((e_count + 2) * sizeof(double), 4);
|
||||
saite3 = _malloc_align((e_count + 2) * sizeof(double), 4);
|
||||
MOC_Recv(saite1, e_count + 2, MOC_DOUBLE, 0, 1, MOC_COMM_WORLD, &moc_status);
|
||||
MOC_Recv(saite2, e_count + 2, MOC_DOUBLE, 0, 1, MOC_COMM_WORLD, &moc_status);
|
||||
|
||||
for (t = 0; t < iterations; t++)
|
||||
{
|
||||
//MOC_Barrier(MOC_COMM_WORLD);
|
||||
/**err = MOC_Get_data (saite1, ea_saite1, e_count+2, MOC_DOUBLE);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string (err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
err = MOC_Get_data (saite2, ea_saite2, e_count+2, MOC_DOUBLE);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string (err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}**/
|
||||
|
||||
simulate(saite1, saite2, saite3, delta_x, delta_t, 0.9, 0.01, e_count);
|
||||
|
||||
err = MOC_IPut_data(saite3, ea_saite3, e_count + 2, MOC_DOUBLE,
|
||||
&moc_req);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
if (rank > 1)
|
||||
{
|
||||
temp_double = saite3[1];
|
||||
MOC_Send(&temp_double, 1, MOC_DOUBLE, rank - 1, 3, MOC_COMM_WORLD);
|
||||
}
|
||||
if (rank < size - 1)
|
||||
{
|
||||
temp_double = saite3[e_count];
|
||||
MOC_Send(&temp_double, 1, MOC_DOUBLE, rank + 1, 3, MOC_COMM_WORLD);
|
||||
}
|
||||
if (rank > 1)
|
||||
{
|
||||
MOC_Recv(&temp_double, 1, MOC_DOUBLE, rank - 1, 3, MOC_COMM_WORLD,
|
||||
&moc_status);
|
||||
saite3[0] = temp_double;
|
||||
}
|
||||
if (rank < size - 1)
|
||||
{
|
||||
MOC_Recv(&temp_double, 1, MOC_DOUBLE, rank + 1, 3, MOC_COMM_WORLD,
|
||||
&moc_status);
|
||||
saite3[e_count + 1] = temp_double;
|
||||
}
|
||||
|
||||
err = MOC_Wait(&moc_req, &moc_status);
|
||||
if (err)
|
||||
{
|
||||
MOC_Error_string(err, error_msg, &errlen);
|
||||
printf("%i: %s\n", rank, error_msg);
|
||||
}
|
||||
MOC_Barrier(MOC_COMM_WORLD);
|
||||
|
||||
pdtemp = saite1;
|
||||
saite1 = saite2;
|
||||
saite2 = saite3;
|
||||
saite3 = pdtemp;
|
||||
|
||||
}
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
DIRS = src/spu src/ppu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAM_ppu64 = ../../simple_init
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/ppu
|
||||
LDFLAGS = -L../../../../lib/ppu
|
||||
IMPORTS = -lmoc_ppu -lspe2 ../spu/simple_init_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#include <moc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc_align.h>
|
||||
|
||||
|
||||
|
||||
extern spe_program_handle_t simple_init_spu;
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int t, rank, size, rl, mspu, aspu;
|
||||
char proc[4];
|
||||
|
||||
if (MOC_Get_max_spu_count(&mspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_max_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
if (MOC_Get_avail_spu_count(&aspu))
|
||||
{
|
||||
printf("An error occured during MOC_Get_avail_spu_count\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("\nThere are %i of %i SPUs available.\n\n", aspu, mspu);
|
||||
|
||||
for (t = 1; t <= aspu; t++)
|
||||
{
|
||||
uint32_t res = MOC_Add_spu_thread ( &simple_init_spu, NULL );
|
||||
switch (res)
|
||||
{
|
||||
case MOC_SUCCESS:
|
||||
printf("Add SPU-thread %i: Success\n", t);
|
||||
break;
|
||||
case MOC_ERR_BUFFER_OVERFLOW:
|
||||
printf("Add SPU-thread %i: Exceeded MOC_SPU_THREAD_MAX\n", t);
|
||||
break;
|
||||
case MOC_ERR_INTERN:
|
||||
printf("Add SPU-thread %i: Internal error\n", t);
|
||||
break;
|
||||
default:
|
||||
printf("Add SPU-thread %i: Unknown error\n", t);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
|
||||
MOC_Init(NULL, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name( proc, &rl);
|
||||
|
||||
printf("Process %i from %i running on %s: Hello World!\n ", rank, size, proc);
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
########################################################################
|
||||
# Target
|
||||
########################################################################
|
||||
|
||||
PROGRAMS_spu := simple_init_spu
|
||||
LIBRARY_embed64 := simple_init_spu.a
|
||||
|
||||
|
||||
########################################################################
|
||||
# Local Defines
|
||||
########################################################################
|
||||
|
||||
INCLUDE = -I../../../../include/spu
|
||||
LDFLAGS = -L../../../../lib/spu
|
||||
IMPORTS = -lmoc_spu
|
||||
|
||||
########################################################################
|
||||
# buildutils/make.footer
|
||||
########################################################################
|
||||
|
||||
ifdef CELL_TOP
|
||||
include $(CELL_TOP)/buildutils/make.footer
|
||||
else
|
||||
include /opt/cell/sdk/buildutils/make.footer
|
||||
endif
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
|
||||
#include <moc.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
int rank, size, rl;
|
||||
char proc[4];
|
||||
|
||||
MOC_Init( 0, 0, NULL);
|
||||
|
||||
MOC_Comm_rank(MOC_COMM_WORLD, &rank);
|
||||
MOC_Comm_size(MOC_COMM_WORLD, &size);
|
||||
MOC_Get_processor_name( proc, &rl);
|
||||
|
||||
printf("Process %i from %i running on %s: Hello World!\n ", rank, size, proc);
|
||||
|
||||
MOC_Finalize();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user