source: issm/trunk/src/c/toolkits/petsc/patches/SerialToVec.cpp@ 586

Last change on this file since 586 was 586, checked in by Eric.Larour, 16 years ago

Added dakota parallel c code capability + Prognostic capability

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/*Matlab includes: */
17#include "mex.h"
18
19#include "../../../shared/shared.h"
20
21Vec SerialToVec(double* vector,int vector_size){
22
23 int i;
24
25 /*output: */
26 Vec outvector=NULL;
27
28 /*petsc indices: */
29 int* idxn=NULL;
30 double* values=NULL;
31 int lower_row,upper_row,range;
32
33
34 /*Create parallel vector: */
35 outvector=NewVec(vector_size);
36
37 /*plug values from local vector into new parallel vector: */
38 VecGetOwnershipRange(outvector,&lower_row,&upper_row);
39 upper_row--;
40 range=upper_row-lower_row+1;
41
42 if (range){
43 idxn=(int*)xmalloc(range*sizeof(int));
44 values=(double*)xmalloc(range*sizeof(double));
45 for (i=0;i<range;i++){
46 idxn[i]=lower_row+i;
47 values[i]=vector[idxn[i]];
48 }
49
50 VecSetValues(outvector,range,idxn,values,INSERT_VALUES);
51 }
52
53
54 /*Assemble vector: */
55 VecAssemblyBegin(outvector);
56 VecAssemblyEnd(outvector);
57
58 /*Free ressources:*/
59 xfree((void**)&idxn);
60 xfree((void**)&values);
61
62 return outvector;
63}
Note: See TracBrowser for help on using the repository browser.