Changeset 5890


Ignore:
Timestamp:
09/19/10 09:29:19 (15 years ago)
Author:
Eric.Larour
Message:

Overloaded NewMat, simpler.
Folded NewVecFromLocalSize into NewVec, using boolean fromlocalsize.

Location:
issm/trunk/src/c/toolkits/petsc/patches
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/c/toolkits/petsc/patches/NewMat.cpp

    r3775 r5890  
    1919#include "../../../include/include.h"
    2020
    21 Mat NewMat(int M,int N,double* psparsity,int* pconnectivity,int* pnumberofdofspernode){
     21/*NewMat(int M,int N){{{1*/
     22Mat NewMat(int M,int N){
    2223
    2324        /*output:*/
    2425        Mat outmatrix=NULL;
    2526
    26         /*Recover parameters: */
     27        /*parameters: */
    2728        double sparsity=.001; //default
     29        int    m,n;
     30        int    d_nz,o_nz,nnz;
    2831
    29         int    connectivity=10; //default
    30         int    numberofdofspernode=2; //default
     32        /*Determine local sizes: */
     33        m=PetscDetermineLocalSize(M);
     34        n=PetscDetermineLocalSize(N);
     35       
     36        nnz=(int)((double)M*(double)N*sparsity); //number of non zeros.
     37        d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
     38        o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
    3139
    32         /*local sizes: */
     40        MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
     41
     42        return outmatrix;
     43}
     44/*}}}*/
     45/*NewMat(int M,int N,double sparsity){{{1*/
     46Mat NewMat(int M,int N,double sparsity){
     47
     48        /*output:*/
     49        Mat outmatrix=NULL;
     50
     51        /*parameters: */
    3352        int    m,n;
    34 
    35         /*row and col distribution: */
    3653        int    d_nz,o_nz;
    3754        int    nnz;
     
    4158        n=PetscDetermineLocalSize(N);
    4259       
    43         /*Branch on what was provided: */
     60        nnz=(int)((double)M*(double)N*sparsity); //number of non zeros.
     61        d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
     62        o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
    4463
    45         if(!psparsity && !pconnectivity && !pnumberofdofspernode){
    46 
    47                 /*Ok, we have our default sparsity, create matrix using this info: */
    48 
    49                 nnz=(int)((double)M*(double)N*sparsity); //number of non zeros.
    50                 d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
    51                 o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
    52 
    53                 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
    54 
    55         }
    56         else if(psparsity){
    57                
    58                 /*Same as above, except we bypass the default sparsity: */
    59                 if(pconnectivity || pnumberofdofspernode)
    60                         ISSMERROR("%s%p%s%p%s%p","cannot determine logic with following set of pointers-> sparsity: ", psparsity," connectivity: ",pconnectivity," numberofdofspernode: ",pnumberofdofspernode);
    61 
    62                 sparsity=*psparsity;
    63 
    64                 nnz=(int)((double)M*(double)N*sparsity); //number of non zeros.
    65                 d_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
    66                 o_nz=(int)((double)nnz/(double)M/2.0); //number of non zeros per row/2
    67 
    68                 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
    69 
    70         }
    71         else if(pconnectivity &&  pnumberofdofspernode){
    72 
    73                 /*entirely different logic. We use the connectivity and numberofdofspernode to figure out how many non-zeros are
    74                  *present per row: */
    75 
    76                 if(psparsity) ISSMERROR("%s%p%s%p%s%p","cannot determine logic with following set of pointers-> sparsity: ", psparsity," connectivity: ",pconnectivity," numberofdofspernode: ",pnumberofdofspernode);
    77 
    78                 connectivity=*pconnectivity;
    79                 numberofdofspernode=*pnumberofdofspernode;
    80        
    81                 /*Figure out number of non zeros per row: */
    82                 d_nz=(int)connectivity*numberofdofspernode/2;
    83                 o_nz=(int)connectivity*numberofdofspernode/2;
    84                
    85                 MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
    86 
    87         }
    88         else{
    89                 ISSMERROR("%s%p%s%p%s%p","cannot determine logic with following set of pointers-> sparsity: ", psparsity," connectivity: ",pconnectivity," numberofdofspernode: ",pnumberofdofspernode);
    90         }
     64        MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
    9165
    9266        return outmatrix;
    9367}
     68/*}}}*/
     69/*NewMat(int M,int N,int connectivity,int numberofdofspernode){{{1*/
     70Mat NewMat(int M,int N,int connectivity,int numberofdofspernode){
     71
     72        /*output:*/
     73        Mat outmatrix=NULL;
     74
     75        /*parameters: */
     76        int    m,n;
     77        int    d_nz,o_nz;
     78        int    nnz;
     79
     80        /*Determine local sizes: */
     81        m=PetscDetermineLocalSize(M);
     82        n=PetscDetermineLocalSize(N);
     83       
     84        /*Figure out number of non zeros per row: */
     85        d_nz=(int)connectivity*numberofdofspernode/2;
     86        o_nz=(int)connectivity*numberofdofspernode/2;
     87
     88        MatCreateMPIAIJ(MPI_COMM_WORLD,m,n,M,N,d_nz,NULL,o_nz,NULL,&outmatrix);
     89
     90        return outmatrix;
     91}
     92/*}}}*/
  • issm/trunk/src/c/toolkits/petsc/patches/NewVec.cpp

    r1 r5890  
    1616#include "./petscpatches.h"
    1717
    18 Vec NewVec(int size){
     18Vec NewVec(int size,bool fromlocalsize){
    1919
    2020        int ierr;
     
    2525
    2626        /*determine local size of vector: */
    27         local_size=PetscDetermineLocalSize(size);
     27        if(fromlocalsize){
     28                local_size=size;
     29        }
     30        else{
     31                local_size=PetscDetermineLocalSize(size);
     32        }
     33       
    2834        VecCreate(PETSC_COMM_WORLD,&vector);
    2935       
     
    3642        return vector;
    3743}
    38 
    39 
    40 
    41 
  • issm/trunk/src/c/toolkits/petsc/patches/petscpatches.h

    r5787 r5890  
    2222
    2323int PetscDetermineLocalSize(int global_size);
    24 Vec NewVec(int size);
    25 Vec NewVecFromLocalSize(int local_size);
    26 Mat NewMat(int M,int N,double* psparsity,int* pconnectivity,int* pnumberofdofspernode);
     24Vec NewVec(int size,bool fromlocalsize);
     25Mat NewMat(int M,int N);
     26Mat NewMat(int M,int N,double sparsity);
     27Mat NewMat(int M,int N,int connectivity,int numberofdofspernode);
     28
    2729int VecTranspose(Vec* tvector,Vec vector);
    2830int VecToMPISerial(double** pgathered_vector, Vec vector);
Note: See TracChangeset for help on using the changeset viewer.