Example #1
0
double * multipleLinearRegression(double **X, double *y, int n, int m){

 double **A, **XT, **B, *b, *x, **Y;
/* int i,j; */ 

 Y=vectorToMatrix(y,m,1);

 x=allocateDoubleVector(n);
 XT=trasposeMatrix(X,n,m); 
/* XT.X.x = XT.b */
 A=multiplyMatrix(XT,X,m,n,n);
 B=multiplyMatrix(XT,Y,m,n,1); 
 b=matrixToVector(B,n,1);

/* for (i=0; i<n; i++){ 
  for (j=0; j<n; j++){
   fprintf(stdout,"%f ",A[i][j]); 
  }
  fprintf(stdout,"\n"); 
 }  
 
 for(i=0;i<n;i++) fprintf(stdout,"%f ",b[i]);
  fprintf(stdout,"\n"); */
 
 x = gaussianElimination (n, A, b); 

 return x;

}
Example #2
0
void transpose (Real **b, int size, int *len, int *disp, int rank, int m){
  int i, *sendcounts, *rdispls;
  Real  *sendbuf, *recvbuf;
  sendbuf = createRealArray (m * len[rank]);
  recvbuf = createRealArray (m * len[rank]);
  sendcounts = calloc(size,sizeof(int));
  rdispls = calloc(size,sizeof(int));
  matrixToVector(b,sendbuf,len,disp, size, rank);

  int index = 0;
  for (int i = 0; i < size; ++i)
  {
    sendcounts[i]= len[rank]*len[i];
    rdispls[i]=index;
    index=index+sendcounts[i];
  }
  MPI_Alltoallv(sendbuf, sendcounts, rdispls, MPI_DOUBLE, recvbuf, sendcounts, rdispls, MPI_DOUBLE, MPI_COMM_WORLD);
  vectorToMatrix(b,recvbuf,len,disp, size, rank);
}