84 if (outputBuffer != NULL) {
85 if (engOutputBuffer(
Engine_, outputBuffer, outputBufferSize)) {
89 if (engEvalString(
Engine_, command)) {
103 pr = mxGetPr(matlabA);
107 mxDestroyArray(matlabA);
113 mxDestroyArray(matlabA);
117 mxDestroyArray(matlabA);
123 mxArray* matlabA = 0;
132 mxDestroyArray(matlabA);
149 mxDestroyArray(matlabA);
154 char* buff =
new char[128];;
155 sprintf(buff,
"%s = %s'", variableName, variableName);
157 mxDestroyArray(matlabA);
164 mxDestroyArray(matlabA);
178 mxArray* matlabA = 0;
183 matlabA = mxCreateDoubleMatrix(numRows, numCols, mxREAL);
187 double* targetPtr = 0;
188 double* sourcePtr = 0;
189 double* source = (
double*)A.
A();
190 double* target = (
double*)mxGetPr(matlabA);
191 int source_LDA = A.
LDA();
192 int target_LDA = A.
LDA();
193 for (col = 0; col < numCols; col++) {
194 targetPtr = target + (col * target_LDA);
195 sourcePtr = source + (col * source_LDA);
196 for (row = 0; row < numRows; row++) {
197 *targetPtr++ = *sourcePtr++;
202 mxDestroyArray(matlabA);
206 mxDestroyArray(matlabA);
214 int* numVectors =
new int[1];
215 int* temp =
new int[1];
222 int* numVectors =
new int[1];
223 int* temp =
new int[1];
236 mxArray* matlabA = 0;
243 matlabA = mxCreateDoubleMatrix(numRows, numCols, mxREAL);
247 double* targetPtr = 0;
249 int* source = (
int*)A.
A();
250 double* target = (
double*)mxGetPr(matlabA);
251 int source_LDA = A.
LDA();
252 int target_LDA = A.
LDA();
253 for (col = 0; col < numCols; col++) {
254 targetPtr = target + (col * target_LDA);
255 sourcePtr = source + (col * source_LDA);
256 for (row = 0; row < numRows; row++) {
257 *targetPtr++ = *sourcePtr++;
262 mxDestroyArray(matlabA);
268 int* numVectors =
new int[2];
270 int* temp =
new int[2];
276 int* temp =
new int[2];
282 int numRows = numVectors[1];
283 int numCols = numVectors[0];
284 double* targetPtr = 0;
290 matlabA = mxCreateDoubleMatrix(numRows, numCols, mxREAL);
291 target = (
double*)mxGetPr(matlabA);
310 for(
int i=0; i < numVectors[0]; i++) {
320 targetPtr = target + (i * numRows);
321 sourcePtr = (
int*)tgIntVector.
Values();
322 for (row = 0; row < numRows; row++) {
323 *targetPtr++ = *sourcePtr++;
329 mxDestroyArray(matlabA);
334 mxDestroyArray(matlabA);
340 mxArray* matlabA = 0;
347 matlabA = mxCreateSparse(
N, M, M*
N, mxREAL);
348 int* matlabAcolumnIndicesPtr = mxGetJc(matlabA);
349 matlabAcolumnIndicesPtr += M;
350 *matlabAcolumnIndicesPtr = M*
N;
354 mxDestroyArray(matlabA);
360 mxDestroyArray(matlabA);
365 char* buff =
new char[128];;
366 sprintf(buff,
"%s = %s'", variableName, variableName);
368 mxDestroyArray(matlabA);
374 mxDestroyArray(matlabA);
383#ifdef USE_ENGPUTARRAY
385 mxSetName(matlabA, variableName);
386 return(engPutArray(
Engine_, matlabA));
389 return(engPutVariable(
Engine_, variableName, matlabA));
395 mxArray* matlabA = 0;
397 if (ierr =
GetmxArray(variableName, &matlabA)) {
398 mxDestroyArray(matlabA);
402 bool isSparse =
false;
408 mxDestroyArray(matlabA);
413 mxDestroyArray(matlabA);
422 double* tempValues = 0;
424 tempValues = mxGetPr(matlabA);
430 mxDestroyArray(matlabA);
449 double* aValues = A.
A();
450 double* mvValues = tempMV.
Values();
451 for(
int i=0; i < A.
M() * A.
N(); i++) {
452 *aValues++ = *mvValues++;
466 int* aValues = A.
A();
467 values =
new double[A.
M() * A.
N()];
468 for (
int i=0; i < A.
M() * A.
N(); i++) {
469 *values++ = *aValues++;
480 int* aValues = A.
A();
481 double* mvValues = tempMV.
Values();
482 for(
int i=0; i < A.
M() * A.
N(); i++) {
483 *aValues++ = *mvValues++;
492 const char* variableName;
495 int inVariableNameLength = strlen(inVariableName);
496 char* buff =
new char[inVariableNameLength*2 + 11];
497 sprintf(buff,
"TRANS_%s = %s'", inVariableName, inVariableName);
501 char* tempStr =
new char[inVariableNameLength + 7];
502 sprintf(tempStr,
"TRANS_%s", inVariableName);
503 variableName = tempStr;
506 variableName = inVariableName;
509 mxArray* matlabA = 0;
511 if (ierr =
GetmxArray(variableName, &matlabA)) {
512 mxDestroyArray(matlabA);
517 char* buff =
new char[strlen(variableName) + 7];
518 sprintf(buff,
"clear %s", variableName);
524 bool isSparse =
false;
532 mxDestroyArray(matlabA);
537 mxDestroyArray(matlabA);
548 int* rowIndex = mxGetJc(matlabA);
549 int* colIndex = mxGetIr(matlabA);
550 double* values = mxGetPr(matlabA);
552 for(
int row = 0; row < numRows; row++) {
553 numCols = *(rowIndex+1) - *rowIndex;
555 int* indices =
new int[numCols];
556 int* indicesPtr = indices;
557 for(
int col=0; col < numCols; col++) {
558 *indicesPtr++ = *colIndex++;
571 mxDestroyArray(matlabA);
578 if (mxGetNumberOfDimensions(matlabA) > 2) {
582 const int* dimensions = mxGetDimensions(matlabA);
583 numRows = dimensions[0];
584 numCols = dimensions[1];
585 isSparse = mxIsSparse(matlabA);
588 numNonZeros = mxGetNzmax(matlabA);
591 numNonZeros = numRows * numCols;
601#ifdef USE_ENGPUTARRAY
603 *matlabA = engGetArray(
Engine_, variableName);
606 *matlabA = engGetVariable(
Engine_, variableName);
608 if (matlabA == NULL) {
int PutCrsGraph(const Epetra_CrsGraph &A, const char *variableName, bool transA)
not implemented yet
int GetCrsMatrix(const char *variableName, Epetra_CrsMatrix &A, bool getTrans)
Puts a Matlab variable into a CrsMatrix.
~EpetraExt_MatlabEngine()
EpetraExt_MatlabEngine destructor which closes the connection to Matlab which causes the Matlab proce...
int PutRowMatrix(const Epetra_RowMatrix &A, const char *variableName, bool transA)
Puts a copy of the serial or distributed RowMatrix into the Matlab workspace.
int PutSerialDenseMatrix(const Epetra_SerialDenseMatrix &A, const char *variableName, int proc=0)
Puts a copy of the SerialDenseMatrix into the Matlab workspace.
int PutMultiVector(const Epetra_MultiVector &A, const char *variableName)
Puts a copy of the serial or distributed MultiVector into the Matlab workspace.
int PutIntSerialDenseMatrix(const Epetra_IntSerialDenseMatrix &A, const char *variableName, int proc=0)
Puts a copy of the IntSerialDenseMatrix into the Matlab workspace.
int PutBlockMap(const Epetra_BlockMap &blockMap, const char *variableName, bool transA)
Puts a copy of the BlockMap or Map into the Matlab workspace.
const Epetra_Comm & Comm_
EpetraExt_MatlabEngine(const Epetra_Comm &Comm)
EpetraExt_MatlabEngine constructor which creates a MatlabEngine object with a connection to an instan...
int GetIntSerialDenseMatrix(const char *variableName, Epetra_IntSerialDenseMatrix &A, int proc=0)
Puts a Matlab variable into a IntSerialDenseMatrix on the specified PE.
int EvalString(char *command, char *outputBuffer=NULL, int outputBufferSize=-1)
Sends a command to Matlab.
int GetMultiVector(const char *variableName, Epetra_MultiVector &A)
Puts a Matlab variable into a MultiVector.
int GetmxArrayDimensions(mxArray *matlabA, bool &isSparse, int &numRows, int &numCols, int &numNonZeros)
Get general information about the mxArray. For internal use but can be used by an advanced user.
int GetmxArray(const char *variableName, mxArray **matlabA)
Get a mxArray from Matlab. For internal use but can be used by an advanced user.
int PutIntoMatlab(const char *variableName, mxArray *matlabA)
Puts a mxArray into Matlab.
int GetSerialDenseMatrix(const char *variableName, Epetra_SerialDenseMatrix &A, int proc=0)
Puts a Matlab variable into a SerialDenseMatrix on the specified PE.
int MaxElementSize() const
int NumGlobalElements() const
virtual int MaxAll(double *PartialMaxs, double *GlobalMaxs, int Count) const=0
virtual int MyPID() const=0
int FillComplete(bool OptimizeDataStorage=true)
virtual int InsertGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
const Epetra_Map & RowMatrixRowMap() const
const Epetra_BlockMap & Map() const
int Import(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
int Export(const Epetra_SrcDistObject &A, const Epetra_Import &Importer, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor=0)
virtual const Epetra_Map & OperatorDomainMap() const=0
virtual const Epetra_Map & OperatorRangeMap() const=0
virtual int NumGlobalNonzeros() const=0
EpetraExt::BlockCrsMatrix: A class for constructing a distributed block matrix.
int CopyBlockMap(mxArray *matlabA, const Epetra_BlockMap &map)
int CopyRowMatrix(mxArray *matlabA, const Epetra_RowMatrix &A)
int CopyMultiVector(double **matlabApr, const Epetra_MultiVector &A)