Actual source code: senddense.c

      1: #define PETSC_DLL

     3:  #include src/sys/src/viewer/impls/socket/socket.h

      7: /*@C
      8:    PetscViewerSocketPutScalar - Passes a Scalar array to a Socket PetscViewer.

     10:   Input Parameters:
     11: +  viewer - obtained from PetscViewerSocketOpen()
     12: .  m - number of rows of array
     13: .  m - number of columns of array
     14: -  array - the array stored in column ordering (matrix or vector data)

     16:     Level: advanced

     18:    Notes:
     19:    Most users should not call this routine, but instead should employ
     20:    either
     21: .vb
     22:      MatView(Mat matrix,PetscViewer viewer)
     23:               or
     24:      VecView(Vec vector,PetscViewer viewer)
     25: .ve

     27:    Concepts: Matlab^sending data
     28:    Concepts: sockets^sending data

     30: .seealso: PetscViewerSocketOpen(), MatView(), VecView(), PetscViewerSocketPutReal(), PetscViewerSocketPutScalar(),
     31:       PETSC_VIEWER_SOCKET_, PETSC_VIEWER_SOCKET_WORLD, PETSC_VIEWER_SOCKET_SELF
     32: @*/
     33: PetscErrorCode PETSC_DLLEXPORT PetscViewerSocketPutScalar(PetscViewer viewer,PetscInt m,PetscInt n,PetscScalar *array)
     34: {
     35:   PetscViewer_Socket *vmatlab = (PetscViewer_Socket*)viewer->data;
     36:   PetscErrorCode     ierr;
     37:   PetscMPIInt        rank;
     38:   int                t = vmatlab->port,type = DENSEREAL,value;

     41:   MPI_Comm_rank(viewer->comm, &rank);
     42:   if (rank) {
     43:     SETERRQ(PETSC_ERR_ARG_WRONG, "Socket viewers may only write from process 0");
     44:   }
     45:   PetscBinaryWrite(t,&type,1,PETSC_INT,PETSC_FALSE);
     46:   PetscBinaryWrite(t,&m,1,PETSC_INT,PETSC_FALSE);
     47:   PetscBinaryWrite(t,&n,1,PETSC_INT,PETSC_FALSE);
     48: #if !defined(PETSC_USE_COMPLEX)
     49:   value = 0;
     50: #else
     51:   value = 1;
     52: #endif
     53:   PetscBinaryWrite(t,&value,1,PETSC_INT,PETSC_FALSE);
     54:   PetscBinaryWrite(t,array,m*n,PETSC_SCALAR,PETSC_FALSE);
     55:   return(0);
     56: }

     60: /*@C
     61:    PetscViewerSocketPutReal - Passes a double (or single) precision array to
     62:    a Matlab PetscViewer.

     64:   Input Parameters:
     65: +  viewer - obtained from PetscViewerSocketOpen()
     66: .  m - number of rows of array
     67: .  m - number of columns of array
     68: -  array - the array stored in column ordering (matrix or vector data)

     70:     Level: advanced

     72:    Notes:
     73:    Most users should not call this routine, but instead should employ
     74:    either
     75: .vb
     76:      MatView(Mat matrix,PetscViewer viewer)
     77:               or
     78:      VecView(Vec vector,PetscViewer viewer)
     79: .ve

     81:    Concepts: Matlab^sending data
     82:    Concepts: sockets^sending data

     84: .seealso: PetscViewerSocketOpen(), MatView(), VecView(), PetscViewerSocketPutInt(), PetscViewerSocketPutReal(),
     85:           PETSC_VIEWER_SOCKET_, PETSC_VIEWER_SOCKET_WORLD, PETSC_VIEWER_SOCKET_SELF
     86: @*/
     87: PetscErrorCode PETSC_DLLEXPORT PetscViewerSocketPutReal(PetscViewer viewer,PetscInt m,PetscInt n,PetscReal *array)
     88: {
     89:   PetscViewer_Socket *vmatlab = (PetscViewer_Socket*)viewer->data;
     90:   PetscErrorCode     ierr;
     91:   PetscMPIInt        rank;
     92:   int                t = vmatlab->port,type = DENSEREAL,value;

     95:   MPI_Comm_rank(viewer->comm, &rank);
     96:   if (rank) {
     97:     SETERRQ(PETSC_ERR_ARG_WRONG, "Socket viewers may only write from process 0");
     98:   }
     99:   PetscBinaryWrite(t,&type,1,PETSC_INT,PETSC_FALSE);
    100:   PetscBinaryWrite(t,&m,1,PETSC_INT,PETSC_FALSE);
    101:   PetscBinaryWrite(t,&n,1,PETSC_INT,PETSC_FALSE);
    102:   value = 0;
    103:   PetscBinaryWrite(t,&value,1,PETSC_INT,PETSC_FALSE);
    104:   PetscBinaryWrite(t,array,m*n,PETSC_REAL,PETSC_FALSE);
    105:   return(0);
    106: }

    111: /*@C
    112:    PetscViewerSocketPutInt - Passes an integer array to a Socket PetscViewer.

    114:    Input Parameters:
    115: +  viewer - obtained from PetscViewerSocketOpen()
    116: .  m - number of rows of array
    117: -  array - the array stored in column ordering (matrix or vector data)

    119:     Level: advanced

    121:    Notes:
    122:    Most users should not call this routine, but instead should employ either
    123: .vb
    124:      MatView(Mat matrix,PetscViewer viewer)
    125:               or
    126:      VecView(Vec vector,PetscViewer viewer)
    127: .ve

    129:    Concepts: Matlab^sending data
    130:    Concepts: sockets^sending data

    132: .seealso: PetscViewerSocketOpen(), MatView(), VecView(), PetscViewerSocketPutScalar(), PetscViewerSocketPutReal(),
    133:        PETSC_VIEWER_SOCKET_, PETSC_VIEWER_SOCKET_WORLD, PETSC_VIEWER_SOCKET_SELF
    134: @*/
    135: PetscErrorCode PETSC_DLLEXPORT PetscViewerSocketPutInt(PetscViewer viewer,PetscInt m,PetscInt *array)
    136: {
    137:   PetscViewer_Socket *vmatlab = (PetscViewer_Socket*)viewer->data;
    138:   PetscErrorCode     ierr;
    139:   PetscMPIInt        rank;
    140:   int                t = vmatlab->port,type = DENSEINT;

    143:   MPI_Comm_rank(viewer->comm, &rank);
    144:   if (rank) {
    145:     SETERRQ(PETSC_ERR_ARG_WRONG, "Socket viewers may only write from process 0");
    146:   }
    147:   PetscBinaryWrite(t,&type,1,PETSC_INT,PETSC_FALSE);
    148:   PetscBinaryWrite(t,&m,1,PETSC_INT,PETSC_FALSE);
    149:   PetscBinaryWrite(t,array,m,PETSC_INT,PETSC_FALSE);
    150:   return(0);
    151: }