Subversion Repositories slepc-dev

Rev

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

Rev Author Line No. Line
2110 jroman 1
/*
2
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3
   SLEPc - Scalable Library for Eigenvalue Problem Computations
2116 eromero 4
   Copyright (c) 2002-2010, Universidad Politecnica de Valencia, Spain
1960 eromero 5
 
2110 jroman 6
   This file is part of SLEPc.
7
 
8
   SLEPc is free software: you can redistribute it and/or modify it under  the
9
   terms of version 3 of the GNU Lesser General Public License as published by
10
   the Free Software Foundation.
11
 
12
   SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
13
   WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
14
   FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
15
   more details.
16
 
17
   You  should have received a copy of the GNU Lesser General  Public  License
18
   along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
19
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20
*/
21
 
1960 eromero 22
#include "private/vecimpl.h"          /*I  "petscvec.h"   I*/
2341 jroman 23
#include <private/vecimplslepc.h>     /*I "slepcvec.h" I*/
1960 eromero 24
 
25
#include "veccomp0.h"
26
 
27
#define __WITH_MPI__
28
#include "veccomp0.h"
29
 
30
#undef __FUNCT__  
31
#define __FUNCT__ "VecDestroy_Comp"
32
PetscErrorCode VecDestroy_Comp(Vec v)
33
{
34
  Vec_Comp       *vs = (Vec_Comp*)v->data;
35
  PetscInt       i;
36
  PetscErrorCode ierr;
37
 
38
  PetscFunctionBegin;
39
  /* if memory was published with AMS then destroy it */
40
  ierr = PetscObjectDepublish(v);CHKERRQ(ierr);
41
 
42
#if defined(PETSC_USE_LOG)
43
  PetscLogObjectState((PetscObject)v,"Length=%D",v->map->n);
44
#endif
45
  for(i=0; i<vs->nx; i++) {
2330 jroman 46
    ierr = VecDestroy(&vs->x[i]);CHKERRQ(ierr);
1960 eromero 47
  }
1965 eromero 48
  if(--vs->n->friends <= 0) {
2330 jroman 49
    ierr = PetscFree(vs->n);CHKERRQ(ierr);
1965 eromero 50
  }
2330 jroman 51
  ierr = PetscFree(vs->x);CHKERRQ(ierr);
52
  ierr = PetscFree(vs);CHKERRQ(ierr);
1960 eromero 53
  PetscFunctionReturn(0);
54
}
55
 
56
static struct _VecOps DvOps = {VecDuplicate_Comp, /* 1 */
57
            VecDuplicateVecs_Default,
58
            VecDestroyVecs_Default,
59
            VecDot_Comp_MPI,
60
            VecMDot_Comp_MPI,
61
            VecNorm_Comp_MPI,
62
            0,
63
            0,
64
            VecScale_Comp,
65
            VecCopy_Comp, /* 10 */
66
            VecSet_Comp,
67
            VecSwap_Comp,
68
            VecAXPY_Comp,
69
            VecAXPBY_Comp,
70
            VecMAXPY_Comp,
2152 eromero 71
            VecAYPX_Comp,
1960 eromero 72
            VecWAXPY_Comp,
73
            VecAXPBYPCZ_Comp,
74
            VecPointwiseMult_Comp,
75
            VecPointwiseDivide_Comp,
76
            0, /* 20 */
77
            0,0,
78
 
79
            VecGetSize_Comp,
2009 eromero 80
            VecGetLocalSize_Comp,
1960 eromero 81
            0/*VecRestoreArray_Seq*/,
82
            VecMax_Comp,
83
            VecMin_Comp,
84
            VecSetRandom_Comp,
85
            0, /* 30 */
86
            0,
87
            VecDestroy_Comp,
88
            VecView_Comp,
89
            0/*VecPlaceArray_Seq*/,
90
            0/*VecReplaceArray_Seq*/,
91
            VecDot_Comp_Seq,
92
            0,
93
            VecNorm_Comp_Seq,
94
            VecMDot_Comp_Seq,
95
            0, /* 40 */
96
            0,
97
            VecReciprocal_Comp,
98
            VecConjugate_Comp,
99
            0,0,
100
            0/*VecResetArray_Seq*/,
101
            0,
102
            VecMaxPointwiseDivide_Comp,
103
            VecPointwiseMax_Comp,
104
            VecPointwiseMaxAbs_Comp,
105
            VecPointwiseMin_Comp,
106
            0,
2219 jroman 107
            VecSqrtAbs_Comp,
1960 eromero 108
            VecAbs_Comp,
109
            VecExp_Comp,
2010 eromero 110
            VecLog_Comp,
111
            0/*VecShift_Comp*/,
112
            0,
2219 jroman 113
            0,
114
            0,
2010 eromero 115
            VecDotNorm2_Comp_MPI
1960 eromero 116
          };
117
 
118
#undef __FUNCT__  
119
#define __FUNCT__ "VecCreate_Comp_Private"
2331 jroman 120
static PetscErrorCode VecCreate_Comp_Private(Vec v,Vec *x,PetscInt nx,PetscBool x_to_me,Vec_Comp_N *n)
1960 eromero 121
{
2317 jroman 122
  Vec_Comp       *s;
123
  PetscErrorCode ierr;
2331 jroman 124
  PetscInt       N=0,lN=0,i,k;
1960 eromero 125
 
126
  PetscFunctionBegin;
1965 eromero 127
  /* Allocate a new Vec_Comp */
2330 jroman 128
  if (v->data) { ierr = PetscFree(v->data);CHKERRQ(ierr); }
2331 jroman 129
  ierr = PetscNewLog(v,Vec_Comp,&s);CHKERRQ(ierr);
130
  ierr = PetscMemcpy(v->ops,&DvOps,sizeof(DvOps));CHKERRQ(ierr);
1960 eromero 131
  v->data  = (void*)s;
132
  v->petscnative     = PETSC_FALSE;
1965 eromero 133
 
134
  /* Allocate the array of Vec, if it is needed to be done */
1960 eromero 135
  if (x_to_me != PETSC_TRUE) {
2331 jroman 136
    ierr = PetscMalloc(sizeof(Vec)*nx,&s->x);CHKERRQ(ierr);
137
    ierr = PetscMemcpy(s->x,x,sizeof(Vec)*nx);CHKERRQ(ierr);
2336 jroman 138
  } else s->x = x;
1965 eromero 139
 
1960 eromero 140
  s->nx = nx;
2336 jroman 141
  for (i=0;i<nx;i++) {
2331 jroman 142
    ierr = VecGetSize(x[i],&k);CHKERRQ(ierr);
2330 jroman 143
    N+= k;
2331 jroman 144
    ierr = VecGetLocalSize(x[i],&k);CHKERRQ(ierr);
2330 jroman 145
    lN+= k;
1960 eromero 146
  }
1965 eromero 147
 
148
  /* Allocate the shared structure, if it is not given */
149
  if (!n) {
2331 jroman 150
    ierr = PetscNewLog(v,Vec_Comp_N,&n);CHKERRQ(ierr);
1965 eromero 151
    s->n = n;
152
    n->n = nx;
153
    n->N = N;
154
    n->lN = lN;
155
    n->friends = 1;
2336 jroman 156
  } else { /* If not, check in the vector in the shared structure */
1965 eromero 157
    s->n = n;
158
    s->n->friends++;
159
    s->n->n = nx;
160
  }
161
 
162
  /* Set the virtual sizes as the real sizes of the vector */
2331 jroman 163
  ierr = VecSetSizes(v,s->n->lN,s->n->N);CHKERRQ(ierr);
1965 eromero 164
 
2330 jroman 165
  ierr = PetscObjectChangeTypeName((PetscObject)v,VECCOMP);CHKERRQ(ierr);
1960 eromero 166
  PetscFunctionReturn(0);
167
}
168
 
169
EXTERN_C_BEGIN
170
#undef __FUNCT__  
171
#define __FUNCT__ "VecCreate_Comp"
2241 jroman 172
PetscErrorCode VecCreate_Comp(Vec V)
1960 eromero 173
{
2317 jroman 174
  PetscErrorCode ierr;
1960 eromero 175
 
176
  PetscFunctionBegin;
2331 jroman 177
  ierr = VecCreate_Comp_Private(V,PETSC_NULL,0,PETSC_FALSE,PETSC_NULL);CHKERRQ(ierr);
1960 eromero 178
  PetscFunctionReturn(0);
179
}
180
EXTERN_C_END
181
 
182
#undef __FUNCT__  
2337 jroman 183
#define __FUNCT__ "VecRegister_Comp"
184
PetscErrorCode VecRegister_Comp(const char path[])
185
{
186
  PetscErrorCode ierr;
187
 
188
  PetscFunctionBegin;
189
  ierr = VecRegisterDynamic(VECCOMP,path,"VecCreate_Comp",VecCreate_Comp);CHKERRQ(ierr);
190
  PetscFunctionReturn(0);
191
}
192
 
193
#undef __FUNCT__  
1960 eromero 194
#define __FUNCT__ "VecCreateComp"
2331 jroman 195
PetscErrorCode VecCreateComp(MPI_Comm comm,PetscInt *Nx,PetscInt n,const VecType t,Vec Vparent,Vec *V)
1960 eromero 196
{
2317 jroman 197
  PetscErrorCode ierr;
198
  Vec            *x;
199
  PetscInt       i;
1960 eromero 200
 
201
  PetscFunctionBegin;
2331 jroman 202
  ierr = VecCreate(comm,V);CHKERRQ(ierr);
203
  ierr = PetscMalloc(sizeof(Vec)*n,&x);CHKERRQ(ierr);
2336 jroman 204
  for(i=0;i<n;i++) {
2331 jroman 205
    ierr = VecCreate(comm,&x[i]);CHKERRQ(ierr);
206
    ierr = VecSetSizes(x[i],PETSC_DECIDE,Nx[i]);CHKERRQ(ierr);
207
    ierr = VecSetType(x[i],t);CHKERRQ(ierr);
1960 eromero 208
  }
2331 jroman 209
  ierr = VecCreate_Comp_Private(*V,x,n,PETSC_TRUE,
2317 jroman 210
                           Vparent?((Vec_Comp*)Vparent->data)->n:PETSC_NULL);CHKERRQ(ierr);
1960 eromero 211
  PetscFunctionReturn(0);
212
}
213
 
214
#undef __FUNCT__  
2155 jroman 215
#define __FUNCT__ "VecCreateCompWithVecs"
2331 jroman 216
PetscErrorCode VecCreateCompWithVecs(Vec *x,PetscInt n,Vec Vparent,Vec *V)
1960 eromero 217
{
2317 jroman 218
  PetscErrorCode ierr;
219
  PetscInt       i;
1960 eromero 220
 
221
  PetscFunctionBegin;
2331 jroman 222
  ierr = VecCreate(((PetscObject)x[0])->comm,V);CHKERRQ(ierr);
2336 jroman 223
  for(i=0;i<n;i++) {
2330 jroman 224
    ierr = PetscObjectReference((PetscObject)x[i]);CHKERRQ(ierr);
1960 eromero 225
  }
2331 jroman 226
  ierr = VecCreate_Comp_Private(*V,x,n,PETSC_FALSE,
2317 jroman 227
                           Vparent?((Vec_Comp*)Vparent->data)->n:PETSC_NULL);CHKERRQ(ierr);
1960 eromero 228
  PetscFunctionReturn(0);
229
}
230
 
231
#undef __FUNCT__  
232
#define __FUNCT__ "VecDuplicate_Comp"
2331 jroman 233
PetscErrorCode VecDuplicate_Comp(Vec win,Vec *V)
1960 eromero 234
{
2317 jroman 235
  PetscErrorCode ierr;
236
  Vec            *x;
237
  PetscInt       i;
238
  Vec_Comp       *s = (Vec_Comp*)win->data;
1960 eromero 239
 
240
  PetscFunctionBegin;
1965 eromero 241
  PetscValidVecComp(win);
2331 jroman 242
  ierr = VecCreate(((PetscObject)win)->comm,V);CHKERRQ(ierr);
243
  ierr = PetscMalloc(sizeof(Vec)*s->nx,&x);CHKERRQ(ierr);
2336 jroman 244
  for (i=0;i<s->nx;i++) {
2331 jroman 245
    ierr = VecDuplicate(s->x[i],&x[i]);CHKERRQ(ierr);
1960 eromero 246
  }
2331 jroman 247
  ierr = VecCreate_Comp_Private(*V,x,s->nx,PETSC_TRUE,s->n);CHKERRQ(ierr);
1960 eromero 248
  PetscFunctionReturn(0);
249
}
250
 
251
#undef __FUNCT__  
252
#define __FUNCT__ "VecCompGetVecs"
2331 jroman 253
PetscErrorCode VecCompGetVecs(Vec win,const Vec **x,PetscInt *n)
1960 eromero 254
{
2317 jroman 255
  Vec_Comp *s = (Vec_Comp*)win->data;
1960 eromero 256
 
257
  PetscFunctionBegin;
1965 eromero 258
  PetscValidVecComp(win);
1960 eromero 259
  if(x) *x = s->x;
260
  if(n) *n = s->nx;
261
  PetscFunctionReturn(0);
262
}
263
 
264
#undef __FUNCT__  
1965 eromero 265
#define __FUNCT__ "VecCompSetVecs"
2331 jroman 266
PetscErrorCode VecCompSetVecs(Vec win,Vec *x,PetscInt n)
1965 eromero 267
{
2317 jroman 268
  Vec_Comp       *s = (Vec_Comp*)win->data;
269
  PetscErrorCode ierr;
1965 eromero 270
 
271
  PetscFunctionBegin;
272
  PetscValidVecComp(win);
273
  if(x) {
274
    if (n > s->nx) {
2330 jroman 275
      ierr = PetscFree(s->x);CHKERRQ(ierr);
2331 jroman 276
      ierr = PetscMalloc(sizeof(Vec)*n,&s->x);CHKERRQ(ierr);
1965 eromero 277
    }
2331 jroman 278
    ierr = PetscMemcpy(s->x,x,sizeof(Vec)*n);CHKERRQ(ierr);
1965 eromero 279
    s->nx = n;
280
  }
281
  s->n->n = n;
282
  PetscFunctionReturn(0);
283
}
284
 
285
#undef __FUNCT__  
1960 eromero 286
#define __FUNCT__ "VecAXPY_Comp"
2331 jroman 287
PetscErrorCode VecAXPY_Comp(Vec v,PetscScalar alpha,Vec w)
1960 eromero 288
{
2317 jroman 289
  PetscErrorCode ierr;
2331 jroman 290
  Vec_Comp       *vs = (Vec_Comp*)v->data,*ws = (Vec_Comp*)w->data;
2317 jroman 291
  PetscInt       i;
1960 eromero 292
 
293
  PetscFunctionBegin;
1965 eromero 294
  PetscValidVecComp(v);
295
  PetscValidVecComp(w);
2336 jroman 296
  for (i=0;i<vs->n->n;i++) {
2331 jroman 297
    ierr = VecAXPY(vs->x[i],alpha,ws->x[i]);CHKERRQ(ierr);
1960 eromero 298
  }
299
  PetscFunctionReturn(0);
300
}
301
 
302
#undef __FUNCT__  
2152 eromero 303
#define __FUNCT__ "VecAYPX_Comp"
2331 jroman 304
PetscErrorCode VecAYPX_Comp(Vec v,PetscScalar alpha,Vec w)
2152 eromero 305
{
2317 jroman 306
  PetscErrorCode ierr;
2331 jroman 307
  Vec_Comp       *vs = (Vec_Comp*)v->data,*ws = (Vec_Comp*)w->data;
2317 jroman 308
  PetscInt       i;
2152 eromero 309
 
310
  PetscFunctionBegin;
311
  PetscValidVecComp(v);
312
  PetscValidVecComp(w);
2336 jroman 313
  for (i=0;i<vs->n->n;i++) {
2331 jroman 314
    ierr = VecAYPX(vs->x[i],alpha,ws->x[i]);CHKERRQ(ierr);
2152 eromero 315
  }
316
  PetscFunctionReturn(0);
317
}
318
 
319
#undef __FUNCT__  
1960 eromero 320
#define __FUNCT__ "VecAXPBY_Comp"
2331 jroman 321
PetscErrorCode VecAXPBY_Comp(Vec v,PetscScalar alpha,PetscScalar beta,Vec w)
1960 eromero 322
{
2317 jroman 323
  PetscErrorCode ierr;
2331 jroman 324
  Vec_Comp       *vs = (Vec_Comp*)v->data,*ws = (Vec_Comp*)w->data;
2317 jroman 325
  PetscInt       i;
1960 eromero 326
 
327
  PetscFunctionBegin;
1965 eromero 328
  PetscValidVecComp(v);
329
  PetscValidVecComp(w);
2336 jroman 330
  for (i=0;i<vs->n->n;i++) {
2331 jroman 331
    ierr = VecAXPBY(vs->x[i],alpha,beta,ws->x[i]);CHKERRQ(ierr);
1960 eromero 332
  }
333
  PetscFunctionReturn(0);
334
}
335
 
336
#undef __FUNCT__  
337
#define __FUNCT__ "VecMAXPY_Comp"
2331 jroman 338
PetscErrorCode VecMAXPY_Comp(Vec v,PetscInt n,const PetscScalar *alpha,Vec *w)
1960 eromero 339
{
2317 jroman 340
  PetscErrorCode ierr;
341
  Vec_Comp       *vs = (Vec_Comp*)v->data;
342
  Vec            *wx;
2331 jroman 343
  PetscInt       i,j;
1960 eromero 344
 
345
  PetscFunctionBegin;
1965 eromero 346
  PetscValidVecComp(v);
2336 jroman 347
  for (i=0;i<n;i++) PetscValidVecComp(w[i]);
1965 eromero 348
 
2331 jroman 349
  ierr = PetscMalloc(sizeof(Vec)*n,&wx);CHKERRQ(ierr);
1960 eromero 350
 
2336 jroman 351
  for (j=0;j<vs->n->n;j++) {
352
    for (i=0;i<n;i++) wx[i] = ((Vec_Comp*)w[i]->data)->x[j];
2331 jroman 353
    ierr = VecMAXPY(vs->x[j],n,alpha,wx);CHKERRQ(ierr);
1960 eromero 354
  }
355
 
2330 jroman 356
  ierr = PetscFree(wx);CHKERRQ(ierr);
1960 eromero 357
  PetscFunctionReturn(0);
358
}
359
 
360
#undef __FUNCT__  
361
#define __FUNCT__ "VecWAXPY_Comp"
2331 jroman 362
PetscErrorCode VecWAXPY_Comp(Vec v,PetscScalar alpha,Vec w,Vec z)
1960 eromero 363
{
2317 jroman 364
  PetscErrorCode ierr;
2331 jroman 365
  Vec_Comp       *vs = (Vec_Comp*)v->data,*ws = (Vec_Comp*)w->data,*zs = (Vec_Comp*)z->data;
2317 jroman 366
  PetscInt       i;
1960 eromero 367
 
368
  PetscFunctionBegin;
1965 eromero 369
  PetscValidVecComp(v);
370
  PetscValidVecComp(w);
371
  PetscValidVecComp(z);
2336 jroman 372
  for (i=0;i<vs->n->n;i++) {
2331 jroman 373
    ierr = VecWAXPY(vs->x[i],alpha,ws->x[i],zs->x[i]);CHKERRQ(ierr);
1960 eromero 374
  }
375
  PetscFunctionReturn(0);
376
}
377
 
378
#undef __FUNCT__  
379
#define __FUNCT__ "VecAXPBYPCZ_Comp"
2331 jroman 380
PetscErrorCode VecAXPBYPCZ_Comp(Vec v,PetscScalar alpha,PetscScalar beta,PetscScalar gamma,Vec w,Vec z)
1960 eromero 381
{
382
  PetscErrorCode  ierr;
2331 jroman 383
  Vec_Comp        *vs = (Vec_Comp*)v->data,*ws = (Vec_Comp*)w->data,*zs = (Vec_Comp*)z->data;
1960 eromero 384
  PetscInt        i;
385
 
386
  PetscFunctionBegin;
1965 eromero 387
  PetscValidVecComp(v);
388
  PetscValidVecComp(w);
389
  PetscValidVecComp(z);
2336 jroman 390
  for (i=0;i<vs->n->n;i++) {
2331 jroman 391
    ierr = VecAXPBYPCZ(vs->x[i],alpha,beta,gamma,ws->x[i],zs->x[i]);CHKERRQ(ierr);
1960 eromero 392
  }
393
  PetscFunctionReturn(0);
394
}
395
 
396
#undef __FUNCT__  
397
#define __FUNCT__ "VecGetSize_Comp"
2331 jroman 398
PetscErrorCode VecGetSize_Comp(Vec v,PetscInt *size)
1960 eromero 399
{
2317 jroman 400
  Vec_Comp *vs = (Vec_Comp*)v->data;
1960 eromero 401
 
402
  PetscFunctionBegin;
1965 eromero 403
  PetscValidVecComp(v);
2336 jroman 404
  PetscValidIntPointer(size,2);
405
  *size = vs->n->N;
1960 eromero 406
  PetscFunctionReturn(0);
407
}
408
 
409
#undef __FUNCT__  
2009 eromero 410
#define __FUNCT__ "VecGetLocalSize_Comp"
2331 jroman 411
PetscErrorCode VecGetLocalSize_Comp(Vec v,PetscInt *size)
2009 eromero 412
{
2317 jroman 413
  Vec_Comp *vs = (Vec_Comp*)v->data;
2009 eromero 414
 
415
  PetscFunctionBegin;
416
  PetscValidVecComp(v);
2336 jroman 417
  PetscValidIntPointer(size,2);
418
  *size = vs->n->lN;
2009 eromero 419
  PetscFunctionReturn(0);
420
}
421
 
422
#undef __FUNCT__  
1960 eromero 423
#define __FUNCT__ "VecMax_Comp"
2331 jroman 424
PetscErrorCode VecMax_Comp(Vec v,PetscInt *idx,PetscReal *z)
1960 eromero 425
{
2317 jroman 426
  PetscErrorCode ierr;
427
  Vec_Comp       *vs = (Vec_Comp*)v->data;
2331 jroman 428
  PetscInt       idxp,s=0,s0;
429
  PetscReal      zp,z0;
2317 jroman 430
  PetscInt       i;
1960 eromero 431
 
432
  PetscFunctionBegin;
1965 eromero 433
  PetscValidVecComp(v);
2336 jroman 434
  if (!idx && !z) PetscFunctionReturn(0);
1960 eromero 435
 
1965 eromero 436
  if (vs->n->n > 0) {
2331 jroman 437
    ierr = VecMax(vs->x[0],idx?&idxp:PETSC_NULL,&zp);CHKERRQ(ierr);
1960 eromero 438
  }
2336 jroman 439
  for (i=1;i<vs->n->n;i++) {
2331 jroman 440
    ierr = VecGetSize(vs->x[i-1],&s0);CHKERRQ(ierr);
2330 jroman 441
    s+= s0;
2331 jroman 442
    ierr = VecMax(vs->x[i],idx?&idxp:PETSC_NULL,&z0);CHKERRQ(ierr);
2336 jroman 443
    if (zp < z0) {
444
      if (idx) *idx = s+idxp;
1960 eromero 445
      zp = z0;
446
    }
447
  }
448
  if (z) *z = zp;
449
  PetscFunctionReturn(0);
450
}
451
 
452
#undef __FUNCT__  
453
#define __FUNCT__ "VecMin_Comp"
2331 jroman 454
PetscErrorCode VecMin_Comp(Vec v,PetscInt *idx,PetscReal *z)
1960 eromero 455
{
2317 jroman 456
  PetscErrorCode ierr;
457
  Vec_Comp       *vs = (Vec_Comp*)v->data;
2331 jroman 458
  PetscInt       idxp,s=0,s0;
459
  PetscReal      zp,z0;
2317 jroman 460
  PetscInt       i;
1960 eromero 461
 
462
  PetscFunctionBegin;
1965 eromero 463
  PetscValidVecComp(v);
2336 jroman 464
  if (!idx && !z) PetscFunctionReturn(0);
1960 eromero 465
 
1965 eromero 466
  if (vs->n->n > 0) {
2331 jroman 467
    ierr = VecMin(vs->x[0],idx?&idxp:PETSC_NULL,&zp);CHKERRQ(ierr);
1960 eromero 468
  }
2336 jroman 469
  for (i=1;i<vs->n->n;i++) {
2331 jroman 470
    ierr = VecGetSize(vs->x[i-1],&s0);CHKERRQ(ierr);
2330 jroman 471
    s+= s0;
2331 jroman 472
    ierr = VecMin(vs->x[i],idx?&idxp:PETSC_NULL,&z0);CHKERRQ(ierr);
1960 eromero 473
    if(zp > z0) {
474
      if(idx) *idx = s+idxp;
475
      zp = z0;
476
    }
477
  }
478
  if (z) *z = zp;
479
  PetscFunctionReturn(0);
480
}
481
 
482
#undef __FUNCT__  
483
#define __FUNCT__ "VecMaxPointwiseDivide_Comp"
2331 jroman 484
PetscErrorCode VecMaxPointwiseDivide_Comp(Vec v,Vec w,PetscReal *m)
1960 eromero 485
{
2317 jroman 486
  PetscErrorCode ierr;
2331 jroman 487
  Vec_Comp       *vs = (Vec_Comp*)v->data,*ws = (Vec_Comp*)w->data;
2317 jroman 488
  PetscReal      work;
489
  PetscInt       i;
1960 eromero 490
 
491
  PetscFunctionBegin;
1965 eromero 492
  PetscValidVecComp(v);
493
  PetscValidVecComp(w);
2336 jroman 494
  if (!m || vs->n->n == 0) PetscFunctionReturn(0);
2331 jroman 495
  ierr = VecMaxPointwiseDivide(vs->x[0],ws->x[0],m);CHKERRQ(ierr);
2336 jroman 496
  for (i=1;i<vs->n->n;i++) {
2331 jroman 497
    ierr = VecMaxPointwiseDivide(vs->x[i],ws->x[i],&work);CHKERRQ(ierr);
498
    *m = PetscMax(*m,work);
1960 eromero 499
  }
500
  PetscFunctionReturn(0);
501
}
502
 
503
 
504
#define __QUOTEME__(x) #x
505
#define __COMPOSE2__(A,B) A##B
506
#define __COMPOSE3__(A,B,C) A##B##C
507
 
508
#define __FUNC_TEMPLATE1__(NAME) \
509
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v) \
510
{ \
511
  PetscErrorCode  ierr; \
512
  Vec_Comp        *vs = (Vec_Comp*)v->data; \
513
  PetscInt        i; \
514
\
515
  PetscFunctionBegin; \
1965 eromero 516
  PetscValidVecComp(v); \
2336 jroman 517
  for (i=0;i<vs->n->n;i++) { \
2330 jroman 518
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i]);CHKERRQ(ierr); \
1960 eromero 519
  } \
520
  PetscFunctionReturn(0);\
2336 jroman 521
}
1960 eromero 522
 
523
#undef __FUNCT__  
524
#define __FUNCT__ "VecConjugate_Comp"
525
__FUNC_TEMPLATE1__(Conjugate)
526
 
527
#undef __FUNCT__  
528
#define __FUNCT__ "VecReciprocal_Comp"
529
__FUNC_TEMPLATE1__(Reciprocal)
530
 
531
#undef __FUNCT__  
2219 jroman 532
#define __FUNCT__ "VecSqrtAbs_Comp"
533
__FUNC_TEMPLATE1__(SqrtAbs)
1960 eromero 534
 
535
#undef __FUNCT__  
536
#define __FUNCT__ "VecAbs_Comp"
537
__FUNC_TEMPLATE1__(Abs)
538
 
539
#undef __FUNCT__  
540
#define __FUNCT__ "VecExp_Comp"
541
__FUNC_TEMPLATE1__(Exp)
542
 
543
#undef __FUNCT__  
544
#define __FUNCT__ "VecLog_Comp"
545
__FUNC_TEMPLATE1__(Log)
546
 
547
 
548
#define __FUNC_TEMPLATE2__(NAME,T0) \
2331 jroman 549
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v,T0 __a) \
1960 eromero 550
{ \
551
  PetscErrorCode  ierr; \
552
  Vec_Comp        *vs = (Vec_Comp*)v->data; \
553
  PetscInt        i; \
554
\
555
  PetscFunctionBegin; \
1965 eromero 556
  PetscValidVecComp(v); \
2336 jroman 557
  for (i=0;i<vs->n->n;i++) { \
2331 jroman 558
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i],__a);CHKERRQ(ierr); \
1960 eromero 559
  } \
560
  PetscFunctionReturn(0);\
2336 jroman 561
}
1960 eromero 562
 
563
#undef __FUNCT__  
564
#define __FUNCT__ "VecSet_Comp"
2331 jroman 565
__FUNC_TEMPLATE2__(Set,PetscScalar)
1960 eromero 566
 
567
#undef __FUNCT__  
568
#define __FUNCT__ "VecView_Comp"
2331 jroman 569
__FUNC_TEMPLATE2__(View,PetscViewer)
1960 eromero 570
 
571
#undef __FUNCT__  
572
#define __FUNCT__ "VecScale_Comp"
2331 jroman 573
__FUNC_TEMPLATE2__(Scale,PetscScalar)
1960 eromero 574
 
575
#undef __FUNCT__  
576
#define __FUNCT__ "VecSetRandom_Comp"
2331 jroman 577
__FUNC_TEMPLATE2__(SetRandom,PetscRandom)
1960 eromero 578
 
579
#undef __FUNCT__  
580
#define __FUNCT__ "VecShift_Comp"
2331 jroman 581
__FUNC_TEMPLATE2__(Shift,PetscScalar)
1960 eromero 582
 
583
 
584
#define __FUNC_TEMPLATE3__(NAME) \
2331 jroman 585
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v,Vec w) \
1960 eromero 586
{ \
587
  PetscErrorCode  ierr; \
2331 jroman 588
  Vec_Comp        *vs = (Vec_Comp*)v->data,\
1960 eromero 589
                  *ws = (Vec_Comp*)w->data; \
590
  PetscInt        i; \
591
\
592
  PetscFunctionBegin; \
1965 eromero 593
  PetscValidVecComp(v); \
594
  PetscValidVecComp(w); \
2336 jroman 595
  for (i=0;i<vs->n->n;i++) { \
2331 jroman 596
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i],ws->x[i]);CHKERRQ(ierr); \
1960 eromero 597
  } \
598
  PetscFunctionReturn(0);\
2336 jroman 599
}
1960 eromero 600
 
601
#undef __FUNCT__  
602
#define __FUNCT__ "VecCopy_Comp"
603
__FUNC_TEMPLATE3__(Copy)
604
 
605
#undef __FUNCT__  
606
#define __FUNCT__ "VecSwap_Comp"
607
__FUNC_TEMPLATE3__(Swap)
608
 
609
 
610
#define __FUNC_TEMPLATE4__(NAME) \
2331 jroman 611
PetscErrorCode __COMPOSE3__(Vec,NAME,_Comp)(Vec v,Vec w,Vec z) \
1960 eromero 612
{ \
613
  PetscErrorCode  ierr; \
614
  Vec_Comp        *vs = (Vec_Comp*)v->data, \
615
                  *ws = (Vec_Comp*)w->data, \
616
                  *zs = (Vec_Comp*)z->data; \
617
  PetscInt        i; \
618
\
619
  PetscFunctionBegin; \
1965 eromero 620
  PetscValidVecComp(v); \
621
  PetscValidVecComp(w); \
622
  PetscValidVecComp(z); \
2336 jroman 623
  for (i=0;i<vs->n->n;i++) { \
2331 jroman 624
    ierr = __COMPOSE2__(Vec,NAME)(vs->x[i],ws->x[i],zs->x[i]);CHKERRQ(ierr); \
1960 eromero 625
  } \
626
  PetscFunctionReturn(0);\
2336 jroman 627
}
1960 eromero 628
 
629
#undef __FUNCT__  
630
#define __FUNCT__ "VecPointwiseMax_Comp"
631
__FUNC_TEMPLATE4__(PointwiseMax)
632
 
633
#undef __FUNCT__  
634
#define __FUNCT__ "VecPointwiseMaxAbs_Comp"
635
__FUNC_TEMPLATE4__(PointwiseMaxAbs)
636
 
637
#undef __FUNCT__  
638
#define __FUNCT__ "VecPointwiseMin_Comp"
639
__FUNC_TEMPLATE4__(PointwiseMin)
640
 
641
#undef __FUNCT__  
642
#define __FUNCT__ "VecPointwiseMult_Comp"
643
__FUNC_TEMPLATE4__(PointwiseMult)
644
 
645
#undef __FUNCT__  
646
#define __FUNCT__ "VecPointwiseDivide_Comp"
647
__FUNC_TEMPLATE4__(PointwiseDivide)