|
Last change
on this file since 9320 was 9320, checked in by Eric.Larour, 14 years ago |
|
Quality control changes:
- "stdlib" to <stdlib> and similar header file problems.
- fscanf vulnerabilities issues.
|
|
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 | #ifdef _SERIAL_
|
|---|
| 18 | #include "mex.h"
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 | #include "../../../shared/shared.h"
|
|---|
| 22 |
|
|---|
| 23 | Vec SerialToVec(double* vector,int vector_size){
|
|---|
| 24 |
|
|---|
| 25 | int i;
|
|---|
| 26 |
|
|---|
| 27 | /*output: */
|
|---|
| 28 | Vec outvector=NULL;
|
|---|
| 29 |
|
|---|
| 30 | /*petsc indices: */
|
|---|
| 31 | int* idxn=NULL;
|
|---|
| 32 | double* values=NULL;
|
|---|
| 33 | int lower_row,upper_row,range;
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | /*Create parallel vector: */
|
|---|
| 37 | outvector=NewVec(vector_size);
|
|---|
| 38 |
|
|---|
| 39 | /*plug values from local vector into new parallel vector: */
|
|---|
| 40 | VecGetOwnershipRange(outvector,&lower_row,&upper_row);
|
|---|
| 41 | upper_row--;
|
|---|
| 42 | range=upper_row-lower_row+1;
|
|---|
| 43 |
|
|---|
| 44 | if (range){
|
|---|
| 45 | idxn=(int*)xmalloc(range*sizeof(int));
|
|---|
| 46 | values=(double*)xmalloc(range*sizeof(double));
|
|---|
| 47 | for (i=0;i<range;i++){
|
|---|
| 48 | idxn[i]=lower_row+i;
|
|---|
| 49 | values[i]=vector[idxn[i]];
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | VecSetValues(outvector,range,idxn,values,INSERT_VALUES);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | /*Assemble vector: */
|
|---|
| 57 | VecAssemblyBegin(outvector);
|
|---|
| 58 | VecAssemblyEnd(outvector);
|
|---|
| 59 |
|
|---|
| 60 | /*Free ressources:*/
|
|---|
| 61 | xfree((void**)&idxn);
|
|---|
| 62 | xfree((void**)&values);
|
|---|
| 63 |
|
|---|
| 64 | return outvector;
|
|---|
| 65 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.