Subversion Repositories slepc-dev

Rev

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

Rev Author Line No. Line
1302 slepc 1
/*
2
     Dot product routines
1376 slepc 3
 
4
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1672 slepc 5
   SLEPc - Scalable Library for Eigenvalue Problem Computations
2575 eromero 6
   Copyright (c) 2002-2011, Universitat Politecnica de Valencia, Spain
1376 slepc 7
 
1672 slepc 8
   This file is part of SLEPc.
9
 
10
   SLEPc is free software: you can redistribute it and/or modify it under  the
11
   terms of version 3 of the GNU Lesser General Public License as published by
12
   the Free Software Foundation.
13
 
14
   SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
15
   WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
16
   FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
17
   more details.
18
 
19
   You  should have received a copy of the GNU Lesser General  Public  License
20
   along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
1376 slepc 21
   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1302 slepc 22
*/
1376 slepc 23
 
2729 jroman 24
#include <slepc-private/ipimpl.h>      /*I "slepcip.h" I*/
1302 slepc 25
 
2445 jroman 26
/* The following definitions are intended to avoid using the "T" versions
27
   of dot products in the case of real scalars */
28
#if defined(PETSC_USE_COMPLEX)
29
#define VecXDotBegin  VecTDotBegin
30
#define VecXDotEnd    VecTDotEnd  
31
#define VecMXDotBegin VecMTDotBegin
32
#define VecMXDotEnd   VecMTDotEnd  
33
#else
34
#define VecXDotBegin  VecDotBegin
35
#define VecXDotEnd    VecDotEnd  
36
#define VecMXDotBegin VecMDotBegin
37
#define VecMXDotEnd   VecMDotEnd  
38
#endif
39
 
1302 slepc 40
#undef __FUNCT__  
41
#define __FUNCT__ "IPNorm"
42
/*@
1704 jroman 43
   IPNorm - Computes the norm of a vector as the square root of the inner
1302 slepc 44
   product (x,x) as defined by IPInnerProduct().
45
 
46
   Collective on IP and Vec
47
 
48
   Input Parameters:
1423 slepc 49
+  ip - the inner product context
1302 slepc 50
-  x  - input vector
51
 
52
   Output Parameter:
53
.  norm - the computed norm
54
 
55
   Notes:
56
   This function will usually compute the 2-norm of a vector, ||x||_2. But
57
   this behaviour may be different if using a non-standard inner product changed
2380 jroman 58
   via IPSetMatrix(). For example, if using the B-inner product for
1302 slepc 59
   positive definite B, (x,y)_B=y^H Bx, then the computed norm is ||x||_B =
60
   sqrt( x^H Bx ).
61
 
62
   Level: developer
63
 
64
.seealso: IPInnerProduct()
65
@*/
66
PetscErrorCode IPNorm(IP ip,Vec x,PetscReal *norm)
67
{
68
  PetscErrorCode ierr;
69
 
70
  PetscFunctionBegin;
2213 jroman 71
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
72
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
1302 slepc 73
  PetscValidPointer(norm,3);
2377 jroman 74
  ierr = (*ip->ops->normbegin)(ip,x,norm);CHKERRQ(ierr);
75
  ierr = (*ip->ops->normend)(ip,x,norm);CHKERRQ(ierr);
76
  PetscFunctionReturn(0);
77
}
78
 
79
#undef __FUNCT__  
80
#define __FUNCT__ "IPNormBegin_Bilinear"
81
PetscErrorCode IPNormBegin_Bilinear(IP ip,Vec x,PetscReal *norm)
82
{
83
  PetscErrorCode ierr;
84
  PetscScalar    p;
85
 
86
  PetscFunctionBegin;
87
  ierr = IPInnerProductBegin(ip,x,x,&p);CHKERRQ(ierr);
88
  PetscFunctionReturn(0);
89
}
90
 
91
#undef __FUNCT__  
92
#define __FUNCT__ "IPNormBegin_Sesquilinear"
93
PetscErrorCode IPNormBegin_Sesquilinear(IP ip,Vec x,PetscReal *norm)
94
{
95
  PetscErrorCode ierr;
96
  PetscScalar    p;
97
 
98
  PetscFunctionBegin;
99
  if (!ip->matrix) {
100
    ierr = VecNormBegin(x,NORM_2,norm);CHKERRQ(ierr);
1432 slepc 101
  } else {
2377 jroman 102
    ierr = IPInnerProductBegin(ip,x,x,&p);CHKERRQ(ierr);
1432 slepc 103
  }
1302 slepc 104
  PetscFunctionReturn(0);
105
}
106
 
107
#undef __FUNCT__  
108
#define __FUNCT__ "IPNormBegin"
109
/*@
110
   IPNormBegin - Starts a split phase norm computation.
111
 
2328 jroman 112
   Collective on IP and Vec
113
 
1302 slepc 114
   Input Parameters:
1423 slepc 115
+  ip   - the inner product context
1302 slepc 116
.  x    - input vector
117
-  norm - where the result will go
118
 
119
   Level: developer
120
 
121
   Notes:
122
   Each call to IPNormBegin() should be paired with a call to IPNormEnd().
123
 
124
.seealso: IPNormEnd(), IPNorm(), IPInnerProduct(), IPMInnerProduct(),
125
          IPInnerProductBegin(), IPInnerProductEnd()
126
@*/
127
PetscErrorCode IPNormBegin(IP ip,Vec x,PetscReal *norm)
128
{
129
  PetscErrorCode ierr;
130
 
131
  PetscFunctionBegin;
2213 jroman 132
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
133
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
1302 slepc 134
  PetscValidPointer(norm,3);
2377 jroman 135
  ierr = (*ip->ops->normbegin)(ip,x,norm);CHKERRQ(ierr);
136
  PetscFunctionReturn(0);
137
}
138
 
139
#undef __FUNCT__  
140
#define __FUNCT__ "IPNormEnd_Bilinear"
141
PetscErrorCode IPNormEnd_Bilinear(IP ip,Vec x,PetscReal *norm)
142
{
143
  PetscErrorCode ierr;
144
  PetscScalar    p;
145
 
146
  PetscFunctionBegin;
147
  ierr = IPInnerProductEnd(ip,x,x,&p);CHKERRQ(ierr);
148
  if (PetscAbsScalar(p)<PETSC_MACHINE_EPSILON)
149
    PetscInfo(ip,"Zero norm, either the vector is zero or a semi-inner product is being used\n");
150
#if defined(PETSC_USE_COMPLEX)
151
  if (PetscRealPart(p)<0.0 || PetscAbsReal(PetscImaginaryPart(p))>PETSC_MACHINE_EPSILON)
152
     SETERRQ(((PetscObject)ip)->comm,1,"IPNorm: The inner product is not well defined");
153
  *norm = PetscSqrtScalar(PetscRealPart(p));
154
#else
155
  if (p<0.0) SETERRQ(((PetscObject)ip)->comm,1,"IPNorm: The inner product is not well defined");
156
  *norm = PetscSqrtScalar(p);
157
#endif
158
  PetscFunctionReturn(0);
159
}
160
 
161
#undef __FUNCT__  
162
#define __FUNCT__ "IPNormEnd_Sesquilinear"
163
PetscErrorCode IPNormEnd_Sesquilinear(IP ip,Vec x,PetscReal *norm)
164
{
165
  PetscErrorCode ierr;
166
  PetscScalar    p;
167
 
168
  PetscFunctionBegin;
169
  if (!ip->matrix) {
170
    ierr = VecNormEnd(x,NORM_2,norm);CHKERRQ(ierr);
1432 slepc 171
  } else {
2377 jroman 172
    ierr = IPInnerProductEnd(ip,x,x,&p);CHKERRQ(ierr);
173
    if (PetscAbsScalar(p)<PETSC_MACHINE_EPSILON)
174
      PetscInfo(ip,"Zero norm, either the vector is zero or a semi-inner product is being used\n");
2558 eromero 175
    if (PetscRealPart(p)<0.0 || PetscAbsReal(PetscImaginaryPart(p))/PetscAbsScalar(p)>PETSC_MACHINE_EPSILON)
2377 jroman 176
       SETERRQ(((PetscObject)ip)->comm,1,"IPNorm: The inner product is not well defined");
177
    *norm = PetscSqrtScalar(PetscRealPart(p));
1432 slepc 178
  }
1302 slepc 179
  PetscFunctionReturn(0);
180
}
181
 
182
#undef __FUNCT__  
183
#define __FUNCT__ "IPNormEnd"
184
/*@
185
   IPNormEnd - Ends a split phase norm computation.
186
 
2328 jroman 187
   Collective on IP and Vec
188
 
1302 slepc 189
   Input Parameters:
1423 slepc 190
+  ip   - the inner product context
1302 slepc 191
-  x    - input vector
192
 
193
   Output Parameter:
194
.  norm - the computed norm
195
 
196
   Level: developer
197
 
198
   Notes:
199
   Each call to IPNormBegin() should be paired with a call to IPNormEnd().
200
 
201
.seealso: IPNormBegin(), IPNorm(), IPInnerProduct(), IPMInnerProduct(),
202
          IPInnerProductBegin(), IPInnerProductEnd()
203
@*/
204
PetscErrorCode IPNormEnd(IP ip,Vec x,PetscReal *norm)
205
{
206
  PetscErrorCode ierr;
207
 
208
  PetscFunctionBegin;
2213 jroman 209
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
210
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
1302 slepc 211
  PetscValidPointer(norm,3);
2377 jroman 212
  ierr = (*ip->ops->normend)(ip,x,norm);CHKERRQ(ierr);
1302 slepc 213
  PetscFunctionReturn(0);
214
}
215
 
216
#undef __FUNCT__  
217
#define __FUNCT__ "IPInnerProduct"
218
/*@
219
   IPInnerProduct - Computes the inner product of two vectors.
220
 
221
   Collective on IP and Vec
222
 
223
   Input Parameters:
1423 slepc 224
+  ip - the inner product context
1302 slepc 225
.  x  - input vector
226
-  y  - input vector
227
 
228
   Output Parameter:
229
.  p - result of the inner product
230
 
231
   Notes:
232
   This function will usually compute the standard dot product of vectors
233
   x and y, (x,y)=y^H x. However this behaviour may be different if changed
2380 jroman 234
   via IPSetMatrix(). This allows use of other inner products such as
1302 slepc 235
   the indefinite product y^T x for complex symmetric problems or the
236
   B-inner product for positive definite B, (x,y)_B=y^H Bx.
237
 
238
   Level: developer
239
 
2380 jroman 240
.seealso: IPSetMatrix(), VecDot(), IPMInnerProduct()
1302 slepc 241
@*/
242
PetscErrorCode IPInnerProduct(IP ip,Vec x,Vec y,PetscScalar *p)
243
{
244
  PetscErrorCode ierr;
245
 
246
  PetscFunctionBegin;
2213 jroman 247
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
248
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
249
  PetscValidHeaderSpecific(y,VEC_CLASSID,3);
1302 slepc 250
  PetscValidScalarPointer(p,4);
251
  ierr = PetscLogEventBegin(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
252
  ip->innerproducts++;
2377 jroman 253
  ierr = (*ip->ops->innerproductbegin)(ip,x,y,p);CHKERRQ(ierr);
254
  ierr = (*ip->ops->innerproductend)(ip,x,y,p);CHKERRQ(ierr);
255
  ierr = PetscLogEventEnd(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
256
  PetscFunctionReturn(0);
257
}
258
 
259
#undef __FUNCT__  
260
#define __FUNCT__ "IPInnerProductBegin_Bilinear"
261
PetscErrorCode IPInnerProductBegin_Bilinear(IP ip,Vec x,Vec y,PetscScalar *p)
262
{
263
  PetscErrorCode ierr;
264
 
265
  PetscFunctionBegin;
1329 slepc 266
  if (ip->matrix) {
1358 slepc 267
    ierr = IPApplyMatrix_Private(ip,x);CHKERRQ(ierr);
2445 jroman 268
    ierr = VecXDotBegin(ip->Bx,y,p);CHKERRQ(ierr);
1329 slepc 269
  } else {
2445 jroman 270
    ierr = VecXDotBegin(x,y,p);CHKERRQ(ierr);
1302 slepc 271
  }
272
  PetscFunctionReturn(0);
273
}
274
 
275
#undef __FUNCT__  
2377 jroman 276
#define __FUNCT__ "IPInnerProductBegin_Sesquilinear"
277
PetscErrorCode IPInnerProductBegin_Sesquilinear(IP ip,Vec x,Vec y,PetscScalar *p)
278
{
279
  PetscErrorCode ierr;
280
 
281
  PetscFunctionBegin;
282
  if (ip->matrix) {
283
    ierr = IPApplyMatrix_Private(ip,x);CHKERRQ(ierr);
284
    ierr = VecDotBegin(ip->Bx,y,p);CHKERRQ(ierr);
285
  } else {
286
    ierr = VecDotBegin(x,y,p);CHKERRQ(ierr);
287
  }
288
  PetscFunctionReturn(0);
289
}
290
 
291
#undef __FUNCT__  
1302 slepc 292
#define __FUNCT__ "IPInnerProductBegin"
293
/*@
294
   IPInnerProductBegin - Starts a split phase inner product computation.
295
 
2328 jroman 296
   Collective on IP and Vec
297
 
1302 slepc 298
   Input Parameters:
1423 slepc 299
+  ip - the inner product context
1302 slepc 300
.  x  - the first vector
301
.  y  - the second vector
302
-  p  - where the result will go
303
 
304
   Level: developer
305
 
306
   Notes:
307
   Each call to IPInnerProductBegin() should be paired with a call to IPInnerProductEnd().
308
 
309
.seealso: IPInnerProductEnd(), IPInnerProduct(), IPNorm(), IPNormBegin(),
310
          IPNormEnd(), IPMInnerProduct()
311
@*/
312
PetscErrorCode IPInnerProductBegin(IP ip,Vec x,Vec y,PetscScalar *p)
313
{
314
  PetscErrorCode ierr;
315
 
316
  PetscFunctionBegin;
2213 jroman 317
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
318
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
319
  PetscValidHeaderSpecific(y,VEC_CLASSID,3);
1302 slepc 320
  PetscValidScalarPointer(p,4);
321
  ierr = PetscLogEventBegin(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
322
  ip->innerproducts++;
2377 jroman 323
  ierr = (*ip->ops->innerproductbegin)(ip,x,y,p);CHKERRQ(ierr);
324
  ierr = PetscLogEventEnd(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
325
  PetscFunctionReturn(0);
326
}
327
 
328
#undef __FUNCT__  
329
#define __FUNCT__ "IPInnerProductEnd_Bilinear"
330
PetscErrorCode IPInnerProductEnd_Bilinear(IP ip,Vec x,Vec y,PetscScalar *p)
331
{
332
  PetscErrorCode ierr;
333
 
334
  PetscFunctionBegin;
1329 slepc 335
  if (ip->matrix) {
2445 jroman 336
    ierr = VecXDotEnd(ip->Bx,y,p);CHKERRQ(ierr);
1329 slepc 337
  } else {
2445 jroman 338
    ierr = VecXDotEnd(x,y,p);CHKERRQ(ierr);
1302 slepc 339
  }
340
  PetscFunctionReturn(0);
341
}
342
 
343
#undef __FUNCT__  
2377 jroman 344
#define __FUNCT__ "IPInnerProductEnd_Sesquilinear"
345
PetscErrorCode IPInnerProductEnd_Sesquilinear(IP ip,Vec x,Vec y,PetscScalar *p)
346
{
347
  PetscErrorCode ierr;
348
 
349
  PetscFunctionBegin;
350
  if (ip->matrix) {
351
    ierr = VecDotEnd(ip->Bx,y,p);CHKERRQ(ierr);
352
  } else {
353
    ierr = VecDotEnd(x,y,p);CHKERRQ(ierr);
354
  }
355
  PetscFunctionReturn(0);
356
}
357
 
358
#undef __FUNCT__  
1302 slepc 359
#define __FUNCT__ "IPInnerProductEnd"
360
/*@
361
   IPInnerProductEnd - Ends a split phase inner product computation.
362
 
2328 jroman 363
   Collective on IP and Vec
364
 
1302 slepc 365
   Input Parameters:
1423 slepc 366
+  ip - the inner product context
1302 slepc 367
.  x  - the first vector
368
-  y  - the second vector
369
 
370
   Output Parameter:
371
.  p  - result of the inner product
372
 
373
   Level: developer
374
 
375
   Notes:
376
   Each call to IPInnerProductBegin() should be paired with a call to IPInnerProductEnd().
377
 
378
.seealso: IPInnerProductBegin(), IPInnerProduct(), IPNorm(), IPNormBegin(),
379
          IPNormEnd(), IPMInnerProduct()
380
@*/
381
PetscErrorCode IPInnerProductEnd(IP ip,Vec x,Vec y,PetscScalar *p)
382
{
383
  PetscErrorCode ierr;
384
 
385
  PetscFunctionBegin;
2213 jroman 386
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
387
  PetscValidHeaderSpecific(x,VEC_CLASSID,2);
388
  PetscValidHeaderSpecific(y,VEC_CLASSID,3);
1302 slepc 389
  PetscValidScalarPointer(p,4);
390
  ierr = PetscLogEventBegin(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
2377 jroman 391
  ierr = (*ip->ops->innerproductend)(ip,x,y,p);CHKERRQ(ierr);
1302 slepc 392
  ierr = PetscLogEventEnd(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
393
  PetscFunctionReturn(0);
394
}
395
 
396
#undef __FUNCT__  
397
#define __FUNCT__ "IPMInnerProduct"
398
/*@
399
   IPMInnerProduct - Computes the inner products a vector x with a set of
400
   vectors (columns of Y).
401
 
402
   Collective on IP and Vec
403
 
404
   Input Parameters:
1423 slepc 405
+  ip - the inner product context
1381 slepc 406
.  x  - the first input vector
1302 slepc 407
.  n  - number of vectors in y
408
-  y  - array of vectors
409
 
410
   Output Parameter:
411
.  p - result of the inner products
412
 
413
   Notes:
414
   This function will usually compute the standard dot product of x and y_i,
415
   (x,y_i)=y_i^H x, for each column of Y. However this behaviour may be different
2380 jroman 416
   if changed via IPSetMatrix(). This allows use of other inner products
1302 slepc 417
   such as the indefinite product y_i^T x for complex symmetric problems or the
418
   B-inner product for positive definite B, (x,y_i)_B=y_i^H Bx.
419
 
420
   Level: developer
421
 
2380 jroman 422
.seealso: IPSetMatrix(), VecMDot(), IPInnerProduct()
1302 slepc 423
@*/
1381 slepc 424
PetscErrorCode IPMInnerProduct(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
1302 slepc 425
{
426
  PetscErrorCode ierr;
427
 
428
  PetscFunctionBegin;
2213 jroman 429
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
430
  PetscValidHeaderSpecific(x,VEC_CLASSID,3);
1302 slepc 431
  PetscValidPointer(y,4);
2213 jroman 432
  PetscValidHeaderSpecific(*y,VEC_CLASSID,4);
1302 slepc 433
  PetscValidScalarPointer(p,5);
434
  ierr = PetscLogEventBegin(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
435
  ip->innerproducts += n;
2377 jroman 436
  ierr = (*ip->ops->minnerproductbegin)(ip,x,n,y,p);CHKERRQ(ierr);
437
  ierr = (*ip->ops->minnerproductend)(ip,x,n,y,p);CHKERRQ(ierr);
438
  ierr = PetscLogEventEnd(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
439
  PetscFunctionReturn(0);
440
}
441
 
442
#undef __FUNCT__  
443
#define __FUNCT__ "IPMInnerProductBegin_Bilinear"
444
PetscErrorCode IPMInnerProductBegin_Bilinear(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
445
{
446
  PetscErrorCode ierr;
447
 
448
  PetscFunctionBegin;
1329 slepc 449
  if (ip->matrix) {
1358 slepc 450
    ierr = IPApplyMatrix_Private(ip,x);CHKERRQ(ierr);
2445 jroman 451
    ierr = VecMXDotBegin(ip->Bx,n,y,p);CHKERRQ(ierr);
1329 slepc 452
  } else {
2445 jroman 453
    ierr = VecMXDotBegin(x,n,y,p);CHKERRQ(ierr);
1302 slepc 454
  }
455
  PetscFunctionReturn(0);
456
}
457
 
458
#undef __FUNCT__  
2377 jroman 459
#define __FUNCT__ "IPMInnerProductBegin_Sesquilinear"
460
PetscErrorCode IPMInnerProductBegin_Sesquilinear(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
461
{
462
  PetscErrorCode ierr;
463
 
464
  PetscFunctionBegin;
465
  if (ip->matrix) {
466
    ierr = IPApplyMatrix_Private(ip,x);CHKERRQ(ierr);
467
    ierr = VecMDotBegin(ip->Bx,n,y,p);CHKERRQ(ierr);
468
  } else {
469
    ierr = VecMDotBegin(x,n,y,p);CHKERRQ(ierr);
470
  }
471
  PetscFunctionReturn(0);
472
}
473
 
474
#undef __FUNCT__  
1302 slepc 475
#define __FUNCT__ "IPMInnerProductBegin"
476
/*@
477
   IPMInnerProductBegin - Starts a split phase multiple inner product computation.
478
 
2328 jroman 479
   Collective on IP and Vec
480
 
1302 slepc 481
   Input Parameters:
1423 slepc 482
+  ip - the inner product context
1381 slepc 483
.  x  - the first input vector
1302 slepc 484
.  n  - number of vectors in y
485
.  y  - array of vectors
486
-  p  - where the result will go
487
 
488
   Level: developer
489
 
490
   Notes:
491
   Each call to IPMInnerProductBegin() should be paired with a call to IPMInnerProductEnd().
492
 
493
.seealso: IPMInnerProductEnd(), IPMInnerProduct(), IPNorm(), IPNormBegin(),
494
          IPNormEnd(), IPInnerProduct()
495
@*/
1381 slepc 496
PetscErrorCode IPMInnerProductBegin(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
1302 slepc 497
{
498
  PetscErrorCode ierr;
499
 
500
  PetscFunctionBegin;
2213 jroman 501
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
502
  PetscValidHeaderSpecific(x,VEC_CLASSID,3);
1877 antodo 503
  if (n == 0) PetscFunctionReturn(0);
1302 slepc 504
  PetscValidPointer(y,4);
2213 jroman 505
  PetscValidHeaderSpecific(*y,VEC_CLASSID,4);
1302 slepc 506
  PetscValidScalarPointer(p,5);
507
  ierr = PetscLogEventBegin(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
508
  ip->innerproducts += n;
2377 jroman 509
  ierr = (*ip->ops->minnerproductbegin)(ip,x,n,y,p);CHKERRQ(ierr);
510
  ierr = PetscLogEventEnd(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
511
  PetscFunctionReturn(0);
512
}
513
 
514
#undef __FUNCT__  
515
#define __FUNCT__ "IPMInnerProductEnd_Bilinear"
516
PetscErrorCode IPMInnerProductEnd_Bilinear(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
517
{
518
  PetscErrorCode ierr;
519
 
520
  PetscFunctionBegin;
1329 slepc 521
  if (ip->matrix) {
2445 jroman 522
    ierr = VecMXDotEnd(ip->Bx,n,y,p);CHKERRQ(ierr);
1329 slepc 523
  } else {
2445 jroman 524
    ierr = VecMXDotEnd(x,n,y,p);CHKERRQ(ierr);
1302 slepc 525
  }
526
  PetscFunctionReturn(0);
527
}
528
 
529
#undef __FUNCT__  
2377 jroman 530
#define __FUNCT__ "IPMInnerProductEnd_Sesquilinear"
531
PetscErrorCode IPMInnerProductEnd_Sesquilinear(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
532
{
533
  PetscErrorCode ierr;
534
 
535
  PetscFunctionBegin;
536
  if (ip->matrix) {
537
    ierr = VecMDotEnd(ip->Bx,n,y,p);CHKERRQ(ierr);
538
  } else {
539
    ierr = VecMDotEnd(x,n,y,p);CHKERRQ(ierr);
540
  }
541
  PetscFunctionReturn(0);
542
}
543
 
544
#undef __FUNCT__  
1302 slepc 545
#define __FUNCT__ "IPMInnerProductEnd"
546
/*@
547
   IPMInnerProductEnd - Ends a split phase multiple inner product computation.
548
 
2328 jroman 549
   Collective on IP and Vec
550
 
1302 slepc 551
   Input Parameters:
1423 slepc 552
+  ip - the inner product context
1381 slepc 553
.  x  - the first input vector
1302 slepc 554
.  n  - number of vectors in y
555
-  y  - array of vectors
556
 
557
   Output Parameter:
558
.  p - result of the inner products
559
 
560
   Level: developer
561
 
562
   Notes:
563
   Each call to IPMInnerProductBegin() should be paired with a call to IPMInnerProductEnd().
564
 
565
.seealso: IPMInnerProductBegin(), IPMInnerProduct(), IPNorm(), IPNormBegin(),
566
          IPNormEnd(), IPInnerProduct()
567
@*/
1381 slepc 568
PetscErrorCode IPMInnerProductEnd(IP ip,Vec x,PetscInt n,const Vec y[],PetscScalar *p)
1302 slepc 569
{
570
  PetscErrorCode ierr;
571
 
572
  PetscFunctionBegin;
2213 jroman 573
  PetscValidHeaderSpecific(ip,IP_CLASSID,1);
574
  PetscValidHeaderSpecific(x,VEC_CLASSID,3);
1877 antodo 575
  if (n == 0) PetscFunctionReturn(0);
1302 slepc 576
  PetscValidPointer(y,4);
2213 jroman 577
  PetscValidHeaderSpecific(*y,VEC_CLASSID,4);
1302 slepc 578
  PetscValidScalarPointer(p,5);
579
  ierr = PetscLogEventBegin(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
2377 jroman 580
  ierr = (*ip->ops->minnerproductend)(ip,x,n,y,p);CHKERRQ(ierr);
1302 slepc 581
  ierr = PetscLogEventEnd(IP_InnerProduct,ip,x,0,0);CHKERRQ(ierr);
582
  PetscFunctionReturn(0);
583
}
2373 jroman 584
 
585
EXTERN_C_BEGIN
586
#undef __FUNCT__  
587
#define __FUNCT__ "IPCreate_Bilinear"
588
PetscErrorCode IPCreate_Bilinear(IP ip)
589
{
590
  PetscFunctionBegin;
2377 jroman 591
  ip->ops->normbegin          = IPNormBegin_Bilinear;
592
  ip->ops->normend            = IPNormEnd_Bilinear;
593
  ip->ops->innerproductbegin  = IPInnerProductBegin_Bilinear;
594
  ip->ops->innerproductend    = IPInnerProductEnd_Bilinear;
595
  ip->ops->minnerproductbegin = IPMInnerProductBegin_Bilinear;
596
  ip->ops->minnerproductend   = IPMInnerProductEnd_Bilinear;
2373 jroman 597
  PetscFunctionReturn(0);
598
}
599
 
600
#if defined(PETSC_USE_COMPLEX)
601
#undef __FUNCT__  
602
#define __FUNCT__ "IPCreate_Sesquilinear"
603
PetscErrorCode IPCreate_Sesquilinear(IP ip)
604
{
605
  PetscFunctionBegin;
2377 jroman 606
  ip->ops->normbegin          = IPNormBegin_Sesquilinear;
607
  ip->ops->normend            = IPNormEnd_Sesquilinear;
608
  ip->ops->innerproductbegin  = IPInnerProductBegin_Sesquilinear;
609
  ip->ops->innerproductend    = IPInnerProductEnd_Sesquilinear;
610
  ip->ops->minnerproductbegin = IPMInnerProductBegin_Sesquilinear;
611
  ip->ops->minnerproductend   = IPMInnerProductEnd_Sesquilinear;
2373 jroman 612
  PetscFunctionReturn(0);
613
}
614
#endif
615
EXTERN_C_END
616