BiCGStab.c 35.6 KB
Newer Older
1
2
3
4
5
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
6
7
//#include <mkl_blas.h>
#include "mymkl.h"
8
9
#include <mpi.h>
#include <hb_io.h>
10
//#include <vector>
11
//#include <sys/prctl.h>
12
13
14
15
16
17
18
19

#include "reloj.h"
#include "ScalarVectors.h"
#include "SparseProduct.h"
#include "ToolsMPI.h"
#include "matrix.h"
#include "common.h"

20
21
22
#include "../malleability/MAM.h"
#include "ToolsMAM.h"

23
24
25
26
27
28
29
30
31
// ================================================================================

#define DIRECT_ERROR 1
#define PRECOND 1
// #define SPMV_OPTIMIZED 1
#ifdef SPMV_OPTIMIZED
  #define COLL_P2P_SPMV 0
#endif

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;

55
  int myId, numP, isOriginal;
56
57
58
59
  MPI_Comm comm;
} Compute_data;


60
61
void BiCGStab_free (Compute_data *computeData);
void originals_set_data(Compute_data *computeData, user_redist_t *user_data, int num_target);
62
63
64
65
66
67
void targets_update(Compute_data *computeData, user_redist_t *user_data);
void user_func(void *args);
void dump(Compute_data *computeData);

void BiCGStab_init (Compute_data *computeData) {
    int size = computeData->matL.dim2, sizeR = computeData->matL.dim1; 
68
69
    int IONE = 1; 
    double DONE = 1.0, DMONE = -1.0, DZERO = 0.0;
70
71
    int n, n_dist, myId, nProcs;
    double t2;
72
#if PRECOND
73
74
75
    int i;
    int *posd = NULL;
    computeData->diags = NULL;
76
77
#endif

78
79
80
81
82
83
84
85
86
87
88
89
    computeData->s = NULL; computeData->q = NULL; computeData->r = NULL; computeData->p = NULL;
    computeData->r0 = NULL; computeData->y = NULL; computeData->p_hat = NULL; computeData->q_hat = NULL;
    computeData->aux = NULL;
    myId = computeData->myId;
    nProcs = computeData->numP;
    n = size; n_dist = sizeR;
    CreateDoubles (&computeData->s, n_dist);
    CreateDoubles (&computeData->q, n_dist);
    CreateDoubles (&computeData->r, n_dist);
    CreateDoubles (&computeData->r0, n_dist);
    CreateDoubles (&computeData->p, n_dist);
    CreateDoubles (&computeData->y, n_dist);
90
91
#if DIRECT_ERROR
    // init exact solution
92
93
94
95
    computeData->res_err = NULL; computeData->x_exact = NULL;
    CreateDoubles (&computeData->x_exact, n_dist);
    CreateDoubles (&computeData->res_err, n_dist);
    InitDoubles (computeData->x_exact, n_dist, DONE, DZERO);
96
97
98
99
#endif // DIRECT_ERROR 

#if PRECOND
    CreateInts (&posd, n_dist);
100
101
102
103
    CreateDoubles (&computeData->p_hat, n_dist);
    CreateDoubles (&computeData->q_hat, n_dist);
    CreateDoubles (&computeData->diags, n_dist);
    GetDiagonalSparseMatrix2 (computeData->matL, computeData->dspls[myId], computeData->diags, posd);
104
105
#pragma omp parallel for
    for (i=0; i<n_dist; i++) 
106
        computeData->diags[i] = DONE / computeData->diags[i];
iker_martin's avatar
iker_martin committed
107
108
    InitDoubles (computeData->p_hat, n_dist, DZERO, DZERO);
    InitDoubles (computeData->q_hat, n_dist, DZERO, DZERO);
109
#endif
110
    CreateDoubles (&computeData->aux, n); 
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

#ifdef SPMV_OPTIMIZED
    int *permP = NULL, *ipermP = NULL;
    int *vdspP = NULL, *vdimP = NULL, *vdspR = NULL, *vdimR = NULL;
    double *vecP = NULL;
    MPI_Datatype *vectDatatypeP = NULL, *vectDatatypeR = NULL;

    CreateInts (&ipermP, size);
    CreateInts (&vdimP, nProcs); CreateInts (&vdspP, nProcs + 1);
    CreateInts (&vdimR, nProcs); CreateInts (&vdspR, nProcs + 1);
    vectDatatypeP = (MPI_Datatype *) malloc (nProcs * sizeof (MPI_Datatype));
    vectDatatypeR = (MPI_Datatype *) malloc (nProcs * sizeof (MPI_Datatype));
    createAlltoallwStruct (COLL_P2P_SPMV, MPI_COMM_WORLD, mat, sizes, dspls, vdimP, 
                vdspP, &aux, &permP, ipermP, vdimR, vdspR, vectDatatypeP, vectDatatypeR);

  // Code required before the loop  
    PermuteInts (mat.vpos, ipermP, mat.vptr[mat.dim1]);
#endif

130
    computeData->iter = 0;
131
132
133
134
135
136
#ifdef SPMV_OPTIMIZED
    joinDistributeVectorSPMV (COLL_P2P_SPMV, MPI_COMM_WORLD, x, vecP, vdimP, vdspP, 
                                vdimR, vdspR, vectDatatypeP, vectDatatypeR);
    InitDoubles (s, sizeR, DZERO, DZERO);
    ProdSparseMatrixVectorByRows (mat, 0, vecP, s);                  // s = A * x
#else
137
138
139
    MPI_Allgatherv (computeData->x, sizeR, MPI_DOUBLE, computeData->aux, computeData->sizes, computeData->dspls, MPI_DOUBLE, computeData->comm);
    InitDoubles (computeData->s, sizeR, DZERO, DZERO);
    ProdSparseMatrixVectorByRows (computeData->matL, 0, computeData->aux, computeData->s); // s = A * x
140
#endif
141
142
    rcopy (&n_dist, computeData->b, &IONE, computeData->r, &IONE);                                // r = b
    raxpy (&n_dist, &DMONE, computeData->s, &IONE, computeData->r, &IONE);           // r -= s
143

144
145
    rcopy (&n_dist, computeData->r, &IONE, computeData->p, &IONE);                                // p = r
    rcopy (&n_dist, computeData->r, &IONE, computeData->r0, &IONE);                               // r0 = r
146
    // compute tolerance and <r0,r0>
147
148
    computeData->rho = rdot (&n_dist, computeData->r, &IONE, computeData->r, &IONE);
    MPI_Allreduce (MPI_IN_PLACE, &computeData->rho, 1, MPI_DOUBLE, MPI_SUM, computeData->comm);
149

150
151
    computeData->tol0 = sqrt (computeData->rho);
    computeData->tol = computeData->tol0;
152
153
154

#if DIRECT_ERROR
    // compute direct error
155
156
    rcopy (&n_dist, computeData->x_exact, &IONE, computeData->res_err, &IONE);                    // res_err = x_exact
    raxpy (&n_dist, &DMONE, computeData->x, &IONE, computeData->res_err, &IONE);                  // res_err -= x
157
158

    // compute inf norm
159
160
    computeData->direct_err = norm_inf(n_dist, computeData->res_err);
    MPI_Allreduce(MPI_IN_PLACE, &computeData->direct_err, 1, MPI_DOUBLE, MPI_MAX, computeData->comm);
161
162

    //    // compute euclidean norm
163
    //    direct_err = rdot (&n_dist, res_err, &IONE, res_err, &IONE);            // direct_err = res_err' * res_err
164
165
166
167
    //    MPI_Allreduce(MPI_IN_PLACE, &direct_err, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
    //    direct_err = sqrt(direct_err);
#endif // DIRECT_ERROR

168
169
170
171
172
#if PRECOND
    RemoveInts (&posd);
#endif

    MPI_Barrier(computeData->comm);
173
    if (myId == 0) 
174
175
        reloj (&computeData->t1, &t2);
}
176

177
178
179
180
181
void BiCGStab_compute (Compute_data *computeData, user_redist_t *user_data) {
    int size = computeData->matL.dim2, sizeR = computeData->matL.dim1; 
    int IONE = 1; 
    double DONE = 1.0, DMONE = -1.0, DZERO = 0.0;
    int n, n_dist;
182
    int maxiter, myId, reconfigure, rec_iter, state, flag;
183
184
185
186
187
188
189
    double beta, alpha, umbral, omega, tmp;
    double t3, t4;
    double reduce[2];

    n = size; n_dist = sizeR; maxiter = 16 * size; rec_iter = maxiter / 2; umbral = 1.0e-8;
    myId = computeData->myId;
    state = -1;
190
191
    reconfigure = 0; rec_iter= 500;
//	  flag = (computeData->rho == 0.0)? -1: 1;
192
193

    while ((computeData->iter < maxiter) && (computeData->tol > umbral)) {
194
//    while ((computeData->iter < maxiter) && (flag == 1)) {
195
196

#if PRECOND
197
        VvecDoubles (DONE, computeData->diags, computeData->p, DZERO, computeData->p_hat, n_dist);              // p_hat = D^-1 * p
198
#else
199
        computeData->p_hat = computeData->p;
200
201
202
203
204
205
206
#endif
#ifdef SPMV_OPTIMIZED
        joinDistributeVectorSPMV (COLL_P2P_SPMV, MPI_COMM_WORLD, p_hat, vecP, vdimP, 
                                    vdspP, vdimR, vdspR, vectDatatypeP, vectDatatypeR);
        InitDoubles (s, sizeR, DZERO, DZERO);
        ProdSparseMatrixVectorByRows (mat, 0, vecP, s);                   // s = A * p
#else
207
208
209
        MPI_Allgatherv (computeData->p_hat, sizeR, MPI_DOUBLE, computeData->aux, computeData->sizes, computeData->dspls, MPI_DOUBLE, computeData->comm);
        InitDoubles (computeData->s, sizeR, DZERO, DZERO);
        ProdSparseMatrixVectorByRows (computeData->matL, 0, computeData->aux, computeData->s);                   // s = A * p
210
211
212
213
#endif

        if (myId == 0) 
#if DIRECT_ERROR
214
            printf ("PD=%d %d \t %g \t %g \t %g \n", computeData->numP, computeData->iter, computeData->tol, umbral, computeData->direct_err);
215
#else        
216
        printf ("%d \t %g \n", computeData->iter, computeData->tol);
217
//        printf ("%d \t %20.10e \n", computeData->iter, computeData->tol);
218
#endif // DIRECT_ERROR
219
220
        alpha = rdot (&n_dist, computeData->r0, &IONE, computeData->s, &IONE);
        MPI_Allreduce (MPI_IN_PLACE, &alpha, 1, MPI_DOUBLE, MPI_SUM, computeData->comm);
221

222
        alpha = computeData->rho / alpha;
223

224
        rcopy (&n_dist, computeData->r, &IONE, computeData->q, &IONE);                            // q = r
225
        tmp = -alpha;
226
        raxpy (&n_dist, &tmp, computeData->s, &IONE, computeData->q, &IONE);                      // q = r - alpha * s;
227
228
229

        // second spmv
#if PRECOND
230
        VvecDoubles (DONE, computeData->diags, computeData->q, DZERO, computeData->q_hat, n_dist);             // q_hat = D^-1 * q
231
#else
232
        computeData->q_hat = computeData->q;
233
234
235
236
237
238
239
#endif
#ifdef SPMV_OPTIMIZED
        joinDistributeVectorSPMV (COLL_P2P_SPMV, MPI_COMM_WORLD, q_hat, vecP, vdimP, 
                                  vdspP, vdimR, vdspR, vectDatatypeP, vectDatatypeR);
        InitDoubles (y, sizeR, DZERO, DZERO);
        ProdSparseMatrixVectorByRows (mat, 0, vecP, y);                // y = A * q
#else
240
241
242
        MPI_Allgatherv (computeData->q_hat, sizeR, MPI_DOUBLE, computeData->aux, computeData->sizes, computeData->dspls, MPI_DOUBLE, computeData->comm);
        InitDoubles (computeData->y, sizeR, DZERO, DZERO);
        ProdSparseMatrixVectorByRows (computeData->matL, 0, computeData->aux, computeData->y);                // y = A * q
243
244
#endif
        // omega = <q, y> / <y, y>
245
246
247
        reduce[0] = rdot (&n_dist, computeData->q, &IONE, computeData->y, &IONE);
        reduce[1] = rdot (&n_dist, computeData->y, &IONE, computeData->y, &IONE);
        MPI_Allreduce (MPI_IN_PLACE, reduce, 2, MPI_DOUBLE, MPI_SUM, computeData->comm);
248
249
250
251

        omega = reduce[0] / reduce[1];

        // x+1 = x + alpha * p + omega * q
252
253
        raxpy (&n_dist, &alpha, computeData->p_hat, &IONE, computeData->x, &IONE); 
        raxpy (&n_dist, &omega, computeData->q_hat, &IONE, computeData->x, &IONE); 
254
255

        // r+1 = q - omega * y
256
        rcopy (&n_dist, computeData->q, &IONE, computeData->r, &IONE);                            // r = q
257
        tmp = -omega;
258
        raxpy (&n_dist, &tmp, computeData->y, &IONE, computeData->r, &IONE);                      // r = q - omega * y;
259
260
        
        // rho = <r0, r+1> and tolerance
261
262
263
        reduce[0] = rdot (&n_dist, computeData->r0, &IONE, computeData->r, &IONE);
        reduce[1] = rdot (&n_dist, computeData->r, &IONE, computeData->r, &IONE);
        MPI_Allreduce (MPI_IN_PLACE, reduce, 2, MPI_DOUBLE, MPI_SUM, computeData->comm);
264
265

        tmp = reduce[0];
266
        computeData->tol = sqrt (reduce[1]) / computeData->tol0;
267
268

        // beta = (alpha / omega) * <r0, r+1> / <r0, r>
269
270
        beta = (alpha / omega) * (tmp / computeData->rho);
        computeData->rho = tmp;
271
272
273
       
        // p+1 = r+1 + beta * (p - omega * s)
        tmp = -omega; 
274
275
276
        raxpy (&n_dist, &tmp, computeData->s, &IONE, computeData->p, &IONE);                     // p -= omega * s
        rscal (&n_dist, &beta, computeData->p, &IONE);                                           // p = beta * p
        raxpy (&n_dist, &DONE, computeData->r, &IONE, computeData->p, &IONE);                    // p += r
277
278
279

#if DIRECT_ERROR
        // compute direct error
280
281
282
        rcopy (&n_dist, computeData->x_exact, &IONE, computeData->res_err, &IONE);               // res_err = x_exact
        raxpy (&n_dist, &DMONE, computeData->x, &IONE, computeData->res_err, &IONE);             // res_err -= x
  
283
        // compute inf norm
284
285
        computeData->direct_err = norm_inf(n_dist, computeData->res_err);
        MPI_Allreduce(MPI_IN_PLACE, &computeData->direct_err, 1, MPI_DOUBLE, MPI_MAX, computeData->comm);
286
287

        //        // compute euclidean norm
288
        //        direct_err = rdot (&n_dist, res_err, &IONE, res_err, &IONE);
289
290
291
292
        //        MPI_Allreduce(MPI_IN_PLACE, &direct_err, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
        //        direct_err = sqrt(direct_err);
#endif // DIRECT_ERROR

293
294
295
        computeData->iter++;
        if (computeData->iter == rec_iter) { reconfigure = 1;}
	if (reconfigure) {
296
//          dump(computeData);
297
298
299
	  MAM_Checkpoint(&state, MAM_CHECK_COMPLETION, user_func, (void *) user_data);
	  if(state == MAM_COMPLETED) {
	    reconfigure = 0; 
300
            BiCGStab_free (computeData);
301
            targets_update(computeData, user_data);
302
303
            sizeR = computeData->matL.dim1; 
            n_dist = sizeR;
304
//            dump(computeData);
305
306
	    }
	}
307
308
    }

309
    MPI_Barrier(computeData->comm);
310
311
312
    if (myId == 0) 
        reloj (&t3, &t4);

313
314
    if(state == MAM_PENDING) {
      MAM_Checkpoint(&state, MAM_WAIT_COMPLETION, user_func, (void *) user_data);
315
316
      BiCGStab_free (computeData);
      targets_update(computeData, user_data);
317
318
    }

319
320
321
322
323
324
325
326
327
328
329
330
331
#ifdef SPMV_OPTIMIZED
    // Code required after the loop 
    PermuteInts (mat.vpos, permP, mat.vptr[mat.dim1]);

    // Freeing memory for Permutation
    free (vectDatatypeR); vectDatatypeR = NULL; free (vectDatatypeP); vectDatatypeP = NULL;
    RemoveDoubles (&vecP); RemoveInts (&permP);
    RemoveInts (&vdspR); RemoveInts (&vdimR); RemoveInts (&vdspP); RemoveInts (&vdimP);
    RemoveInts (&ipermP);
#endif

    if (myId == 0) {
        printf ("Size: %d \n", n);
332
333
334
335
        printf ("Iter: %d \n", computeData->iter);
        printf ("Tol: %g \n", computeData->tol);
        printf ("Time_loop: %20.10e\n", (t3-computeData->t1));
        printf ("Time_iter: %20.10e\n", (t3-computeData->t1)/computeData->iter);
336
    }
337
338
339
}

void BiCGStab_free (Compute_data *computeData) {
340

341
    RemoveDoubles (&computeData->x); RemoveDoubles (&computeData->b);
342
343
344
    RemoveDoubles (&computeData->aux); RemoveDoubles (&computeData->s); 
    RemoveDoubles (&computeData->q); RemoveDoubles (&computeData->r); 
    RemoveDoubles (&computeData->p); RemoveDoubles (&computeData->r0); RemoveDoubles (&computeData->y);
345
#if PRECOND
346
347
    RemoveDoubles (&computeData->diags);
    RemoveDoubles(&computeData->p_hat); RemoveDoubles (&computeData->q_hat); 
348
#endif
iker_martin's avatar
iker_martin committed
349
350
351
#if DIRECT_ERROR
    RemoveDoubles (&computeData->res_err); RemoveDoubles (&computeData->x_exact); 
#endif
352
353

    RemoveInts (&computeData->sizes); RemoveInts (&computeData->dspls); 
iker_martin's avatar
iker_martin committed
354
    RemoveInts (&computeData->vlen);
355
356
357
358
359
360
    if (computeData->isOriginal) {
      RemoveSparseMatrix (&computeData->matL);
      computeData->isOriginal = 0;
    } else {
      RemoveSparseMatrix2 (&computeData->matL);
    }
361
362
363
364
365
366
367
368
369
370
}

/*********************************************************************************/

int main (int argc, char **argv) {
    int dim; 
    double *sol1 = NULL, *sol2 = NULL;
    int index = 0, indexL = 0;
    SparseMatrix mat  = {0, 0, NULL, NULL, NULL}, sym = {0, 0, NULL, NULL, NULL};

371
372
    int root = 0, myId, nProcs;
    int isTarget, numTarget, req, initNumP;
373
374
375
    int dimL, dspL, *vdimL = NULL, *vdspL = NULL;
    SparseMatrix matL = {0, 0, NULL, NULL, NULL};
    double *sol1L = NULL, *sol2L = NULL;
376
    double beta;
377

378
379
    int IONE = 1;
    double DMONE = -1.0;
380

381
382
383
    int mat_from_file, nodes, size_param, stencil_points;
    Compute_data computeData;
    user_redist_t user_data;
384
385
386

    /***************************************/

387
    MPI_Init_thread (&argc, &argv, MPI_THREAD_MULTIPLE, &req);
388
389
390
391
392
393

    // Definition of the variables nProcs and myId
    MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
    MPI_Comm_rank(MPI_COMM_WORLD, &myId);
    root = nProcs-1;
    root = 0;
394
395
396
    computeData.myId = myId;
    computeData.numP = nProcs;
    computeData.comm = MPI_COMM_WORLD;
397
    initNumP = computeData.numP; 
398
399
400
    user_data = empty_user_data;
    user_data.comm = computeData.comm;

401
    //prctl(PR_SET_PTRACER, PR_SET_PTRACER_ANY, 0, 0, 0);
402
    isTarget = MAM_Init(root, &computeData.comm, argv[0], user_func, (void *) &user_data);
403

404
405
    if(isTarget) {
      targets_update(&computeData, &user_data);
406
      computeData.isOriginal = 0;
407
//            dump(&computeData);
408
409
410
411
    } else {
    /***************************************/
      if (argc == 4) {
          mat_from_file = atoi(argv[2]);
iker_martin's avatar
iker_martin committed
412
	  numTarget = atoi(argv[3]);
413
414
415
416
417
418
      } else {
          mat_from_file = atoi(argv[2]);
          nodes = atoi(argv[3]);
          size_param = atoi(argv[4]);
          stencil_points = atoi(argv[5]);
      }
419
420
    /***************************************/

421
//      printf ("A\n");
422
423
424
425
426
427
428
429
      CreateInts (&vdimL, nProcs); CreateInts (&vdspL, nProcs); 
      if(mat_from_file) {
          if (myId == root) {
              // Creating the matrix
              ReadMatrixHB (argv[1], &sym);
              TransposeSparseMatrices (sym, 0, &mat, 0);
              dim = mat.dim1;
          }
430
431

        // Distributing the matrix
432
433
434
435
436
437
          dim = DistributeMatrix (mat, index, &matL, indexL, vdimL, vdspL, root, MPI_COMM_WORLD);
          dimL = vdimL[myId]; dspL = vdspL[myId];
          if (myId == root) {
            RemoveSparseMatrix (&mat);
            RemoveSparseMatrix (&sym);
          } 
438
//          printf ("B\n");
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
      }
      else {
          dim = size_param * size_param * size_param;
          int divL, rstL, i;
          divL = (dim / nProcs); rstL = (dim % nProcs);
          for (i=0; i<nProcs; i++) vdimL[i] = divL + (i < rstL);
          vdspL[0] = 0; for (i=1; i<nProcs; i++) vdspL[i] = vdspL[i-1] + vdimL[i-1];
          dimL = vdimL[myId]; dspL = vdspL[myId];
          int band_width = size_param * (size_param + 1) + 1;
          band_width = 100 * nodes;
          long nnz_here = ((long) (stencil_points + 2 * band_width)) * dimL;
          printf ("dimL: %d, nodes: %d, size_param: %d, band_width: %d, stencil_points: %d, nnz_here: %ld\n",
                  dimL, nodes, size_param, band_width, stencil_points, nnz_here);
          allocate_matrix(dimL, dim, nnz_here, &matL);
          generate_Poisson3D_filled(&matL, size_param, stencil_points, band_width, dspL, dimL, dim);

          // To generate ill-conditioned matrices
  //        double factor = 1.0e6;
  //        ScaleFirstRowCol(matL, dspL, dimL, myId, root, factor);
      }
      MPI_Barrier(MPI_COMM_WORLD);

      // Creating the vectors
      CreateDoubles (&sol1, dim);
//      CreateDoubles (&sol2, dim);
      CreateDoubles (&sol1L, dimL);
      CreateDoubles (&sol2L, dimL);

//      InitDoubles (sol2, dim, 0.0, 0.0);
      InitDoubles (sol1L, dimL, 0.0, 0.0);
      InitDoubles (sol2L, dimL, 0.0, 0.0);
470
471
472

    /***************************************/

473
//      printf ("C\n");
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492

      beta = 1.0 / sqrt(dim);
      if(mat_from_file) {
          // compute b = A * x_c, x_c = 1/sqrt(nbrows)
          InitDoubles (sol1, dim, 1.0, 0.0);
          ProdSparseMatrixVectorByRows (matL, 0, sol1, sol1L);                  // s = A * x
          rscal (&dimL, &beta, sol1L, &IONE);                                         // s = beta * s
      } else {
          InitDoubles (sol1, dim, 0.0, 0.0);

          int k=0;
          int *vptrM = matL.vptr;
          for (int i=0; i < matL.dim1; i++) {
              for(int j=vptrM[i]; j<vptrM[i+1]; j++) {
                  sol1L[k] += matL.vval[j];
              }
          }
      }

493
//      printf ("D\n");
494
495
496

//      MPI_Scatterv (sol2, vdimL, vdspL, MPI_DOUBLE, sol2L, dimL, MPI_DOUBLE, root, MPI_COMM_WORLD); //FIXME It does not seem to do anything

497
//      printf ("E\n");
498
499
500
501
502
503
504
505
506
507
      computeData.sizes = vdimL;
      computeData.my_size = dimL;
      computeData.dspls = vdspL;
      computeData.my_dspl = dspL;
      computeData.b = sol1L;
      computeData.x = sol2L;
      computeData.matL = matL;
      computeData.n = computeData.matL.dim2;
      RemoveDoubles (&sol1); 
      BiCGStab_init (&computeData);
508
509
      originals_set_data(&computeData, &user_data, numTarget);
      computeData.isOriginal = 1;
510
511
512
    }


513
    BiCGStab_compute (&computeData, &user_data);
514
515
516
517


    // Error computation ||b-Ax||
//    if(mat_from_file) {
518
        dim = computeData.matL.dim2;
519
520
521
522
523
        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);
524
        raxpy (&computeData.my_size, &DMONE, computeData.x, &IONE, computeData.b, &IONE);          
525
526
        beta = rdot (&computeData.my_size, computeData.b, &IONE, computeData.b, &IONE);
        MPI_Allreduce (MPI_IN_PLACE, &beta, 1, MPI_DOUBLE, MPI_SUM, computeData.comm);
527
528
529
530
531
        
//    } else {
//        // case with x_exact = {1.0}
//        for (int i=0; i<dimL; i++)
//            sol2L[i] -= 1.0;
532
//        beta = rdot (&dimL, sol2L, &IONE, sol2L, &IONE);            
533
534
535
//    } 

    beta = sqrt(beta);
536
    if (computeData.myId == 0) {
537
        printf ("Error: %20.10e\n", beta);
538
539
        print_global_results(computeData.t1);
    }
540
541
542

    /***************************************/
    // Freeing memory
543
    BiCGStab_free (&computeData);
544
    RemoveDoubles (&sol2); 
545
546
547
548
549
    MAM_Finalize ();

    if(initNumP > numTarget && computeData.myId == 0) {
      MPI_Abort(MPI_COMM_WORLD, -100);
    }
550
    if(computeData.comm != MPI_COMM_WORLD && computeData.comm != MPI_COMM_NULL) MPI_Comm_free(&(computeData.comm));
551
552
553
554
555
556

    MPI_Finalize ();

    return 0;
}

557
558
559
560
561
562

/* MAM New functions */

/*
 * Función para declarar los datos a comunicar por parte de MAM
 */
563
void originals_set_data(Compute_data *computeData, user_redist_t *user_data, int num_target) {
564

565
566
567
568
    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);
569
570
571

    MAM_Set_target_number(num_target);

572
573
574
575
576
577
    //MAM_Data_add(&(computeData->n), NULL, 1, MPI_INT, MAM_DATA_REPLICATED, MAM_DATA_CONSTANT);
    //MAM_Data_add(&(computeData->tol0), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_CONSTANT);
    //MAM_Data_add(&(computeData->t1), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_CONSTANT);
    MAM_Data_add(&(computeData->n), NULL, 1, MPI_INT, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    MAM_Data_add(&(computeData->tol0), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    MAM_Data_add(&(computeData->t1), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
578
579
580
581
582
583
584
585

    MAM_Data_add(&(computeData->iter), NULL, 1, MPI_INT, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    MAM_Data_add(&(computeData->tol), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    MAM_Data_add(&(computeData->rho), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
#if DIRECT_ERROR
    MAM_Data_add(&(computeData->direct_err), NULL, 1, MPI_DOUBLE, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
#endif

586
587
588
589
590
591
    //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);

    MAM_Data_add(computeData->r0, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    MAM_Data_add(computeData->b, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
592
#if PRECOND
593
594
    //MAM_Data_add(computeData->diags, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    MAM_Data_add(computeData->diags, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
595
596
#endif
#if DIRECT_ERROR
597
598
    //MAM_Data_add(computeData->x_exact, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    MAM_Data_add(computeData->x_exact, NULL, computeData->n, MPI_DOUBLE, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
599
600
601
602
603
#endif

    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);
604
605
606
607
#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
608

609
610
611
612
613
    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;
614
615
616
617
618
619
620
621
622
623
624
625
}


void targets_update(Compute_data *computeData, user_redist_t *user_data) {
    size_t entry, total_qty;
    void *value = NULL;
    MPI_Datatype type;

    MPI_Comm_size(computeData->comm, &computeData->numP);
    MPI_Comm_rank(computeData->comm, &computeData->myId);

    entry = 0;
626
    /*
627
628
629
630
631
632
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_CONSTANT);
    computeData->n = *((int *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_CONSTANT);
    computeData->tol0 = *((double *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_CONSTANT);
    computeData->t1 = *((double *)value);
633
634
635
636
637
638
639
    */
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->n = *((int *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->tol0 = *((double *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->t1 = *((double *)value);
640

641
//    entry = 0;
642
643
644
645
646
647
648
649
650
651
652
653
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->iter = *((int *)value); 
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->tol = *((double *)value); 
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->rho = *((double *)value); 
#if DIRECT_ERROR
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_REPLICATED, MAM_DATA_VARIABLE);
    computeData->direct_err = *((double *)value); 
#endif

    entry = 0;
654
    /*
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    computeData->vlen = ((int *)value);
    //computeData->vlen = user_data->recv_vlen;
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    computeData->r0 = ((double *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    computeData->b = ((double *)value);
#if PRECOND
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    computeData->diags = ((double *)value);
#endif
#if DIRECT_ERROR
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_CONSTANT);
    computeData->x_exact = ((double *)value);
#endif
670
671
672
673
674
675
676
677
678
679
680
681
682
683
    */
    computeData->vlen = user_data->recv_vlen;
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->r0 = ((double *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->b = ((double *)value);
#if PRECOND
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->diags = ((double *)value);
#endif
#if DIRECT_ERROR
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->x_exact = ((double *)value);
#endif
684

685
//    entry = 0;
686
687
688
689
690
691
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->p = ((double *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->r = ((double *)value);
    MAM_Data_get_pointer(&value, entry++, &total_qty, &type, MAM_DATA_DISTRIBUTED, MAM_DATA_VARIABLE);
    computeData->x = ((double *)value);
692
693
694
695
696
697
#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
698
699
700
701
  
    int n = computeData->n;
    CreateInts (&computeData->sizes, computeData->numP); 
    CreateInts (&computeData->dspls, computeData->numP); 
702
703
704
705
706
707
    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;
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
    CreateDoubles (&computeData->s, n_dist);
    CreateDoubles (&computeData->q, n_dist);
    CreateDoubles (&computeData->y, n_dist);
    CreateDoubles (&computeData->aux, n); 
#if DIRECT_ERROR
    CreateDoubles (&computeData->res_err, n_dist);
#endif

    *user_data = empty_user_data;
    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;
    user_data->comm = computeData->comm;
}


void user_func(void *args) {
    int local_flag, flag = 0;
    mam_user_reconf_t user_reconf;

    MAM_Get_Reconf_Info(&user_reconf);
    user_redist_t *user_data = (user_redist_t *) args;
    if(!user_data->initiated) {
732
733
734
      targets_distribution_synch(user_reconf, user_data);
      flag = 1;
      /*
735
736
737
738
739
740
741
      targets_distribution(user_reconf, user_data);
      user_data->initiated = 1;

      if(user_reconf.rank_state == MAM_PROC_NEW_RANK) {
        MPI_Waitall(2, user_data->reqs, MPI_STATUSES_IGNORE);
	flag = 1;
      }
742
      */
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
    } else {
      MPI_Testall(2, user_data->reqs, &local_flag, MPI_STATUSES_IGNORE);
      MPI_Allreduce(&local_flag, &flag, 1, MPI_INT, MPI_MIN, user_data->comm);
    }

    if(flag) MAM_Resume_redistribution(NULL);
}


void dump(Compute_data *computeData) {
  int i;

  if(computeData->myId == 0) printf("TamBL="); 
  fflush(stdout); MPI_Barrier(computeData->comm);
  for(i=0; i<computeData->numP; i++) {
    if(computeData->myId == i) {
      printf("%d, ", computeData->my_size);
    }
    fflush(stdout);
    sleep(1);
    MPI_Barrier(computeData->comm);
  }

766
  if(computeData->myId == 0) printf("\nVlen="); 
767
768
769
770
771
772
773
774
775
776
777
778
779
  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("%d, ", computeData->vlen[j]);
      }

    }
    fflush(stdout);
    sleep(1);
    MPI_Barrier(computeData->comm);
  }
iker_martin's avatar
iker_martin committed
780

781
  if(computeData->myId == 0) printf("\nVptr="); 
iker_martin's avatar
iker_martin committed
782
783
784
785
786
787
788
789
790
791
792
793
794
795
  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);
  }

796
  if(computeData->myId == 0) printf("\nVpos="); 
iker_martin's avatar
iker_martin committed
797
798
799
800
801
802
803
804
805
806
807
808
809
810
  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);
  }

811
  if(computeData->myId == 0) printf("\nVval="); 
iker_martin's avatar
iker_martin committed
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
  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);
  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);
  }
930

iker_martin's avatar
iker_martin committed
931
  if(computeData->myId == 0) printf("\nq_hat="); 
932
  fflush(stdout); MPI_Barrier(computeData->comm);
iker_martin's avatar
iker_martin committed
933
934
935
936
937
938
939
940
941
942
943
944
  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);
  }
945
/*
iker_martin's avatar
iker_martin committed
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
  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);
  }
  */
976
}
iker_martin's avatar
iker_martin committed
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005

/*
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;
*/