Initial commit.

This commit is contained in:
2017-10-26 19:57:24 +02:00
commit 9ce8b5485d
1090 changed files with 47036 additions and 0 deletions
+15
View File
@@ -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
+25
View File
@@ -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
View File
@@ -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;
}
+25
View File
@@ -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
+242
View File
@@ -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;
}