Subversion Repositories slepc-dev

Rev

Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1960 eromero 1
 
2
#include "petscmat.h"
3
#include "private/vecimpl.h"          /*I  "petscvec.h"   I*/
4
#include "veccomp_private.h"
5
#include "veccomp.h"
6
#include "../src/vec/vec/impls/dvecimpl.h"
7
#include "../src/mat/impls/aij/seq/aij.h"
8
#include "../src/mat/impls/aij/mpi/mpiaij.h"
9
 
10
typedef struct {
1965 eromero 11
  PetscInt      n,        /* number of active subvectors */
12
                N,        /* virtual global size */
13
                lN,       /* virtual local size */
14
                friends;  /* number of vectors sharing this structure */
15
} Vec_Comp_N;
16
 
17
typedef struct {
1960 eromero 18
  Vec           *x;       /* the vectors */
1965 eromero 19
  PetscInt      nx;       /* number of available subvectors */
20
  Vec_Comp_N    *n;       /* structure shared by friend vectors */
1960 eromero 21
} Vec_Comp;
22
 
1965 eromero 23
#if defined(PETSC_USE_DEBUG)
24
#define PetscValidVecComp(x) \
25
  if (((Vec_Comp*)(x)->data)->nx < ((Vec_Comp*)(x)->data)->n->n) { \
26
    return PetscError(__LINE__,__FUNCT__,__FILE__,__SDIR__,1,0,"Invalid number of subvectors required!");}
27
#else
28
#define PetscValidVecComp(x)
29
#endif
30
 
31
static PetscErrorCode VecCreate_Comp_Private(Vec v, Vec *x, PetscInt nx,
32
                                             PetscTruth x_to_me, Vec_Comp_N* n);
33
 
1960 eromero 34
#include "veccomp0.h"
35
 
36
#define __WITH_MPI__
37
#include "veccomp0.h"
38
 
39
#undef __FUNCT__  
40
#define __FUNCT__ "VecRegistre_Comp"
41
PetscErrorCode PETSCVEC_DLLEXPORT VecRegister_Comp(const char path[])
42
{
43
  PetscErrorCode ierr;
44
 
45
  PetscFunctionBegin;
46
 
47
  ierr = VecRegisterDynamic(VECCOMP, path, "VecCreate_Comp", VecCreate_Comp);
48
  CHKERRQ(ierr);
49
 
50
  PetscFunctionReturn(0);
51
}
52
 
53
 
54
#undef __FUNCT__  
55
#define __FUNCT__ "VecDestroy_Comp"
56
PetscErrorCode VecDestroy_Comp(Vec v)
57
{
58
  Vec_Comp       *vs = (Vec_Comp*)v->data;
59
  PetscInt       i;
60
  PetscErrorCode ierr;
61
 
62
  PetscFunctionBegin;
63
 
64
  /* if memory was published with AMS then destroy it */
65
  ierr = PetscObjectDepublish(v);CHKERRQ(ierr);
66
 
67
#if defined(PETSC_USE_LOG)
68
  PetscLogObjectState((PetscObject)v,"Length=%D",v->map->n);
69
#endif
70
  for(i=0; i<vs->nx; i++) {
71
    ierr = VecDestroy(vs->x[i]); CHKERRQ(ierr);
72
  }
1965 eromero 73
  if(--vs->n->friends <= 0) {
74
    ierr = PetscFree(vs->n); CHKERRQ(ierr);
75
  }
1960 eromero 76
  ierr = PetscFree(vs->x); CHKERRQ(ierr);
77
  ierr = PetscFree(vs); CHKERRQ(ierr);
78
 
79
  PetscFunctionReturn(0);
80
}
81
 
82
 
83
static struct _VecOps DvOps = {VecDuplicate_Comp, /* 1 */
84
            VecDuplicateVecs_Default,
85
            VecDestroyVecs_Default,
86
            VecDot_Comp_MPI,
87
            VecMDot_Comp_MPI,
88
            VecNorm_Comp_MPI,
89
            0,
90
            0,
91
            VecScale_Comp,
92
            VecCopy_Comp, /* 10 */
93
            VecSet_Comp,
94
            VecSwap_Comp,
95
            VecAXPY_Comp,
96
            VecAXPBY_Comp,
97
            VecMAXPY_Comp,
98
            VecAXPY_Comp/*VecAYPX_Comp*/,
99
            VecWAXPY_Comp,
100
            VecAXPBYPCZ_Comp,
101
            VecPointwiseMult_Comp,
102
            VecPointwiseDivide_Comp,
103
            0, /* 20 */
104
            0,0,
105
 
106
            VecGetSize_Comp,
2009 eromero 107
            VecGetLocalSize_Comp,
1960 eromero 108
            0/*VecRestoreArray_Seq*/,
109
            VecMax_Comp,
110
            VecMin_Comp,
111
            VecSetRandom_Comp,
112
            0, /* 30 */
113
            0,
114
            VecDestroy_Comp,
115
            VecView_Comp,
116
            0/*VecPlaceArray_Seq*/,
117
            0/*VecReplaceArray_Seq*/,
118
            VecDot_Comp_Seq,
119
            0,
120
            VecNorm_Comp_Seq,
121
            VecMDot_Comp_Seq,
122
            0, /* 40 */
123
            0,
124
            0, /* VecLoadIntoVectorNative */
125
            VecReciprocal_Comp,
126
            0, /* VecViewNative */
127
            VecConjugate_Comp,
128
            0,0,
129
            0/*VecResetArray_Seq*/,
130
            0,
131
            VecMaxPointwiseDivide_Comp,
132
            0/*VecLoad_Binary*/, /* 50 */
133
            VecPointwiseMax_Comp,
134
            VecPointwiseMaxAbs_Comp,
135
            VecPointwiseMin_Comp,
136
            0,
137
            VecSqrt_Comp,
138
            VecAbs_Comp,
139
            VecExp_Comp,
2010 eromero 140
            VecLog_Comp,
141
            0/*VecShift_Comp*/,
142
            0,
143
            VecDotNorm2_Comp_MPI
1960 eromero 144
          };
145
 
146
#undef __FUNCT__  
147
#define __FUNCT__ "VecCreate_Comp_Private"
148
static PetscErrorCode VecCreate_Comp_Private(Vec v, Vec *x, PetscInt nx,
1965 eromero 149
                                             PetscTruth x_to_me, Vec_Comp_N *n)
1960 eromero 150
{
151
  Vec_Comp        *s;
152
  PetscErrorCode  ierr;
1965 eromero 153
  PetscInt        N=0, lN=0, i, k;
1960 eromero 154
 
155
  PetscFunctionBegin;
156
 
1965 eromero 157
  /* Allocate a new Vec_Comp */
1960 eromero 158
  if (v->data) { ierr = PetscFree(v->data); CHKERRQ(ierr); }
159
  ierr = PetscNewLog(v, Vec_Comp, &s); CHKERRQ(ierr);
160
  ierr = PetscMemcpy(v->ops, &DvOps, sizeof(DvOps)); CHKERRQ(ierr);
161
  v->data  = (void*)s;
162
  v->petscnative     = PETSC_FALSE;
1965 eromero 163
 
164
  /* Allocate the array of Vec, if it is needed to be done */
1960 eromero 165
  if (x_to_me != PETSC_TRUE) {
166
    ierr = PetscMalloc(sizeof(Vec)*nx, &s->x); CHKERRQ(ierr);
167
    ierr = PetscMemcpy(s->x, x, sizeof(Vec)*nx); CHKERRQ(ierr);
168
  } else
169
    s->x = x;
1965 eromero 170
 
1960 eromero 171
  s->nx = nx;
172
  for(i=0; i<nx; i++) {
1965 eromero 173
    ierr = VecGetSize(x[i], &k); CHKERRQ(ierr); N+= k;
1960 eromero 174
    ierr = VecGetLocalSize(x[i], &k); CHKERRQ(ierr); lN+= k;
175
  }
1965 eromero 176
 
177
  /* Allocate the shared structure, if it is not given */
178
  if (!n) {
179
    ierr = PetscNewLog(v, Vec_Comp_N, &n); CHKERRQ(ierr);
180
    s->n = n;
181
    n->n = nx;
182
    n->N = N;
183
    n->lN = lN;
184
    n->friends = 1;
185
  }
186
 
187
  /* If not, check in the vector in the shared structure */
188
  else {
189
    s->n = n;
190
    s->n->friends++;
191
    s->n->n = nx;
192
  }
193
 
194
  /* Set the virtual sizes as the real sizes of the vector */
195
  ierr = VecSetSizes(v, s->n->lN, s->n->N); CHKERRQ(ierr);
196
 
1960 eromero 197
  ierr = PetscObjectChangeTypeName((PetscObject)v,VECCOMP); CHKERRQ(ierr);
198
  ierr = PetscPublishAll(v); CHKERRQ(ierr);
199
 
200
  PetscFunctionReturn(0);
201
}
202
 
203
 
204
EXTERN_C_BEGIN
205
#undef __FUNCT__  
206
#define __FUNCT__ "VecCreate_Comp"
207
PetscErrorCode PETSCVEC_DLLEXPORT VecCreate_Comp(Vec V)
208
{
209
  PetscErrorCode  ierr;
210
 
211
  PetscFunctionBegin;
212
 
1965 eromero 213
  ierr = VecCreate_Comp_Private(V, PETSC_NULL, 0, PETSC_FALSE, PETSC_NULL);
214
  CHKERRQ(ierr);
1960 eromero 215
 
216
  PetscFunctionReturn(0);
217
}
218
EXTERN_C_END
219
 
220
 
221
EXTERN_C_BEGIN
222
#undef __FUNCT__  
223
#define __FUNCT__ "VecCreateComp"
224
PetscErrorCode PETSCVEC_DLLEXPORT VecCreateComp(MPI_Comm comm, PetscInt *Nx,
1965 eromero 225
                                                PetscInt n, const VecType t,
226
                                                Vec Vparent, Vec *V)
1960 eromero 227
{
228
  PetscErrorCode  ierr;
229
  Vec             *x;
230
  PetscInt        i;
231
 
232
  PetscFunctionBegin;
233
 
234
  ierr = VecCreate(comm, V); CHKERRQ(ierr);
235
  ierr = PetscMalloc(sizeof(Vec)*n, &x); CHKERRQ(ierr);
236
  for(i=0; i<n; i++) {
237
    ierr = VecCreate(comm, &x[i]); CHKERRQ(ierr);
238
    ierr = VecSetSizes(x[i], PETSC_DECIDE, Nx[i]); CHKERRQ(ierr);
239
    ierr = VecSetType(x[i], t); CHKERRQ(ierr);
240
  }
1965 eromero 241
  ierr = VecCreate_Comp_Private(*V, x, n, PETSC_TRUE,
242
                           Vparent?((Vec_Comp*)Vparent->data)->n:PETSC_NULL);
243
  CHKERRQ(ierr);
1960 eromero 244
 
245
  PetscFunctionReturn(0);
246
}
247
EXTERN_C_END
248
 
249
EXTERN_C_BEGIN
250
#undef __FUNCT__  
251
#define __FUNCT__ "VecCreateCompWithVec"
252
PetscErrorCode PETSCVEC_DLLEXPORT VecCreateCompWithVecs(Vec *x, PetscInt n,
1965 eromero 253
                                                        Vec Vparent, Vec *V)
1960 eromero 254
{
255
  PetscErrorCode  ierr;
256
  PetscInt        i;
257
 
258
  PetscFunctionBegin;
259
 
260
  ierr = VecCreate(((PetscObject)x[0])->comm, V); CHKERRQ(ierr);
261
  for(i=0; i<n; i++) {
262
    ierr = PetscObjectReference((PetscObject)x[i]); CHKERRQ(ierr);
263
  }
1965 eromero 264
  ierr = VecCreate_Comp_Private(*V, x, n, PETSC_FALSE,
265
                           Vparent?((Vec_Comp*)Vparent->data)->n:PETSC_NULL);
266
  CHKERRQ(ierr);
1960 eromero 267
 
268
  PetscFunctionReturn(0);
269
}
270
EXTERN_C_END
271
 
272
 
273
EXTERN_C_BEGIN
274
#undef __FUNCT__  
275
#define __FUNCT__ "VecDuplicate_Comp"
276
PetscErrorCode VecDuplicate_Comp(Vec win, Vec *V)
277
{
278
  PetscErrorCode  ierr;
279
  Vec             *x;
280
  PetscInt        i;
281
  Vec_Comp        *s = (Vec_Comp*)win->data;
282
 
283
  PetscFunctionBegin;
284
 
1965 eromero 285
  PetscValidVecComp(win);
286
 
1960 eromero 287
  ierr = VecCreate(((PetscObject)win)->comm, V); CHKERRQ(ierr);
288
  ierr = PetscMalloc(sizeof(Vec)*s->nx, &x); CHKERRQ(ierr);
289
  for(i=0; i<s->nx; i++) {
290
    ierr = VecDuplicate(s->x[i], &x[i]); CHKERRQ(ierr);
291
  }
1965 eromero 292
  ierr = VecCreate_Comp_Private(*V, x, s->nx, PETSC_TRUE, s->n); CHKERRQ(ierr);
1960 eromero 293
 
294
  PetscFunctionReturn(0);
295
}
296
EXTERN_C_END
297
 
298
 
299
EXTERN_C_BEGIN
300
#undef __FUNCT__  
301
#define __FUNCT__ "VecCompGetVecs"
302
PetscErrorCode VecCompGetVecs(Vec win, const Vec **x, PetscInt *n)
303
{
304
  Vec_Comp        *s = (Vec_Comp*)win->data;
305
 
306
  PetscFunctionBegin;
307
 
1965 eromero 308
  PetscValidVecComp(win);
309
 
1960 eromero 310
  if(x) *x = s->x;
311
  if(n) *n = s->nx;
312
 
313
  PetscFunctionReturn(0);
314
}
315
EXTERN_C_END
316
 
317
 
318
EXTERN_C_BEGIN
319
#undef __FUNCT__  
1965 eromero 320
#define __FUNCT__ "VecCompSetVecs"
321
PetscErrorCode VecCompSetVecs(Vec win, Vec *x, PetscInt n)
322
{
323
  Vec_Comp        *s = (Vec_Comp*)win->data;
324
  PetscErrorCode  ierr;
325
 
326
  PetscFunctionBegin;
327
 
328
  PetscValidVecComp(win);
329
 
330
  if(x) {
331
    if (n > s->nx) {
332
      ierr = PetscFree(s->x); CHKERRQ(ierr);
333
      ierr = PetscMalloc(sizeof(Vec)*n, &s->x); CHKERRQ(ierr);
334
    }
335
    ierr = PetscMemcpy(s->x, x, sizeof(Vec)*n); CHKERRQ(ierr);
336
    s->nx = n;
337
  }
338
  s->n->n = n;
339
 
340
  PetscFunctionReturn(0);
341
}
342
EXTERN_C_END
343
 
344
 
345
EXTERN_C_BEGIN
346
#undef __FUNCT__  
1960 eromero 347
#define __FUNCT__ "VecAXPY_Comp"
348
PetscErrorCode VecAXPY_Comp(Vec v, PetscScalar alpha, Vec w)
349
{
350
  PetscErrorCode  ierr;
351
  Vec_Comp        *vs = (Vec_Comp*)v->data,
352
                  *ws = (Vec_Comp*)w->data;
353
  PetscInt        i;
354
 
355
  PetscFunctionBegin;
356
 
1965 eromero 357
  PetscValidVecComp(v);
358
  PetscValidVecComp(w);
359
 
360
  for(i=0; i<vs->n->n; i++) {
1960 eromero 361
    ierr = VecAXPY(vs->x[i], alpha, ws->x[i]); CHKERRQ(ierr);
362
  }
363
 
364
  PetscFunctionReturn(0);
365
}
366
EXTERN_C_END
367
 
368
 
369
EXTERN_C_BEGIN
370
#undef __FUNCT__  
371
#define __FUNCT__ "VecAXPBY_Comp"
372
PetscErrorCode VecAXPBY_Comp(Vec v, PetscScalar alpha, PetscScalar beta, Vec w)
373
{
374
  PetscErrorCode  ierr;
375
  Vec_Comp        *vs = (Vec_Comp*)v->data,
376
                  *ws = (Vec_Comp*)w->data;
377
  PetscInt        i;
378
 
379
  PetscFunctionBegin;
380
 
1965 eromero 381
  PetscValidVecComp(v);
382
  PetscValidVecComp(w);
383
 
384
  for(i=0; i<vs->n->n; i++) {
1960 eromero 385
    ierr = VecAXPBY(vs->x[i], alpha, beta, ws->x[i]); CHKERRQ(ierr);
386
  }
387
 
388
  PetscFunctionReturn(0);
389
}
390
EXTERN_C_END
391
 
392
 
393
EXTERN_C_BEGIN
394
#undef __FUNCT__  
395
#define __FUNCT__ "VecMAXPY_Comp"
396
PetscErrorCode VecMAXPY_Comp(Vec v, PetscInt n, const PetscScalar *alpha,
397
                             Vec *w)
398
{
399
  PetscErrorCode  ierr;
400
  Vec_Comp        *vs = (Vec_Comp*)v->data;
401
  Vec             *wx;
402
  PetscInt        i, j;
403
 
404
  PetscFunctionBegin;
405
 
1965 eromero 406
  PetscValidVecComp(v);
407
  for(i=0; i<n; i++) PetscValidVecComp(w[i]);
408
 
1960 eromero 409
  ierr = PetscMalloc(sizeof(Vec)*n, &wx); CHKERRQ(ierr);
410
 
1965 eromero 411
  for(j=0; j<vs->n->n; j++) {
1960 eromero 412
    for(i=0; i<n; i++) wx[i] = ((Vec_Comp*)w[i]->data)->x[j];
413
    ierr = VecMAXPY(vs->x[j], n, alpha, wx); CHKERRQ(ierr);
414
  }
415
 
416
  ierr = PetscFree(wx); CHKERRQ(ierr);
417
 
418
  PetscFunctionReturn(0);
419
}
420
EXTERN_C_END
421
 
422
 
423
EXTERN_C_BEGIN
424
#undef __FUNCT__  
425
#define __FUNCT__ "VecWAXPY_Comp"
426
PetscErrorCode VecWAXPY_Comp(Vec v, PetscScalar alpha, Vec w, Vec z)
427
{
428
  PetscErrorCode  ierr;
429
  Vec_Comp        *vs = (Vec_Comp*)v->data,
430
                  *ws = (Vec_Comp*)w->data,
431
                  *zs = (Vec_Comp*)z->data;
432
  PetscInt        i;
433
 
434
  PetscFunctionBegin;
435
 
1965 eromero 436
  PetscValidVecComp(v);
437
  PetscValidVecComp(w);
438
  PetscValidVecComp(z);
439
 
440
  for(i=0; i<vs->n->n; i++) {
1960 eromero 441
    ierr = VecWAXPY(vs->x[i], alpha, ws->x[i], zs->x[i]); CHKERRQ(ierr);
442
  }
443
 
444
  PetscFunctionReturn(0);
445
}
446
EXTERN_C_END
447
 
448
 
449
EXTERN_C_BEGIN
450
#undef __FUNCT__  
451
#define __FUNCT__ "VecAXPBYPCZ_Comp"
452
PetscErrorCode VecAXPBYPCZ_Comp(Vec v, PetscScalar alpha, PetscScalar beta,
453
                                PetscScalar gamma, Vec w, Vec z)
454
{
455
  PetscErrorCode  ierr;
456
  Vec_Comp        *vs = (Vec_Comp*)v->data,
457
                  *ws = (Vec_Comp*)w->data,
458
                  *zs = (Vec_Comp*)z->data;
459
  PetscInt        i;
460
 
461
  PetscFunctionBegin;
462
 
1965 eromero 463
  PetscValidVecComp(v);
464
  PetscValidVecComp(w);
465
  PetscValidVecComp(z);
466
 
467
  for(i=0; i<vs->n->n; i++) {
1960 eromero 468
    ierr = VecAXPBYPCZ(vs->x[i], alpha, beta, gamma, ws->x[i], zs->x[i]);
469
    CHKERRQ(ierr);
470
  }
471
 
472
  PetscFunctionReturn(0);
473
}
474
EXTERN_C_END
475
 
476
 
477
EXTERN_C_BEGIN
478
#undef __FUNCT__  
479
#define __FUNCT__ "VecGetSize_Comp"
480
PetscErrorCode VecGetSize_Comp(Vec v, PetscInt *size)
481
{
482
  Vec_Comp        *vs = (Vec_Comp*)v->data;
483
 
484
  PetscFunctionBegin;
485
 
1965 eromero 486
  PetscValidVecComp(v);
1960 eromero 487
 
1965 eromero 488
  if (size) *size = vs->n->N;
489
 
1960 eromero 490
  PetscFunctionReturn(0);
491
}
492
EXTERN_C_END
493
 
494
 
495
EXTERN_C_BEGIN
496
#undef __FUNCT__  
2009 eromero 497
#define __FUNCT__ "VecGetLocalSize_Comp"
498
PetscErrorCode VecGetLocalSize_Comp(Vec v, PetscInt *size)
499
{
500
  Vec_Comp        *vs = (Vec_Comp*)v->data;
501
 
502
  PetscFunctionBegin;
503
 
504
  PetscValidVecComp(v);
505
 
506
  if (size) *size = vs->n->lN;
507
 
508
  PetscFunctionReturn(0);
509
}
510
EXTERN_C_END
511
 
512
 
513
 
514
EXTERN_C_BEGIN
515
#undef __FUNCT__  
1960 eromero 516
#define __FUNCT__ "VecMax_Comp"
517
PetscErrorCode VecMax_Comp(Vec v, PetscInt *idx, PetscReal *z)
518
{
519
  PetscErrorCode  ierr;
520
  Vec_Comp        *vs = (Vec_Comp*)v->data;
521
  PetscInt        idxp, s=0, s0;
522
  PetscReal       zp, z0;
523
  PetscInt        i;
524
 
525
  PetscFunctionBegin;
526
 
1965 eromero 527
  PetscValidVecComp(v);
528
 
1960 eromero 529
  if(!idx && !z)
530
    PetscFunctionReturn(0);
531
 
1965 eromero 532
  if (vs->n->n > 0) {
1960 eromero 533
    ierr = VecMax(vs->x[0], idx?&idxp:PETSC_NULL, &zp); CHKERRQ(ierr);
534
  }
1965 eromero 535
  for (i=1; i<vs->n->n; i++) {
1960 eromero 536
    ierr = VecGetSize(vs->x[i-1], &s0); CHKERRQ(ierr); s+= s0;
537
    ierr = VecMax(vs->x[i], idx?&idxp:PETSC_NULL, &z0); CHKERRQ(ierr);
538
    if(zp < z0) {
539
      if(idx) *idx = s+idxp;
540
      zp = z0;
541
    }
542
  }
543
  if (z) *z = zp;
544
 
545
  PetscFunctionReturn(0);
546
}
547
EXTERN_C_END
548
 
549
 
550
EXTERN_C_BEGIN
551
#undef __FUNCT__  
552
#define __FUNCT__ "VecMin_Comp"
553
PetscErrorCode VecMin_Comp(Vec v, PetscInt *idx, PetscReal *z)
554
{
555
  PetscErrorCode  ierr;
556
  Vec_Comp        *vs = (Vec_Comp*)v->data;
557
  PetscInt        idxp, s=0, s0;
558
  PetscReal       zp, z0;
559
  PetscInt        i;
560
 
561
  PetscFunctionBegin;
562
 
1965 eromero 563
  PetscValidVecComp(v);
564
 
1960 eromero 565
  if(!idx && !z)
566
    PetscFunctionReturn(0);
567
 
1965 eromero 568
  if (vs->n->n > 0) {
1960 eromero 569
    ierr = VecMin(vs->x[0], idx?&idxp:PETSC_NULL, &zp); CHKERRQ(ierr);
570
  }
1965 eromero 571
  for (i=1; i<vs->n->n; i++) {
1960 eromero 572
    ierr = VecGetSize(vs->x[i-1], &s0); CHKERRQ(ierr); s+= s0;
573
    ierr = VecMin(vs->x[i], idx?&idxp:PETSC_NULL, &z0); CHKERRQ(ierr);
574
    if(zp > z0) {
575
      if(idx) *idx = s+idxp;
576
      zp = z0;
577
    }
578
  }
579
  if (z) *z = zp;
580
 
581
  PetscFunctionReturn(0);
582
}
583
EXTERN_C_END
584
 
585
 
586
EXTERN_C_BEGIN
587
#undef __FUNCT__  
588
#define __FUNCT__ "VecMaxPointwiseDivide_Comp"
589
PetscErrorCode VecMaxPointwiseDivide_Comp(Vec v, Vec w, PetscReal *m)
590
{
591
  PetscErrorCode  ierr;
592
  Vec_Comp        *vs = (Vec_Comp*)v->data,
593
                  *ws = (Vec_Comp*)w->data;
594
  PetscReal       work;
595
  PetscInt        i;
596
 
597
  PetscFunctionBegin;
598
 
1965 eromero 599
  PetscValidVecComp(v);
600
  PetscValidVecComp(w);
601
 
602
  if(!m || vs->n->n == 0)
1960 eromero 603
    PetscFunctionReturn(0);
604
  ierr = VecMaxPointwiseDivide(vs->x[0], ws->x[0], m); CHKERRQ(ierr);
1965 eromero 605
  for (i=1; i<vs->n->n; i++) {
1960 eromero 606
    ierr = VecMaxPointwiseDivide(vs->x[i], ws->x[i], &work); CHKERRQ(ierr);
607
    *m = PetscMax(*m, work);
608
  }
609
 
610
  PetscFunctionReturn(0);
611
}
612
EXTERN_C_END
613
 
614
 
615
#define __QUOTEME__(x) #x
616
#define __COMPOSE2__(A,B) A##B
617
#define __COMPOSE3__(A,B,C) A##B##C
618
 
619
#define __FUNC_TEMPLATE1__(NAME) \
620
EXTERN_C_BEGIN \
621
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v) \
622
{ \
623
  PetscErrorCode  ierr; \
624
  Vec_Comp        *vs = (Vec_Comp*)v->data; \
625
  PetscInt        i; \
626
\
627
  PetscFunctionBegin; \
628
\
1965 eromero 629
  PetscValidVecComp(v); \
630
\
631
  for(i=0; i<vs->n->n; i++) { \
1960 eromero 632
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i]); CHKERRQ(ierr); \
633
  } \
634
\
635
  PetscFunctionReturn(0);\
636
} \
637
EXTERN_C_END \
638
 
639
#undef __FUNCT__  
640
#define __FUNCT__ "VecConjugate_Comp"
641
__FUNC_TEMPLATE1__(Conjugate)
642
 
643
#undef __FUNCT__  
644
#define __FUNCT__ "VecReciprocal_Comp"
645
__FUNC_TEMPLATE1__(Reciprocal)
646
 
647
#undef __FUNCT__  
648
#define __FUNCT__ "VecSqrt_Comp"
649
__FUNC_TEMPLATE1__(Sqrt)
650
 
651
#undef __FUNCT__  
652
#define __FUNCT__ "VecAbs_Comp"
653
__FUNC_TEMPLATE1__(Abs)
654
 
655
#undef __FUNCT__  
656
#define __FUNCT__ "VecExp_Comp"
657
__FUNC_TEMPLATE1__(Exp)
658
 
659
#undef __FUNCT__  
660
#define __FUNCT__ "VecLog_Comp"
661
__FUNC_TEMPLATE1__(Log)
662
 
663
 
664
#define __FUNC_TEMPLATE2__(NAME,T0) \
665
EXTERN_C_BEGIN \
666
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v, T0 __a) \
667
{ \
668
  PetscErrorCode  ierr; \
669
  Vec_Comp        *vs = (Vec_Comp*)v->data; \
670
  PetscInt        i; \
671
\
672
  PetscFunctionBegin; \
673
\
1965 eromero 674
  PetscValidVecComp(v); \
675
\
676
  for(i=0; i<vs->n->n; i++) { \
1960 eromero 677
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i], __a); CHKERRQ(ierr); \
678
  } \
679
\
680
  PetscFunctionReturn(0);\
681
} \
682
EXTERN_C_END \
683
 
684
#undef __FUNCT__  
685
#define __FUNCT__ "VecSet_Comp"
686
__FUNC_TEMPLATE2__(Set, PetscScalar)
687
 
688
#undef __FUNCT__  
689
#define __FUNCT__ "VecView_Comp"
690
__FUNC_TEMPLATE2__(View, PetscViewer)
691
 
692
#undef __FUNCT__  
693
#define __FUNCT__ "VecScale_Comp"
694
__FUNC_TEMPLATE2__(Scale, PetscScalar)
695
 
696
#undef __FUNCT__  
697
#define __FUNCT__ "VecSetRandom_Comp"
698
__FUNC_TEMPLATE2__(SetRandom, PetscRandom)
699
 
700
#undef __FUNCT__  
701
#define __FUNCT__ "VecShift_Comp"
702
__FUNC_TEMPLATE2__(Shift, PetscScalar)
703
 
704
 
705
#define __FUNC_TEMPLATE3__(NAME) \
706
EXTERN_C_BEGIN \
707
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v, Vec w) \
708
{ \
709
  PetscErrorCode  ierr; \
710
  Vec_Comp        *vs = (Vec_Comp*)v->data, \
711
                  *ws = (Vec_Comp*)w->data; \
712
  PetscInt        i; \
713
\
714
  PetscFunctionBegin; \
715
\
1965 eromero 716
  PetscValidVecComp(v); \
717
  PetscValidVecComp(w); \
718
\
719
  for(i=0; i<vs->n->n; i++) { \
1960 eromero 720
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i], ws->x[i]); CHKERRQ(ierr); \
721
  } \
722
\
723
  PetscFunctionReturn(0);\
724
} \
725
EXTERN_C_END \
726
 
727
#undef __FUNCT__  
728
#define __FUNCT__ "VecCopy_Comp"
729
__FUNC_TEMPLATE3__(Copy)
730
 
731
#undef __FUNCT__  
732
#define __FUNCT__ "VecSwap_Comp"
733
__FUNC_TEMPLATE3__(Swap)
734
 
735
 
736
#define __FUNC_TEMPLATE4__(NAME) \
737
EXTERN_C_BEGIN \
738
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v, Vec w, Vec z) \
739
{ \
740
  PetscErrorCode  ierr; \
741
  Vec_Comp        *vs = (Vec_Comp*)v->data, \
742
                  *ws = (Vec_Comp*)w->data, \
743
                  *zs = (Vec_Comp*)z->data; \
744
  PetscInt        i; \
745
\
746
  PetscFunctionBegin; \
747
\
1965 eromero 748
  PetscValidVecComp(v); \
749
  PetscValidVecComp(w); \
750
  PetscValidVecComp(z); \
751
\
752
  for(i=0; i<vs->n->n; i++) { \
1960 eromero 753
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i], ws->x[i], zs->x[i]); \
754
    CHKERRQ(ierr); \
755
  } \
756
\
757
  PetscFunctionReturn(0);\
758
} \
759
EXTERN_C_END \
760
 
761
#undef __FUNCT__  
762
#define __FUNCT__ "VecPointwiseMax_Comp"
763
__FUNC_TEMPLATE4__(PointwiseMax)
764
 
765
#undef __FUNCT__  
766
#define __FUNCT__ "VecPointwiseMaxAbs_Comp"
767
__FUNC_TEMPLATE4__(PointwiseMaxAbs)
768
 
769
#undef __FUNCT__  
770
#define __FUNCT__ "VecPointwiseMin_Comp"
771
__FUNC_TEMPLATE4__(PointwiseMin)
772
 
773
#undef __FUNCT__  
774
#define __FUNCT__ "VecPointwiseMult_Comp"
775
__FUNC_TEMPLATE4__(PointwiseMult)
776
 
777
#undef __FUNCT__  
778
#define __FUNCT__ "VecPointwiseDivide_Comp"
779
__FUNC_TEMPLATE4__(PointwiseDivide)