okay:
Code:
#include <stdlib.h>
#ifdef SESC
#include "sescapi.h"
#endif
struct args{
double ****TT; //TT is a pointer to T
double ****S; //S is a pointer to A
int *aa; //aa is a copy of a
int matr_num; //the number of the matrix currently being calculated
int t_num; //the number of the thread curently running
};
//main function for calculating the row values
void *calc_row(void * t_args)
{
struct args *aargs = (struct args *) t_args;
int threadnum = aargs->t_num; //the thread number is also the row number
int matrnum = aargs->matr_num;
int col,m;
for(col=0;col<(aargs->aa)[matrnum+1];col++){ //aa[matrnum+1] columns in TT
(*(aargs->TT))[matrnum][threadnum][z]=0;
for(m=0;m<(aargs->aa)[matrnum];m++){ //aa[matrnum+1] rows in S
(*(aargs->TT))[matrnum][threadnum][col] += (*(aargs->TT))[matrnum-1][threadnum][col]*(*(aargs->S))[matrnum][col][m];
}
}
#ifdef SESC
sesc_exit(0);
#endif
exit(0);
}
double **programY(double ***A, int *a, int mat_num)
{
#ifdef SESC
sesc_init();
#endif
double **result;
double ***T;
int i, j;
/* memory allocation for intermediate results */
T = (double ***) malloc((mat_num)*sizeof(double **));
for(i=1; i<mat_num;i++)
{
T[i] = (double **)malloc(a[0]*sizeof(double *));
for(j=0; j<a[0]; j++)
{
T[i][j] = (double *)malloc(a[i+1] * sizeof(double));
}
}
T[0] = A[0];
/* matrix multiplication */
#ifdef SESC
for(i=1;i<mat_num;i++)
{
for(j=0;j<a[0];j++) //a[0] rows in T[i]
{
struct args targs;
targs.TT=&T;
targs.S=&A;
targs.aa=a;
targs.matr_num=i;
targs.t_num=j;
sesc_spawn((void *) *calc_row, (void *)&targs, 0); //one thread per row of first matrix (for T[1]*A[2], this means T[1])
}
sesc_wait();
}
sesc_exit(0);
result = T[mat_num-1];
#else
result = NULL;
#endif
/* memory deallocation - this loop does not deallocate T[0](= A[0]) and T[mat_num](=result).*/
for(i=1; i<mat_num-1;i++)
{
for(j=0; j<a[0]; j++)
{
free(T[i][j]);
}
free(T[i]);
}
free(T);
return result;
}
to pass T by reference, i made the struct's TT variable into a pointer to a three dimensional array, which i initialize in programY() to the reference to T, and i dereference it in calc_row. i did the same basic thing for A. my head hurts. and not so surprisingly this didn't work.