2008/9/25

Conditional operator <-> ternary operator

condition ? expression1 : expression2
C = A > B ? V1: V2;

if (A>B) C = V1;
elese C =V2;

2008/9/24

Distribution Data (DA)

DAGetInfo
Gets information about a given distributed array.
Synopsis
#include "petscda.h"
PetscErrorCode PETSCDM_DLLEXPORT DAGetInfo(DA da,PetscInt *dim,PetscInt *M,PetscInt *N,PetscInt *P,PetscInt *m,PetscInt *n,PetscInt *p,PetscInt *dof,PetscInt *s,DAPeriodicType *wrap,DAStencilType *st)
Input Parameter
da -the distributed array
Output Parameters
dim - dimension of the distributed array (1, 2, or 3)
M, N, P - global dimension in each direction of the array
m, n, p - corresponding number of procs in each dimension
dof - number of degrees of freedom per node
s - stencil width
wrap - type of periodicity, one of DA_NONPERIODIC, DA_XPERIODIC, DA_YPERIODIC, DA_XYPERIODIC, DA_XYZPERIODIC, DA_XZPERIODIC, DA_YZPERIODIC,DA_ZPERIODIC
st - stencil type, either DA_STENCIL_STAR or DA_STENCIL_BOX
Note
Use PETSC_NULL (PETSC_NULL_INTEGER in Fortran) in place of any output parameter that is not of interest.

DAGetCorners
Returns the global (x,y,z) indices of the lower left corner of the local region, excluding ghost points.
Synopsis
#include "petscda.h"
PetscErrorCode PETSCDM_DLLEXPORT DAGetCorners(DA da,PetscInt *x,PetscInt *y,PetscInt *z,PetscInt *m,PetscInt *n,PetscInt *p)
Input Parameter
da -the distributed array
Output Parameters
x,y,z - the corner indices (where y and z are optional; these are used for 2D and 3D problems)
m,n,p - widths in the corresponding directions (where n and p are optional; these are used for 2D and 3D problems)
Note
The corner information is independent of the number of degrees of freedom per node set with the DACreateXX() routine. Thus the x, y, z, and m, n, p can be thought of as coordinates on a logical grid, where each grid point has (potentially) several degrees of freedom. Any of y, z, n, and p can be passed in as PETSC_NULL if not needed.

2008/9/17

Data Visualizer

MayaVi
homepage: http://mayavi.sourceforge.net/index.html
  • An easy to use GUI.
  • Can be imported as a Python module from other Python programs and can also be scripted from the Python interpreter.
  • Provides modules to:
    • Visualize computational grids.
    • Visualize scalar, vector and tensor data.
  • Quite a few data filters are also provided.
  • Supports volume visualization of data via texture and ray cast mappers.
  • ParaView
    Homepage: http://www.paraview.org/New/index.html

    ParaView is an open-source, multi-platform application designed to visualize data sets of size varying from small to very large. The goals of the ParaView project include the following:

    • Develop an open-source, multi-platform visualization application.
    • Support distributed computation models to process large data sets.
    • Create an open, flexible, and intuitive user interface.
    • Develop an extensible architecture based on open standards.
    OpenDX
    Homepage: http://www.opendx.org/
    OpenDX gives you new control over your data...and new insights into their meaning. Yet OpenDX is easy to use because it lets you visualize data in ways you've never dreamed of--without getting bogged down in the technology.

    2008/9/11

    PetscBarrier

    PetscBarrier
    Blocks until this routine is executed by all processors owning the object A.
    Synopsis
    #include "petsc.h"
    PetscErrorCode PetscBarrier(PetscObject obj)
    Input Parameters
    A -PETSc object (Mat, Vec, IS, SNES etc...) Must be caste with a (PetscObject), can use PETSC_NULL (for MPI_COMM_WORLD)

    Easy usage: PetscBarrier(PETSC_NULL)

    C++ command-line arguments

    When running a C++ program in command-line mode in Unix (e.g. telnet or dtterm session), or in MSDOS mode on Windows, you can type extra arguments following the program name. These arguments are automatically passed as string parameters to the main routine.
    For instant, if our program name is a.out, we may type in ./a.out -m 20 -n 30 -z 90 -haha happy from the terminal, and the string "may" would automatically be passed as a parameter to the main routine of our a.out program.
    To use these parameters, we must specify in our main routine what the parameter names and types are, and the format is exactly as follows:
    int main(int argc, char *argv[])
    Each argument is passed as a seperate character array, so argv[1] points to the first argument text, argv[2] points to the second argument text, etc. (argv[0] gives you the name of the executable file for the program itself)
    example
    How to execute:
    ./a.out -n 30 -m 40

    2008/9/10

    vector function in PETSc

    VecCreate
    Creates an empty vector object
    Synopsis
    #include "petscvec.h"
    VecCreate(MPI_Comm comm, Vec *vec)

    VecSetSizes
    Sets the local and global sizes, and checks to determine compatibility
    Synopsis
    #include "petscvec.h"
    PetscErrorCode PETSCVEC_DLLEXPORT VecSetSizes(Vec v, PetscInt n, PetscInt N)
    Parameter
    v-the vector
    n-localsize
    N-Globalsize

    MPI function in PETCs

    MPI_Comm_rank

    #include "mpi.h"
    int MPI_Comm_rank ( MPI_Comm comm, int *rank)
    Determines the rank of the calling process in the communicator

    2008/9/9

    Sone definition of PETSc parameter

    • PetscMPIInt = int {typedef int PetscMPIInt}
    • PetscErrorCode = int {typedef int PetscErrorCode}
    • PetscInt = int {no 64bit }
    • PetscInt = long long {64bit}
    • PetscErrorCode = int {typedef int PetscErrorCode}

    2008/9/8

    同時使用c的stdio.h和c++的iostream

    同時使用c的stdio.h和c++的iostream需要呼叫特殊的iostream函式
    ios::sync_with_stdio();

    C++除錯用cerr

    iostream 函式庫提供了cerr,讓你可以寫到標準錯誤。cerr的用法和cout非常類似,但是他並不會將輸出的data儲存在buffer。在真正顯示之前,先將所要顯示的字元儲存在buffer,這種做法可以加快顯示的速度,但是cerr並不使用這種做法,這樣才可以立刻顯示儲錯訊息。

    2008/9/2

    兩個程式檔.cpp的全域變數的宣告

    In main.cpp
    object global_value=xxx;
    int main(){
    .......
    }
    In function.cpp
    extern object global_value;
    int function(){
    }

    How to compiler PETSc's program and run

    Makefile:

    include ${PETSC_DIR}/bmake/common/base
    include ${PETSC_DIR}/bmake/common/test
    print.out: p-hellow.o
    ${CLINKER} -o print.out p-hellow.o ${PETSC_LIB}

    Note: It will find correspond file name automatically.
    For example: p-hellow.o -> p-hellow.cpp

    runfile:
    ${PETSC_DIR}/bin/petscmpiexec -np 2 ./print.out
    OR
    mpirun -np 2 ./print.out