Ignore:
Timestamp:
03/14/12 17:09:20 (13 years ago)
Author:
Mathieu Morlighem
Message:

Added support for empty vectors in serial mode

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/c/toolkits/petsc/patches/PetscVectorToMatlabVector.cpp

    r9320 r11716  
    2727int PetscVectorToMatlabVector(mxArray** pdataref,Vec vector){
    2828
    29 
    30         int i;
    31         int rows;
    32         int* idxm=NULL;
    33         double* values=NULL;
     29        int     i;
     30        int     rows;
     31        int    *idxm   = NULL;
     32        double *values = NULL;
    3433
    3534        /*output: */
     
    3736
    3837        /*Get size of vector: */
    39         VecGetSize(vector,&rows);
     38        if(vector){
     39                VecGetSize(vector,&rows);
     40                if(rows){
     41                        idxm=(int*)xmalloc(rows*sizeof(int));
     42                        values=(double*)xmalloc(rows*sizeof(double));
     43                        for(i=0;i<rows;i++)idxm[i]=i;
    4044
    41         if(rows){
    42                 idxm=(int*)xmalloc(rows*sizeof(int));
    43                 values=(double*)xmalloc(rows*sizeof(double));
    44                 for(i=0;i<rows;i++)idxm[i]=i;
    45                  
    46                 VecGetValues(vector,rows,idxm,values);
     45                        VecGetValues(vector,rows,idxm,values);
     46                }
     47        }
     48        else{
     49                rows=0;
    4750        }
    4851
     
    6164}
    6265
    63 
    6466#endif  //#ifdef _SERIAL_
    65 
Note: See TracChangeset for help on using the changeset viewer.