Subversion Repositories slepc-dev

Rev

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