Commit cf2459d8 authored by iker_martin's avatar iker_martin
Browse files

MaM functionality is now working for basic cases. Minor changes and memory bug...

MaM functionality is now working for basic cases. Minor changes and memory bug fixes for this intention.
parent d396827d
......@@ -52,12 +52,13 @@ typedef struct {
int my_size, my_dspl;
int *vlen;
int myId, numP;
int myId, numP, isOriginal;
MPI_Comm comm;
} Compute_data;
void originals_set_data(Compute_data *computeData, int num_target);
void BiCGStab_free (Compute_data *computeData);
void originals_set_data(Compute_data *computeData, user_redist_t *user_data, int num_target);
void targets_update(Compute_data *computeData, user_redist_t *user_data);
void user_func(void *args);
void dump(Compute_data *computeData);
......@@ -186,7 +187,7 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
n = size; n_dist = sizeR; maxiter = 16 * size; rec_iter = maxiter / 2; umbral = 1.0e-8;
myId = computeData->myId;
state = -1;
reconfigure = 0; rec_iter = -100;
reconfigure = 0; rec_iter = 1;
while ((computeData->iter < maxiter) && (computeData->tol > umbral)) {
......@@ -195,7 +196,6 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
#else
computeData->p_hat = computeData->p;
#endif
//dump(computeData);
#ifdef SPMV_OPTIMIZED
joinDistributeVectorSPMV (COLL_P2P_SPMV, MPI_COMM_WORLD, p_hat, vecP, vdimP,
vdspP, vdimR, vdspR, vectDatatypeP, vectDatatypeR);
......@@ -209,7 +209,7 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
if (myId == 0)
#if DIRECT_ERROR
printf ("%d \t %g \t %g \t %g \n", computeData->iter, computeData->tol, umbral, computeData->direct_err);
printf ("PD=%d %d \t %g \t %g \t %g \n", computeData->numP, computeData->iter, computeData->tol, umbral, computeData->direct_err);
#else
printf ("%d \t %g \n", computeData->iter, computeData->tol);
#endif // DIRECT_ERROR
......@@ -290,11 +290,15 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
computeData->iter++;
if (computeData->iter == rec_iter) { reconfigure = 1;}
if (reconfigure) {
//dump(computeData);
MAM_Checkpoint(&state, MAM_CHECK_COMPLETION, user_func, (void *) user_data);
if(state == MAM_COMPLETED) {
reconfigure = 0;
//free_computeData(computeData);
BiCGStab_free (computeData);
targets_update(computeData, user_data);
sizeR = computeData->matL.dim1;
n_dist = sizeR;
//dump(computeData);
}
}
}
......@@ -305,8 +309,8 @@ void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
if(state == MAM_PENDING) {
MAM_Checkpoint(&state, MAM_WAIT_COMPLETION, user_func, (void *) user_data);
//free_computeData(computeData);
//targets_update(dist_data, computeData, user_data);
BiCGStab_free (computeData);
targets_update(computeData, user_data);
}
#ifdef SPMV_OPTIMIZED
......@@ -346,11 +350,12 @@ void BiCGStab_free (Compute_data *computeData) {
RemoveDoubles (&computeData->b);
RemoveInts (&computeData->sizes); RemoveInts (&computeData->dspls);
RemoveInts (&computeData->vlen);
RemoveSparseMatrix (&computeData->matL);
}
void originals_free() {
if (computeData->isOriginal) {
RemoveSparseMatrix (&computeData->matL);
computeData->isOriginal = 0;
} else {
RemoveSparseMatrix2 (&computeData->matL);
}
}
/*********************************************************************************/
......@@ -394,6 +399,8 @@ int main (int argc, char **argv) {
if(isTarget) {
targets_update(&computeData, &user_data);
computeData.isOriginal = 0;
//dump(&computeData);
} else {
/***************************************/
if (argc == 4) {
......@@ -494,23 +501,23 @@ int main (int argc, char **argv) {
computeData.n = computeData.matL.dim2;
RemoveDoubles (&sol1);
BiCGStab_init (&computeData);
originals_set_data(&computeData, numTarget);
originals_set_data(&computeData, &user_data, numTarget);
computeData.isOriginal = 1;
}
BiCGStab_compute (&computeData, &user_data);
printf ("F\n");
// Error computation ||b-Ax||
// if(mat_from_file) {
dim = matL.dim2;
dim = computeData.matL.dim2;
CreateDoubles (&sol2, dim);
InitDoubles (sol2, dim, 0.0, 0.0);
MPI_Allgatherv (computeData.x, computeData.my_size, MPI_DOUBLE, sol2, computeData.sizes, computeData.dspls, MPI_DOUBLE, computeData.comm);
InitDoubles (computeData.x, computeData.my_size, 0, 0);
ProdSparseMatrixVectorByRows (computeData.matL, 0, sol2, computeData.x);
raxpy (&dimL, &DMONE, computeData.x, &IONE, computeData.b, &IONE);
raxpy (&computeData.my_size, &DMONE, computeData.x, &IONE, computeData.b, &IONE);
beta = rdot (&computeData.my_size, computeData.b, &IONE, computeData.b, &IONE);
MPI_Allreduce (MPI_IN_PLACE, &beta, 1, MPI_DOUBLE, MPI_SUM, computeData.comm);
......@@ -522,13 +529,14 @@ int main (int argc, char **argv) {
// }
beta = sqrt(beta);
if (myId == 0)
if (computeData.myId == 0)
printf ("Error: %20.10e\n", beta);
/***************************************/
// Freeing memory
BiCGStab_free (&computeData);
RemoveDoubles (&sol2);
if(computeData.comm != MPI_COMM_WORLD && computeData.comm != MPI_COMM_NULL) MPI_Comm_free(&(computeData.comm));
MAM_Finalize ();
MPI_Finalize ();
......@@ -542,12 +550,12 @@ int main (int argc, char **argv) {
/*
* Función para declarar los datos a comunicar por parte de MAM
*/
void originals_set_data(Compute_data *computeData, int num_target) {
void originals_set_data(Compute_data *computeData, user_redist_t *user_data, int num_target) {
TransformHeadertoLength (computeData->matL.vptr, computeData->n);
CreateInts (&computeData->vlen, computeData->n);
CopyInts (computeData->matL.vptr+1, computeData->vlen, computeData->n);
TransformLengthtoHeader (computeData->matL.vptr, computeData->n);
TransformHeadertoLength (computeData->matL.vptr, computeData->my_size);
CreateInts (&computeData->vlen, computeData->my_size);
CopyInts (computeData->matL.vptr+1, computeData->vlen, computeData->my_size);
TransformLengthtoHeader (computeData->matL.vptr, computeData->my_size);
MAM_Set_target_number(num_target);
......@@ -562,7 +570,7 @@ void originals_set_data(Compute_data *computeData, int num_target) {
MAM_Data_add(&(computeData->direct_err), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
#endif
MAM_Data_add(computeData->vlen, NULL, computeData->n, MPI_INT, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT); //TODO Calcular vlen
MAM_Data_add(computeData->vlen, NULL, computeData->n, MPI_INT, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
MAM_Data_add(computeData->r0, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
MAM_Data_add(computeData->b, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
#if PRECOND
......@@ -575,7 +583,16 @@ void originals_set_data(Compute_data *computeData, int num_target) {
MAM_Data_add(computeData->p, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
MAM_Data_add(computeData->r, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
MAM_Data_add(computeData->x, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
#if PRECOND
MAM_Data_add(computeData->p_hat, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
MAM_Data_add(computeData->q_hat, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
#endif
user_data->n = computeData->n;
user_data->array_vptr = computeData->matL.vptr;
user_data->array_vlen = computeData->vlen;
user_data->array_vpos = computeData->matL.vpos;
user_data->array_vval = computeData->matL.vval;
}
......@@ -631,27 +648,30 @@ void targets_update(Compute_data *computeData, user_redist_t *user_data) {
computeData->r = ((double *)value);
MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
computeData->x = ((double *)value);
#if PRECOND
MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
computeData->p_hat = ((double *)value);
MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
computeData->q_hat = ((double *)value);
#endif
int n_dist = computeData->matL.dim1;
int n = computeData->n;
CreateInts (&computeData->sizes, computeData->numP);
CreateInts (&computeData->dspls, computeData->numP);
ComputeMatrixSizes (n, computeData->sizes, computeData->dspls, computeData->comm);
computeData->my_size = computeData->sizes[computeData->myId];
computeData->my_dspl = computeData->dspls[computeData->myId];
computeData->matL = user_data->other_subm;
int n_dist = computeData->matL.dim1;
CreateDoubles (&computeData->s, n_dist);
CreateDoubles (&computeData->q, n_dist);
CreateDoubles (&computeData->y, n_dist);
CreateDoubles (&computeData->aux, n);
#if PRECOND
CreateDoubles (&computeData->p_hat, n_dist);
CreateDoubles (&computeData->q_hat, n_dist);
#endif
#if DIRECT_ERROR
CreateDoubles (&computeData->res_err, n_dist);
#endif
ComputeMatrixSizes (n, computeData->sizes, computeData->dspls, computeData->comm);
computeData->my_size = computeData->sizes[computeData->myId];
computeData->my_dspl = computeData->dspls[computeData->myId];
computeData->matL = user_data->other_subm;
*user_data = empty_user_data;
user_data->array_vptr = computeData->matL.vptr;
user_data->array_vlen = computeData->vlen;
......@@ -676,7 +696,6 @@ void user_func(void *args) {
if(user_reconf.rank_state == MAM_PROC_NEW_RANK) {
MPI_Waitall(2, user_data->reqs, MPI_STATUSES_IGNORE);
flag = 1;
}
} else {
......@@ -701,10 +720,8 @@ void dump(Compute_data *computeData) {
sleep(1);
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("\n");
fflush(stdout); MPI_Barrier(computeData->comm);
if(computeData->myId == 0) printf("Vlen=");
if(computeData->myId == 0) printf("\nVlen=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
......@@ -719,7 +736,7 @@ void dump(Compute_data *computeData) {
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("Vptr=");
if(computeData->myId == 0) printf("\nVptr=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
......@@ -734,7 +751,7 @@ void dump(Compute_data *computeData) {
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("Vpos=");
if(computeData->myId == 0) printf("\nVpos=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
......@@ -749,7 +766,7 @@ void dump(Compute_data *computeData) {
MPI_Barrier(computeData->comm);
}
if(computeData->myId == 0) printf("Vval=");
if(computeData->myId == 0) printf("\nVval=");
fflush(stdout); MPI_Barrier(computeData->comm);
for(i=0; i<computeData->numP; i++) {
if(computeData->myId == i) {
......@@ -868,7 +885,7 @@ void dump(Compute_data *computeData) {
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++) {
......@@ -883,7 +900,7 @@ void dump(Compute_data *computeData) {
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++) {
......
......@@ -81,29 +81,31 @@ void targets_distribution(mam_user_reconf_t user_reconf, user_redist_t *user_dat
}
}
}
//get_dist(n, dist_data.myId, dist_data.numP, &dist_data);
get_dist(n, dist_data.myId, dist_data.numP, &dist_data);
//CreateSparseMatrixVptr(&user_data->other_subm, dist_data.tamBl, n, 0);
CreateSparseMatrixVptr(&user_data->other_subm, dist_data.tamBl, n, 0);
user_data->other_subm.vptr[0] = 0;
for(i=0; i<dist_data.tamBl; i++) {
user_data->other_subm.vptr[i+1] = vlen[i];
}
//TransformLengthtoHeader(user_data->other_subm.vptr, user_data->other_subm.dim1); // The array is converted from vlen to vptr
TransformLengthtoHeader(user_data->other_subm.vptr, user_data->other_subm.dim1); // The array is converted from vlen to vptr
elems = user_data->other_subm.vptr[dist_data.tamBl];
//CreateSparseMatrixValues(&user_data->other_subm, dist_data.tamBl, n, elems, 0);
CreateSparseMatrixValues(&user_data->other_subm, dist_data.tamBl, n, elems, 0);
recv_vpos = user_data->other_subm.vpos;
recv_vval = user_data->other_subm.vval;
prepare_redist_counts(rcounts, rdispls, user_reconf.numS, offset, dist_data, user_data->other_subm.vptr);
// print_counts2(dist_data, rcounts, rdispls, numP, 0, "TARGETS");
}
if(user_reconf.rank_state != MAM_PROC_NEW_RANK) {
MPI_Comm_rank(user_data->comm, &dist_data.myId);
dist_data.numP = user_reconf.numS;
//get_dist(n, dist_data.myId, dist_data.numP, &dist_data);
get_dist(n, dist_data.myId, dist_data.numP, &dist_data);
offset = (user_reconf.numS + user_reconf.numT) == numP ?
user_reconf.numS : 0;
//prepare_redist_counts(scounts, sdispls, user_reconf.numT, offset, dist_data, user_data->array_vptr);
prepare_redist_counts(scounts, sdispls, user_reconf.numT, offset, dist_data, user_data->array_vptr);
// print_counts2(dist_data, scounts, sdispls, numP, 0, "SOURCES");
}
// COMUNICACION DE DATOS //
......
......@@ -2,6 +2,7 @@
#define ToolsMAM 1
#include <ScalarVectors.h>
#include "SparseProduct.h"
#include <mpi.h>
#include "../malleability/MAM.h"
......
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