~ubuntu-branches/ubuntu/warty/petsc/warty

« back to all changes in this revision

Viewing changes to src/vec/examples/tutorials/ex16.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2004-06-07 13:41:43 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040607134143-92p586zrauvie0le
Tags: 2.2.0-2
* Upstream patch level 2.
* New PETSC_BOPT_EXTRA option for different BOPT and lib names, with _c++
  symlinks only for plain and single (closes: #249617).
* New DEBIAN_DIST=contrib option to link with hypre, parmetis (closes:
  #249619).
* Combined petsc-c and petsc-fortran substvars into petsc-compilers.
* Extra quote in -dev prerm eliminates "too many arguments" problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*$Id: ex12.c,v 1.18 2001/09/11 16:32:18 bsmith Exp $*/
 
2
 
 
3
/* Program usage:  mpirun ex1 [-help] [all PETSc options] */
 
4
 
 
5
static char help[] = "Demonstrates VecStrideScatter() and VecStrideGather() with subvectors that are also strided.\n\n";
 
6
 
 
7
/*T
 
8
   Concepts: vectors^sub-vectors;
 
9
   Processors: n
 
10
T*/
 
11
 
 
12
/* 
 
13
  Include "petscvec.h" so that we can use vectors.  Note that this file
 
14
  automatically includes:
 
15
     petsc.h       - base PETSc routines   petscis.h     - index sets
 
16
     petscsys.h    - system routines       petscviewer.h - viewers
 
17
*/
 
18
 
 
19
#include "petscvec.h"
 
20
 
 
21
#undef __FUNCT__
 
22
#define __FUNCT__ "main"
 
23
int main(int argc,char **argv)
 
24
{
 
25
  Vec           v,s,r,vecs[2];               /* vectors */
 
26
  int           i,start,end,n = 20,ierr;
 
27
  PetscScalar   one = 1.0,value;
 
28
 
 
29
  ierr = PetscInitialize(&argc,&argv,(char*)0,help);CHKERRQ(ierr); 
 
30
  ierr = PetscOptionsGetInt(PETSC_NULL,"-n",&n,PETSC_NULL);CHKERRQ(ierr);
 
31
 
 
32
  /* 
 
33
      Create multi-component vector with 2 components
 
34
  */
 
35
  ierr = VecCreate(PETSC_COMM_WORLD,&v);CHKERRQ(ierr);
 
36
  ierr = VecSetSizes(v,PETSC_DECIDE,n);CHKERRQ(ierr);
 
37
  ierr = VecSetBlockSize(v,4);CHKERRQ(ierr);
 
38
  ierr = VecSetFromOptions(v);CHKERRQ(ierr);
 
39
 
 
40
  /* 
 
41
      Create double-component vectors
 
42
  */
 
43
  ierr = VecCreate(PETSC_COMM_WORLD,&s);CHKERRQ(ierr);
 
44
  ierr = VecSetSizes(s,PETSC_DECIDE,n/2);CHKERRQ(ierr);
 
45
  ierr = VecSetBlockSize(s,2);CHKERRQ(ierr);
 
46
  ierr = VecSetFromOptions(s);CHKERRQ(ierr);
 
47
  ierr = VecDuplicate(s,&r);CHKERRQ(ierr);
 
48
 
 
49
  vecs[0] = s;
 
50
  vecs[1] = r;
 
51
  /*
 
52
     Set the vector values
 
53
  */
 
54
  ierr = VecGetOwnershipRange(v,&start,&end);CHKERRQ(ierr);
 
55
  for (i=start; i<end; i++) {
 
56
    value = i;
 
57
    ierr  = VecSetValues(v,1,&i,&value,INSERT_VALUES);CHKERRQ(ierr);
 
58
  }
 
59
 
 
60
  /*
 
61
     Get the components from the multi-component vector to the other vectors
 
62
  */
 
63
  ierr = VecStrideGatherAll(v,vecs,INSERT_VALUES);CHKERRQ(ierr);
 
64
 
 
65
  ierr = VecView(s,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
 
66
  ierr = VecView(r,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
 
67
 
 
68
  ierr = VecStrideScatterAll(vecs,v,ADD_VALUES);CHKERRQ(ierr);
 
69
 
 
70
  ierr = VecView(v,PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
 
71
 
 
72
  /* 
 
73
     Free work space.  All PETSc objects should be destroyed when they
 
74
     are no longer needed.
 
75
  */
 
76
  ierr = VecDestroy(v);CHKERRQ(ierr);
 
77
  ierr = VecDestroy(s);CHKERRQ(ierr);
 
78
  ierr = VecDestroy(r);CHKERRQ(ierr);
 
79
  ierr = PetscFinalize();CHKERRQ(ierr);
 
80
  return 0;
 
81
}
 
82