Actual source code: receivedense.c
1: /*
2: This is part of the MatlabSockettool Package. It is called by
3: the receive.mex4 Matlab program.
4:
5: Written by Barry Smith, bsmith@mcs.anl.gov 4/14/92
6: Updated by Ridhard Katz, katz@ldeo.columbia.edu 9/28/03
8: Since this is called from Matlab it cannot be compiled with C++.
9: */
14: #include <stdio.h>
15: #include petscsys.h
16: #include "mex.h"
17: #define PETSC_MEX_ERROR(a) {fprintf(stdout,"RECEIVE %s \n",a); return -1;}
18: /*-----------------------------------------------------------------*/
21: PetscErrorCode ReceiveDenseMatrix(mxArray *plhs[],int t)
22: {
23: int m,n,i;
24: mxComplexity compx = mxREAL;
25:
26: /* get size of matrix */
27: if (PetscBinaryRead(t,&m,1,PETSC_INT)) PETSC_MEX_ERROR("reading number columns");
28: if (PetscBinaryRead(t,&n,1,PETSC_INT)) PETSC_MEX_ERROR("reading number rows");
29: if (PetscBinaryRead(t,&compx,1,PETSC_INT)) PETSC_MEX_ERROR("reading if complex");
30:
31: /*allocate matrix */
32: plhs[0] = mxCreateDoubleMatrix(m,n,compx);
33: /* read in matrix */
34: if (compx == mxREAL) {
35: if (PetscBinaryRead(t,mxGetPr(plhs[0]),n*m,PETSC_DOUBLE)) PETSC_MEX_ERROR("read dense matrix");
36: } else {
37: for (i=0; i<n*m; i++) {
38: if (PetscBinaryRead(t,mxGetPr(plhs[0])+i,1,PETSC_DOUBLE))PETSC_MEX_ERROR("read dense matrix");
39: if (PetscBinaryRead(t,mxGetPi(plhs[0])+i,1,PETSC_DOUBLE))PETSC_MEX_ERROR("read dense matrix");
40: }
41: }
42: return 0;
43: }
47: PetscErrorCode ReceiveDenseIntMatrix(mxArray *plhs[],int t)
48: {
49: int m,i,*array;
50: double *values;
53: /* get size of matrix */
54: PetscBinaryRead(t,&m,1,PETSC_INT); if (ierr) PETSC_MEX_ERROR("reading number columns");
55:
56: /*allocate matrix */
57: plhs[0] = mxCreateDoubleMatrix(m,1,mxREAL);
59: /* read in matrix */
60: array = (int*) malloc(m*sizeof(int)); if (!array) PETSC_MEX_ERROR("reading allocating space");
61: PetscBinaryRead(t,array,m,PETSC_INT); if (ierr) PETSC_MEX_ERROR("read dense matrix");
63: values = mxGetPr(plhs[0]);
64: for (i =0; i<m; i++) {
65: values[i] = array[i];
66: }
67: free(array);
69: return 0;
70: }
71:
72: