Commit d396827d authored by iker_martin's avatar iker_martin
Browse files

Fixed minor memory errors

parent 03439e71
...@@ -103,6 +103,8 @@ void BiCGStab_init (Compute_data *computeData) { ...@@ -103,6 +103,8 @@ void BiCGStab_init (Compute_data *computeData) {
#pragma omp parallel for #pragma omp parallel for
for (i=0; i<n_dist; i++) for (i=0; i<n_dist; i++)
computeData->diags[i] = DONE / computeData->diags[i]; computeData->diags[i] = DONE / computeData->diags[i];
InitDoubles (computeData->p_hat, n_dist, DZERO, DZERO);
InitDoubles (computeData->q_hat, n_dist, DZERO, DZERO);
#endif #endif
CreateDoubles (&computeData->aux, n); CreateDoubles (&computeData->aux, n);
...@@ -193,6 +195,7 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) { ...@@ -193,6 +195,7 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
#else #else
computeData->p_hat = computeData->p; computeData->p_hat = computeData->p;
#endif #endif
//dump(computeData);
#ifdef SPMV_OPTIMIZED #ifdef SPMV_OPTIMIZED
joinDistributeVectorSPMV (COLL_P2P_SPMV, MPI_COMM_WORLD, p_hat, vecP, vdimP, joinDistributeVectorSPMV (COLL_P2P_SPMV, MPI_COMM_WORLD, p_hat, vecP, vdimP,
vdspP, vdimR, vdspR, vectDatatypeP, vectDatatypeR); vdspP, vdimR, vdspR, vectDatatypeP, vectDatatypeR);
...@@ -335,10 +338,14 @@ void BiCGStab_free (Compute_data *computeData) { ...@@ -335,10 +338,14 @@ void BiCGStab_free (Compute_data *computeData) {
RemoveDoubles (&computeData->diags); RemoveDoubles (&computeData->diags);
RemoveDoubles(&computeData->p_hat); RemoveDoubles (&computeData->q_hat); RemoveDoubles(&computeData->p_hat); RemoveDoubles (&computeData->q_hat);
#endif #endif
#if DIRECT_ERROR
RemoveDoubles (&computeData->res_err); RemoveDoubles (&computeData->x_exact);
#endif
RemoveDoubles (&computeData->x); RemoveDoubles (&computeData->x);
RemoveDoubles (&computeData->b); RemoveDoubles (&computeData->b);
RemoveInts (&computeData->sizes); RemoveInts (&computeData->dspls); RemoveInts (&computeData->sizes); RemoveInts (&computeData->dspls);
RemoveInts (&computeData->vlen);
RemoveSparseMatrix (&computeData->matL); RemoveSparseMatrix (&computeData->matL);
} }
...@@ -391,6 +398,7 @@ int main (int argc, char **argv) { ...@@ -391,6 +398,7 @@ int main (int argc, char **argv) {
/***************************************/ /***************************************/
if (argc == 4) { if (argc == 4) {
mat_from_file = atoi(argv[2]); mat_from_file = atoi(argv[2]);
numTarget = atoi(argv[3]);
} else { } else {
mat_from_file = atoi(argv[2]); mat_from_file = atoi(argv[2]);
nodes = atoi(argv[3]); nodes = atoi(argv[3]);
...@@ -408,7 +416,6 @@ int main (int argc, char **argv) { ...@@ -408,7 +416,6 @@ int main (int argc, char **argv) {
TransposeSparseMatrices (sym, 0, &mat, 0); TransposeSparseMatrices (sym, 0, &mat, 0);
dim = mat.dim1; dim = mat.dim1;
} }
numTarget = atoi(argv[3]);
// Distributing the matrix // Distributing the matrix
dim = DistributeMatrix (mat, index, &matL, indexL, vdimL, vdspL, root, MPI_COMM_WORLD); dim = DistributeMatrix (mat, index, &matL, indexL, vdimL, vdspL, root, MPI_COMM_WORLD);
...@@ -488,7 +495,6 @@ int main (int argc, char **argv) { ...@@ -488,7 +495,6 @@ int main (int argc, char **argv) {
RemoveDoubles (&sol1); RemoveDoubles (&sol1);
BiCGStab_init (&computeData); BiCGStab_init (&computeData);
originals_set_data(&computeData, numTarget); originals_set_data(&computeData, numTarget);
dump(&computeData);
} }
...@@ -540,7 +546,7 @@ void originals_set_data(Compute_data *computeData, int num_target) { ...@@ -540,7 +546,7 @@ void originals_set_data(Compute_data *computeData, int num_target) {
TransformHeadertoLength (computeData->matL.vptr, computeData->n); TransformHeadertoLength (computeData->matL.vptr, computeData->n);
CreateInts (&computeData->vlen, computeData->n); CreateInts (&computeData->vlen, computeData->n);
CopyInts (computeData->matL.vptr, computeData->vlen, computeData->n); CopyInts (computeData->matL.vptr+1, computeData->vlen, computeData->n);
TransformLengthtoHeader (computeData->matL.vptr, computeData->n); TransformLengthtoHeader (computeData->matL.vptr, computeData->n);
MAM_Set_target_number(num_target); MAM_Set_target_number(num_target);
...@@ -712,6 +718,229 @@ void dump(Compute_data *computeData) { ...@@ -712,6 +718,229 @@ void dump(Compute_data *computeData) {
sleep(1); sleep(1);
MPI_Barrier(computeData->comm); MPI_Barrier(computeData->comm);
} }
if(computeData->myId == 0) printf("\n");
if(computeData->myId == 0) printf("Vptr=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size+1; j++) {
printf("%d, ", computeData->matL.vptr[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("Vpos=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->matL.vptr[computeData->my_size]; j++) {
printf("%d, ", computeData->matL.vpos[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("Vval=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->matL.vptr[computeData->my_size]; j++) {
printf("%lf, ", computeData->matL.vval[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\nX=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->x[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\nB=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->b[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\nr=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->r[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\nr0=");
fflush(stdout); MPI_Barrier(computeData->comm); fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->r0[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\np=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->p[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\ndiags=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->diags[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\np_hat=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->p_hat[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
/*
if(computeData->myId == 0) printf("\nq_hat=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->q_hat[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\ns=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->s[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\ny=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
for(int j=0; j<computeData->my_size; j++) {
printf("%lf, ", computeData->y[j]);
}
}
fflush(stdout);
sleep(1);
MPI_Barrier(computeData->comm);
}
*/
} }
/*
typedef struct {
double tol, tol0;
int iter, n;
double rho;
double *x, *b;
double *s, *q, *r, *p, *r0, *y, *p_hat, *q_hat;
double *aux;
SparseMatrix matL;
#if PRECOND
double *diags;
#endif
#if DIRECT_ERROR
double *res_err, *x_exact;
double direct_err;
#endif
double t1;
int *sizes, *dspls;
int my_size, my_dspl;
int *vlen;
int myId, numP;
MPI_Comm comm;
} Compute_data;
*/
...@@ -180,7 +180,7 @@ int DistributeMatrix (SparseMatrix spr, int index, ptr_SparseMatrix sprL, int in ...@@ -180,7 +180,7 @@ int DistributeMatrix (SparseMatrix spr, int index, ptr_SparseMatrix sprL, int in
// Calculating the vectors of sizes (vdimL) and displacements (vdspl) // Calculating the vectors of sizes (vdimL) and displacements (vdspl)
divL = (dim / nProcs); rstL = (dim % nProcs); divL = (dim / nProcs); rstL = (dim % nProcs);
for (i=0; i<nProcs; i++) vdimL[i] = divL + (i < rstL); for (i=0; i<nProcs; i++) vdimL[i] = divL + (i < rstL);
vdspL[0] = 0; for (i=0; i<nProcs; i++) vdspL[i+1] = vdspL[i] + vdimL[i]; vdspL[0] = 0; for (i=1; i<nProcs; i++) vdspL[i] = vdspL[i-1] + vdimL[i-1];
dimL = vdimL[myId]; dspL = vdspL[myId]; dimL = vdimL[myId]; dspL = vdspL[myId];
// Distribution of the matrix, by blocks // Distribution of the matrix, by blocks
...@@ -234,7 +234,7 @@ int ComputeMatrixSizes (int dim, int *vdimL, int *vdspL, MPI_Comm comm) { ...@@ -234,7 +234,7 @@ int ComputeMatrixSizes (int dim, int *vdimL, int *vdspL, MPI_Comm comm) {
// Calculating the vectors of sizes (vdimL) and displacements (vdspl) // Calculating the vectors of sizes (vdimL) and displacements (vdspl)
divL = (dim / nProcs); rstL = (dim % nProcs); divL = (dim / nProcs); rstL = (dim % nProcs);
for (i=0; i<nProcs; i++) vdimL[i] = divL + (i < rstL); for (i=0; i<nProcs; i++) vdimL[i] = divL + (i < rstL);
vdspL[0] = 0; for (i=0; i<nProcs; i++) vdspL[i+1] = vdspL[i] + vdimL[i]; vdspL[0] = 0; for (i=1; i<nProcs; i++) vdspL[i] = vdspL[i-1] + vdimL[i-1];
return dim; return dim;
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment