Last change
on this file since 11995 was 11995, checked in by Mathieu Morlighem, 13 years ago |
merged trunk-jpl and trunk for revision 11994M
|
File size:
1.2 KB
|
Line | |
---|
1 | /* \file SerialToVec.cpp
|
---|
2 | * \brief: convert a serial vector on all cpus into a parallel vector
|
---|
3 | */
|
---|
4 |
|
---|
5 | #ifdef HAVE_CONFIG_H
|
---|
6 | #include <config.h>
|
---|
7 | #else
|
---|
8 | #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
|
---|
9 | #endif
|
---|
10 |
|
---|
11 | /*Petsc includes: */
|
---|
12 | #include "petscmat.h"
|
---|
13 | #include "petscvec.h"
|
---|
14 | #include "petscksp.h"
|
---|
15 |
|
---|
16 | #include "../../../shared/shared.h"
|
---|
17 |
|
---|
18 | Vec SerialToVec(double* vector,int vector_size){
|
---|
19 |
|
---|
20 | int i;
|
---|
21 |
|
---|
22 | /*output: */
|
---|
23 | Vec outvector=NULL;
|
---|
24 |
|
---|
25 | /*petsc indices: */
|
---|
26 | int* idxn=NULL;
|
---|
27 | double* values=NULL;
|
---|
28 | int lower_row,upper_row,range;
|
---|
29 |
|
---|
30 |
|
---|
31 | /*Create parallel vector: */
|
---|
32 | outvector=NewVec(vector_size);
|
---|
33 |
|
---|
34 | /*plug values from local vector into new parallel vector: */
|
---|
35 | VecGetOwnershipRange(outvector,&lower_row,&upper_row);
|
---|
36 | upper_row--;
|
---|
37 | range=upper_row-lower_row+1;
|
---|
38 |
|
---|
39 | if (range){
|
---|
40 | idxn=(int*)xmalloc(range*sizeof(int));
|
---|
41 | values=(double*)xmalloc(range*sizeof(double));
|
---|
42 | for (i=0;i<range;i++){
|
---|
43 | idxn[i]=lower_row+i;
|
---|
44 | values[i]=vector[idxn[i]];
|
---|
45 | }
|
---|
46 |
|
---|
47 | VecSetValues(outvector,range,idxn,values,INSERT_VALUES);
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | /*Assemble vector: */
|
---|
52 | VecAssemblyBegin(outvector);
|
---|
53 | VecAssemblyEnd(outvector);
|
---|
54 |
|
---|
55 | /*Free ressources:*/
|
---|
56 | xfree((void**)&idxn);
|
---|
57 | xfree((void**)&values);
|
---|
58 |
|
---|
59 | return outvector;
|
---|
60 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.