summaryrefslogtreecommitdiff
path: root/modules/mpi/src/c
diff options
context:
space:
mode:
authorShashank2017-05-29 12:40:26 +0530
committerShashank2017-05-29 12:40:26 +0530
commit0345245e860375a32c9a437c4a9d9cae807134e9 (patch)
treead51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/mpi/src/c
downloadscilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.gz
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.tar.bz2
scilab_for_xcos_on_cloud-0345245e860375a32c9a437c4a9d9cae807134e9.zip
CMSCOPE changed
Diffstat (limited to 'modules/mpi/src/c')
-rwxr-xr-xmodules/mpi/src/c/.deps/libscimpi_la-deserialization.Plo1
-rwxr-xr-xmodules/mpi/src/c/.deps/libscimpi_la-serialization.Plo1
-rwxr-xr-xmodules/mpi/src/c/DllmainMpi.c39
-rwxr-xr-xmodules/mpi/src/c/deserialization.c309
-rwxr-xr-xmodules/mpi/src/c/deserialization.h21
-rwxr-xr-xmodules/mpi/src/c/mpi.rc96
-rwxr-xr-xmodules/mpi/src/c/sci_mpi.h11
-rwxr-xr-xmodules/mpi/src/c/serialization.c457
-rwxr-xr-xmodules/mpi/src/c/serialization.h22
9 files changed, 957 insertions, 0 deletions
diff --git a/modules/mpi/src/c/.deps/libscimpi_la-deserialization.Plo b/modules/mpi/src/c/.deps/libscimpi_la-deserialization.Plo
new file mode 100755
index 000000000..9ce06a81e
--- /dev/null
+++ b/modules/mpi/src/c/.deps/libscimpi_la-deserialization.Plo
@@ -0,0 +1 @@
+# dummy
diff --git a/modules/mpi/src/c/.deps/libscimpi_la-serialization.Plo b/modules/mpi/src/c/.deps/libscimpi_la-serialization.Plo
new file mode 100755
index 000000000..9ce06a81e
--- /dev/null
+++ b/modules/mpi/src/c/.deps/libscimpi_la-serialization.Plo
@@ -0,0 +1 @@
+# dummy
diff --git a/modules/mpi/src/c/DllmainMpi.c b/modules/mpi/src/c/DllmainMpi.c
new file mode 100755
index 000000000..f65a5da50
--- /dev/null
+++ b/modules/mpi/src/c/DllmainMpi.c
@@ -0,0 +1,39 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include <windows.h>
+/*--------------------------------------------------------------------------*/
+#pragma comment(lib,"../../bin/libintl.lib")
+#pragma comment(lib,"../../bin/blasplus.lib")
+
+//MS MPI
+#pragma comment(lib,"../../libs/mpi/lib/msmpi.lib")
+
+
+/*--------------------------------------------------------------------------*/
+int WINAPI DllMain (HINSTANCE hInstance , DWORD reason, PVOID pvReserved)
+{
+ switch (reason)
+ {
+ case DLL_PROCESS_ATTACH:
+ break;
+ case DLL_PROCESS_DETACH:
+ break;
+ case DLL_THREAD_ATTACH:
+ break;
+ case DLL_THREAD_DETACH:
+ break;
+ }
+ return 1;
+}
+/*--------------------------------------------------------------------------*/
+
diff --git a/modules/mpi/src/c/deserialization.c b/modules/mpi/src/c/deserialization.c
new file mode 100755
index 000000000..e77d989ef
--- /dev/null
+++ b/modules/mpi/src/c/deserialization.c
@@ -0,0 +1,309 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011-2011 - DIGITEO - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "api_scilab.h"
+#include "BOOL.h"
+#include "MALLOC.h"
+#include "deserialization.h"
+
+static int deserialize_double(void *_pvCtx, int *_piBuffer, int _iBufferSize)
+{
+ SciErr sciErr;
+ int iRows = _piBuffer[1];
+ int iCols = _piBuffer[2];
+ int iComplex = _piBuffer[3];
+ double *pdblR = NULL;
+ double *pdblI = NULL;
+ int iSize = 0;
+
+ //check size of input buffer
+ iSize = 4 + (iRows * iCols * (iComplex + 1) * (sizeof(double) / sizeof(int)));
+ if (iSize != _iBufferSize)
+ {
+ printf("Bad buffer size: \n\tReceived: %d\n\tExpected: %d\n", _iBufferSize, iSize);
+ return 1;
+ }
+
+ pdblR = (double *)(_piBuffer + 4);
+ pdblI = pdblR + iRows * iCols;
+
+ if (iComplex)
+ {
+ sciErr = createComplexMatrixOfDouble(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, pdblR, pdblI);
+ }
+ else
+ {
+ sciErr = createMatrixOfDouble(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, pdblR);
+ }
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int deserialize_string(void *_pvCtx, int *_piBuffer, int _iBufferSize)
+{
+ SciErr sciErr;
+ int i = 0;
+ int iRows = _piBuffer[1];
+ int iCols = _piBuffer[2];
+ int iSize = 0;
+ int *piInLen = _piBuffer + 4;
+ char **pstData = NULL;
+ char *pstInData = (char *)(_piBuffer + 4 + iRows * iCols);
+
+ //check size of input buffer
+ for (i = 0; i < iRows * iCols; i++)
+ {
+ iSize += piInLen[i];
+ }
+
+ if (iSize % 4)
+ {
+ iSize = iSize * sizeof(char) / sizeof(int) + 1;
+ }
+ else
+ {
+ iSize = iSize * sizeof(char) / sizeof(int);
+ }
+
+ iSize += (4 + iRows * iCols);
+
+ if (iSize != _iBufferSize)
+ {
+ printf("Bad buffer size: \n\tReceived: %d\n\tExpected: %d\n", _iBufferSize, iSize);
+ return 1;
+ }
+ pstData = (char **)MALLOC(iRows * iCols * sizeof(char *));
+
+ for (i = 0; i < iRows * iCols; i++)
+ {
+ pstData[i] = (char *)MALLOC((piInLen[i] + 1) * sizeof(char));
+ memcpy(pstData[i], pstInData, piInLen[i]);
+ pstData[i][piInLen[i]] = 0;
+ pstInData += piInLen[i];
+ }
+
+ sciErr = createMatrixOfString(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (const char * const *)pstData);
+ for (i = 0; i < iRows * iCols; i++)
+ {
+ FREE(pstData[i]);
+ }
+
+ FREE(pstData);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int deserialize_boolean(void *_pvCtx, int *_piBuffer, int _iBufferSize)
+{
+ SciErr sciErr;
+ int iRows = _piBuffer[1];
+ int iCols = _piBuffer[2];
+ int iSize = 0;
+ int *piBool = NULL;
+
+ //check size of input buffer
+ iSize = 4 + (iRows * iCols);
+ if (iSize != _iBufferSize)
+ {
+ printf("Bad buffer size: \n\tReceived: %d\n\tExpected: %d\n", _iBufferSize, iSize);
+ return 1;
+ }
+
+ piBool = _piBuffer + 4;
+ sciErr = createMatrixOfBoolean(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, piBool);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ return 0;
+}
+
+static int deserialize_int(void *_pvCtx, int *_piBuffer, int _iBufferSize)
+{
+ SciErr sciErr;
+ int iRows = _piBuffer[1];
+ int iCols = _piBuffer[2];
+ int iPrecision = _piBuffer[3];
+ int iItemSize = 0;
+ int iSize = 0;
+ void *pvData = NULL;
+
+ //check size of input buffer
+ if (iPrecision == SCI_INT8 || iPrecision == SCI_UINT8)
+ {
+ iItemSize = sizeof(char);
+ }
+ else if (iPrecision == SCI_INT16 || iPrecision == SCI_UINT16)
+ {
+ iItemSize = sizeof(short);
+ }
+ else if (iPrecision == SCI_INT32 || iPrecision == SCI_UINT32)
+ {
+ iItemSize = sizeof(int);
+ }
+ /*
+ else if(iPrecision == SCI_INT64 || iPrecision == SCI_UINT64)
+ {
+ iItemSize = sizeof(long long);
+ }
+ */
+ iSize = iRows * iCols;
+ if ((iSize * iItemSize) % sizeof(int))
+ {
+ iSize = (iSize * iItemSize) / sizeof(int) + 1;
+ }
+ else
+ {
+ iSize = (iSize * iItemSize) / (sizeof(int));
+ }
+
+ iSize += 4;
+ if (iSize != _iBufferSize)
+ {
+ printf("Bad buffer size: \n\tReceived: %d\n\tExpected: %d\n", _iBufferSize, iSize);
+ return 1;
+ }
+
+ pvData = _piBuffer + 4;
+
+ switch (iPrecision)
+ {
+ case SCI_INT8:
+ sciErr = createMatrixOfInteger8(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (char *)pvData);
+ break;
+ case SCI_UINT8:
+ sciErr = createMatrixOfUnsignedInteger8(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (unsigned char *)pvData);
+ break;
+ case SCI_INT16:
+ sciErr = createMatrixOfInteger16(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (short *)pvData);
+ break;
+ case SCI_UINT16:
+ sciErr = createMatrixOfUnsignedInteger16(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (unsigned short *)pvData);
+ break;
+ case SCI_INT32:
+ sciErr = createMatrixOfInteger32(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (int *)pvData);
+ break;
+ case SCI_UINT32:
+ sciErr = createMatrixOfUnsignedInteger32(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (unsigned int *)pvData);
+ break;
+ /*
+ case SCI_INT64 :
+ sciErr = createMatrixOfInteger64(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (long long*)pvData);
+ break;
+ case SCI_UINT64 :
+ sciErr = createMatrixOfUnsignedInteger64(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, (unsigned long long*)pvData);
+ break;
+ */
+ default:
+ break;
+ }
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ return 0;
+}
+
+static int deserialize_sparse(void *_pvCtx, int *_piBuffer, int _iBufferSize, BOOL _bData)
+{
+ SciErr sciErr;
+ int iRows = _piBuffer[1];
+ int iCols = _piBuffer[2];
+ int iComplex = _piBuffer[3];
+ int iItemCount = _piBuffer[4];
+ int *piRowCount = NULL;
+ int *piColPos = NULL;
+ double *pdblR = NULL;
+ double *pdblI = NULL;
+ int iSize = 0;
+
+ iSize = 5 + iRows + iItemCount;
+ if (_bData)
+ {
+ iSize += iItemCount * (iComplex + 1) * sizeof(double) / sizeof(int);
+ }
+
+ if (iSize != _iBufferSize)
+ {
+ printf("Bad buffer size: \n\tReceived: %d\n\tExpected: %d\n", _iBufferSize, iSize);
+ return 1;
+ }
+
+ piRowCount = _piBuffer + 5;
+ piColPos = _piBuffer + 5 + iRows;
+
+ if (_bData)
+ {
+ pdblR = (double *)(_piBuffer + 5 + iRows + iItemCount);
+ if (iComplex)
+ {
+ pdblI = pdblR + iItemCount;
+ sciErr = createComplexSparseMatrix(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, iItemCount, piRowCount, piColPos, pdblR, pdblI);
+ }
+ else
+ {
+ sciErr = createSparseMatrix(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, iItemCount, piRowCount, piColPos, pdblR);
+ }
+ }
+ else
+ {
+ sciErr = createBooleanSparseMatrix(_pvCtx, nbInputArgument(_pvCtx) + 1, iRows, iCols, iItemCount, piRowCount, piColPos);
+ }
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+ return 0;
+}
+
+int deserialize_from_mpi(void *_pvCtx, int *_piBuffer, int _iBufferSize)
+{
+ switch (*_piBuffer)
+ {
+ case sci_matrix:
+ return deserialize_double(pvApiCtx, _piBuffer, _iBufferSize);
+ case sci_strings:
+ return deserialize_string(pvApiCtx, _piBuffer, _iBufferSize);
+ case sci_boolean:
+ return deserialize_boolean(pvApiCtx, _piBuffer, _iBufferSize);
+ case sci_sparse:
+ return deserialize_sparse(pvApiCtx, _piBuffer, _iBufferSize, TRUE);
+ case sci_boolean_sparse:
+ return deserialize_sparse(pvApiCtx, _piBuffer, _iBufferSize, FALSE);
+ case sci_ints:
+ return deserialize_int(pvApiCtx, _piBuffer, _iBufferSize);
+ default:
+ return -1; //unknow type
+ }
+}
+
+
diff --git a/modules/mpi/src/c/deserialization.h b/modules/mpi/src/c/deserialization.h
new file mode 100755
index 000000000..1a4cca10a
--- /dev/null
+++ b/modules/mpi/src/c/deserialization.h
@@ -0,0 +1,21 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011-2011 - DIGITEO - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+/**
+ * Deserialize a mpi data to a Scilab variable
+ *
+ * @param _pvCtx The runtime context
+ * @param _piBuffer The buffer
+ * @param _iBufferSize The size of the buffer
+ * @return 0 in case of success
+ */
+int deserialize_from_mpi(void *_pvCtx, int *_piBuffer, int _iBufferSize);
diff --git a/modules/mpi/src/c/mpi.rc b/modules/mpi/src/c/mpi.rc
new file mode 100755
index 000000000..c838bf78c
--- /dev/null
+++ b/modules/mpi/src/c/mpi.rc
@@ -0,0 +1,96 @@
+// Microsoft Visual C++ generated resource script.
+//
+
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+//#include "afxres.h"
+#define APSTUDIO_HIDDEN_SYMBOLS
+#include "windows.h"
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// French (France) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA)
+#ifdef _WIN32
+LANGUAGE LANG_FRENCH, SUBLANG_FRENCH
+#pragma code_page(1252)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 5,5,2,0
+ PRODUCTVERSION 5,5,2,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040c04b0"
+ BEGIN
+ VALUE "FileDescription", "mpi module"
+ VALUE "FileVersion", "5, 5, 2, 0"
+ VALUE "InternalName", "mpi module"
+ VALUE "LegalCopyright", "Copyright (C) 2017"
+ VALUE "OriginalFilename", "mpi.dll"
+ VALUE "ProductName", " mpi module"
+ VALUE "ProductVersion", "5, 5, 2, 0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x40c, 1200
+ END
+END
+
+#endif // French (France) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/modules/mpi/src/c/sci_mpi.h b/modules/mpi/src/c/sci_mpi.h
new file mode 100755
index 000000000..2da5474e2
--- /dev/null
+++ b/modules/mpi/src/c/sci_mpi.h
@@ -0,0 +1,11 @@
+
+#ifndef __SCIMPI
+#define __SCIMPI
+
+#include <mpi.h>
+/* Create some static datastructure to store all the Request references */
+extern MPI_Request *request;
+extern int **listRequestPointer;
+extern int *listRequestPointerSize;
+
+#endif /* __SCIMPI */
diff --git a/modules/mpi/src/c/serialization.c b/modules/mpi/src/c/serialization.c
new file mode 100755
index 000000000..fd688758a
--- /dev/null
+++ b/modules/mpi/src/c/serialization.c
@@ -0,0 +1,457 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011-2011 - DIGITEO - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+#include <string.h>
+#include <stdio.h>
+#include "api_scilab.h"
+#include "BOOL.h"
+#include "MALLOC.h"
+#include "serialization.h"
+
+static int serialize_double(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
+{
+ SciErr sciErr;
+ int iRows = 0;
+ int iCols = 0;
+ int iOne = 1;
+ int iSize = 0;
+ double *pdblR = NULL;
+ double *pdblI = NULL;
+
+ int *piOut = NULL;
+ int iOutLen = 0;
+
+ if (isVarComplex(_pvCtx, _piAddr))
+ {
+ double *p = NULL;
+
+ sciErr = getComplexMatrixOfDouble(_pvCtx, _piAddr, &iRows, &iCols, &pdblR, &pdblI);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ iOutLen = 4 + (2 * iRows * iCols * sizeof(double) / sizeof(int));
+ piOut = (int *)MALLOC(iOutLen * sizeof(int));
+ if (piOut == NULL)
+ {
+ return 1;
+ }
+
+ piOut[0] = sci_matrix;
+ piOut[1] = iRows;
+ piOut[2] = iCols;
+ piOut[3] = 1; //complex
+
+ //move 'p' to first real value
+ p = (double *)(piOut + 4);
+ iSize = iRows * iCols;
+ C2F(dcopy) (&iSize, pdblR, &iOne, p, &iOne);
+ //move 'p' to first complex value
+ p = p + iRows * iCols;
+ C2F(dcopy) (&iSize, pdblI, &iOne, p, &iOne);
+ }
+ else
+ {
+ double *p = NULL;
+
+ sciErr = getMatrixOfDouble(_pvCtx, _piAddr, &iRows, &iCols, &pdblR);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ iOutLen = 4 + (iRows * iCols * sizeof(double) / sizeof(int));
+ piOut = (int *)MALLOC(iOutLen * sizeof(int));
+ if (piOut == NULL)
+ {
+ return 1;
+ }
+
+ piOut[0] = sci_matrix;
+ piOut[1] = iRows;
+ piOut[2] = iCols;
+ piOut[3] = 0; //not complex
+
+ //move 'p' to first value
+ p = (double *)(piOut + 4);
+ iSize = iRows * iCols;
+ C2F(dcopy) (&iSize, pdblR, &iOne, p, &iOne);
+ }
+
+ *_piBuffer = piOut;
+ *_piBufferSize = iOutLen;
+ return 0;
+}
+
+static int serialize_string(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
+{
+ int iErr = 0;
+ int i = 0;
+ int iRows = 0;
+ int iCols = 0;
+ char **pstData = NULL;
+ char *p = NULL;
+
+ int *piOut = NULL;
+ int *piOutLen = NULL;
+ int iOutLen = 0;
+
+ iErr = getAllocatedMatrixOfString(_pvCtx, _piAddr, &iRows, &iCols, &pstData);
+ if (iErr)
+ {
+ return 1;
+ }
+
+ for (i = 0; i < iRows * iCols; i++)
+ {
+ iOutLen += (int)strlen(pstData[i]);
+ }
+
+ if (iOutLen % 4)
+ {
+ iOutLen = iOutLen / (sizeof(int) / sizeof(char)) + 1;
+ }
+ else
+ {
+ iOutLen = iOutLen / (sizeof(int) / sizeof(char));
+ }
+
+ //4 for header and size of each string
+ iOutLen += 4 + iRows * iCols;
+
+ piOut = (int *)MALLOC(iOutLen * sizeof(int));
+ if (piOut == NULL)
+ {
+ return 1;
+ }
+
+ piOut[0] = sci_strings;
+ piOut[1] = iRows;
+ piOut[2] = iCols;
+ piOut[3] = 0; //not complex
+
+ piOutLen = piOut + 4;
+
+ for (i = 0; i < iRows * iCols; i++)
+ {
+ piOutLen[i] = (int)strlen(pstData[i]);
+ }
+
+ p = (char *)(piOut + 4 + iRows * iCols);
+ for (i = 0; i < iRows * iCols; i++)
+ {
+ memcpy(p, pstData[i], piOutLen[i]);
+ p += piOutLen[i];
+ }
+
+ *_piBuffer = piOut;
+ *_piBufferSize = iOutLen;
+
+ freeAllocatedMatrixOfString(iRows, iCols, pstData);
+ return 0;
+}
+
+static int serialize_boolean(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
+{
+ SciErr sciErr;
+ int iRows = 0;
+ int iCols = 0;
+ int *piBool = NULL;
+ int *p = NULL;
+
+ int *piOut = NULL;
+ int iOutLen = 0;
+
+ sciErr = getMatrixOfBoolean(_pvCtx, _piAddr, &iRows, &iCols, &piBool);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ //4 for header and 1 for each boolean
+ iOutLen = 4 + iRows * iCols;
+
+ piOut = (int *)MALLOC(iOutLen * sizeof(int *));
+ if (piOut == NULL)
+ {
+ return 1;
+ }
+
+ piOut[0] = sci_boolean;
+ piOut[1] = iRows;
+ piOut[2] = iCols;
+ piOut[3] = 0; //not complex
+
+ p = (int *)(piOut + 4);
+ memcpy(p, piBool, iRows * iCols * sizeof(int));
+
+ *_piBuffer = piOut;
+ *_piBufferSize = iOutLen;
+ return 0;
+}
+
+static int serialize_int(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
+{
+ SciErr sciErr;
+ int iPrecision = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int iItemSize = 0;
+ void *p = NULL;
+ void *pvData = NULL;
+
+ int *piOut = NULL;
+ int iOutLen = 0;
+
+ sciErr = getVarDimension(_pvCtx, _piAddr, &iRows, &iCols);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ sciErr = getMatrixOfIntegerPrecision(_pvCtx, _piAddr, &iPrecision);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ if (iPrecision == SCI_INT8 || iPrecision == SCI_UINT8)
+ {
+ iItemSize = sizeof(char);
+ }
+ else if (iPrecision == SCI_INT16 || iPrecision == SCI_UINT16)
+ {
+ iItemSize = sizeof(short);
+ }
+ else if (iPrecision == SCI_INT32 || iPrecision == SCI_UINT32)
+ {
+ iItemSize = sizeof(int);
+ }
+ /*
+ else if(iPrecision == SCI_INT64 || iPrecision == SCI_UINT64)
+ {
+ iItemSize = sizeof(long long);
+ }
+ */
+ //check and adjust alignement on integer
+ iOutLen = iRows * iCols;
+ if ((iOutLen * iItemSize) % sizeof(int))
+ {
+ iOutLen = (iOutLen * iItemSize) / sizeof(int) + 1;
+ }
+ else
+ {
+ iOutLen = (iOutLen * iItemSize) / (sizeof(int));
+ }
+
+ iOutLen += 4;
+ piOut = (int *)MALLOC(iOutLen * sizeof(int *));
+ if (piOut == NULL)
+ {
+ return 1;
+ }
+
+ piOut[0] = sci_ints;
+ piOut[1] = iRows;
+ piOut[2] = iCols;
+ piOut[3] = iPrecision; //precision
+
+ switch (iPrecision)
+ {
+ case SCI_INT8:
+ {
+ sciErr = getMatrixOfInteger8(_pvCtx, _piAddr, &iRows, &iCols, (char **)&pvData);
+ break;
+ }
+ case SCI_UINT8:
+ {
+ sciErr = getMatrixOfUnsignedInteger8(_pvCtx, _piAddr, &iRows, &iCols, (unsigned char **)&pvData);
+ break;
+ }
+ case SCI_INT16:
+ {
+ sciErr = getMatrixOfInteger16(_pvCtx, _piAddr, &iRows, &iCols, (short **)&pvData);
+ break;
+ }
+ case SCI_UINT16:
+ {
+ sciErr = getMatrixOfUnsignedInteger16(_pvCtx, _piAddr, &iRows, &iCols, (unsigned short **)&pvData);
+ break;
+ }
+ case SCI_INT32:
+ {
+ sciErr = getMatrixOfInteger32(_pvCtx, _piAddr, &iRows, &iCols, (int **)&pvData);
+ break;
+ }
+ case SCI_UINT32:
+ {
+ sciErr = getMatrixOfUnsignedInteger32(_pvCtx, _piAddr, &iRows, &iCols, (unsigned int **)&pvData);
+ break;
+ }
+ /*
+ case SCI_INT64 :
+ {
+ sciErr = getMatrixOfInteger64(_pvCtx, _piAddr, &iRows, &iCols, (long long**)&pvData);
+ break;
+ }
+ case SCI_UINT64 :
+ {
+ sciErr = getMatrixOfUnsignedInteger64(_pvCtx, _piAddr, &iRows, &iCols, (unsigned long long**)&pvData);
+ break;
+ }
+ */ default:
+ FREE(piOut);
+ return 1;
+ }
+
+ if (sciErr.iErr)
+ {
+ FREE(piOut);
+ printError(&sciErr, 0);
+ return 1;
+ }
+
+ p = piOut + 4;
+ memcpy(p, pvData, iRows * iCols * iItemSize);
+ *_piBuffer = piOut;
+ *_piBufferSize = iOutLen;
+ return 0;
+}
+
+static int serialize_sparse(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize, BOOL _bData)
+{
+ int iRet = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int iItemCount = 0;
+ int *piRowCount = 0;
+ int *piColPos = 0;
+ int iComplex = 0;
+
+ double *pdblR = NULL;
+ double *pdblI = NULL;
+
+ int *piOut = NULL;
+ int iOutLen = 0;
+
+ if (_bData)
+ {
+ //sparse
+
+ iComplex = isVarComplex(_pvCtx, _piAddr);
+ if (iComplex)
+ {
+ iRet = getAllocatedComplexSparseMatrix(_pvCtx, _piAddr, &iRows, &iCols, &iItemCount, &piRowCount, &piColPos, &pdblR, &pdblI);
+ }
+ else
+ {
+ iRet = getAllocatedSparseMatrix(_pvCtx, _piAddr, &iRows, &iCols, &iItemCount, &piRowCount, &piColPos, &pdblR);
+ }
+ }
+ else
+ {
+ //boolean sparse
+ iRet = getAllocatedBooleanSparseMatrix(_pvCtx, _piAddr, &iRows, &iCols, &iItemCount, &piRowCount, &piColPos);
+ }
+
+ if (iRet)
+ {
+ return 1;
+ }
+
+ //5 -> 4 for header + 1 for item count
+ iOutLen = 5 + iRows + iItemCount;
+
+ if (_bData)
+ {
+ iOutLen += iItemCount * (iComplex + 1) * sizeof(double) / sizeof(int);
+ }
+
+ piOut = (int *)MALLOC(iOutLen * sizeof(int));
+
+ piOut[0] = _bData ? sci_sparse : sci_boolean_sparse;
+ piOut[1] = iRows;
+ piOut[2] = iCols;
+ piOut[3] = iComplex;
+ piOut[4] = iItemCount;
+
+ memcpy(piOut + 5, piRowCount, iRows * sizeof(int));
+ memcpy(piOut + 5 + iRows, piColPos, iItemCount * sizeof(int));
+
+ if (_bData)
+ {
+ int iOne = 1;
+ double *pRealData = (double *)(piOut + 5 + iRows + iItemCount);
+
+ C2F(dcopy) (&iItemCount, pdblR, &iOne, pRealData, &iOne);
+ if (iComplex)
+ {
+ double *pImgData = pRealData + iItemCount;
+
+ C2F(dcopy) (&iItemCount, pdblI, &iOne, pImgData, &iOne);
+ }
+ }
+
+ *_piBuffer = piOut;
+ *_piBufferSize = iOutLen;
+
+ if (_bData)
+ {
+ if (iComplex)
+ {
+ freeAllocatedSparseMatrix(piRowCount, piColPos, pdblR);
+ }
+ else
+ {
+ freeAllocatedComplexSparseMatrix(piRowCount, piColPos, pdblR, pdblI);
+ }
+ }
+ else
+ {
+ freeAllocatedBooleanSparse(piRowCount, piColPos);
+ }
+
+ return 0;
+}
+
+int serialize_to_mpi(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize)
+{
+ switch (*_piAddr)
+ {
+ case sci_matrix:
+ return serialize_double(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+ break;
+ case sci_strings:
+ return serialize_string(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+ break;
+ case sci_boolean:
+ return serialize_boolean(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+ break;
+ case sci_sparse:
+ return serialize_sparse(pvApiCtx, _piAddr, _piBuffer, _piBufferSize, TRUE);
+ break;
+ case sci_boolean_sparse:
+ return serialize_sparse(pvApiCtx, _piAddr, _piBuffer, _piBufferSize, FALSE);
+ break;
+ case sci_ints:
+ return serialize_int(pvApiCtx, _piAddr, _piBuffer, _piBufferSize);
+ break;
+ default:
+ return -1;
+ break;
+ }
+} \ No newline at end of file
diff --git a/modules/mpi/src/c/serialization.h b/modules/mpi/src/c/serialization.h
new file mode 100755
index 000000000..a42a50ae9
--- /dev/null
+++ b/modules/mpi/src/c/serialization.h
@@ -0,0 +1,22 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2011-2011 - DIGITEO - Antoine ELIAS
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+/**
+ * Serialize a Scilab variable to mpi data
+ *
+ * @param _pvCtx The runtime context
+ * @param _piBuffer The buffer
+ * @param _iBufferSize The size of the buffer
+ * @return 0 in case of success
+ */
+
+int serialize_to_mpi(void *_pvCtx, int *_piAddr, int **_piBuffer, int *_piBufferSize);