diff options
author | Shashank | 2017-05-29 12:40:26 +0530 |
---|---|---|
committer | Shashank | 2017-05-29 12:40:26 +0530 |
commit | 0345245e860375a32c9a437c4a9d9cae807134e9 (patch) | |
tree | ad51ecbfa7bcd3cc5f09834f1bb8c08feaa526a4 /modules/mpi/sci_gateway | |
download | scilab_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/sci_gateway')
26 files changed, 1097 insertions, 0 deletions
diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-gw_mpi.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-gw_mpi.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-gw_mpi.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_bcast.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_bcast.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_bcast.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_comm_rank.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_comm_rank.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_comm_rank.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_comm_size.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_comm_size.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_comm_size.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_finalize.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_finalize.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_finalize.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_get_processor_name.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_get_processor_name.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_get_processor_name.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_init.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_init.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_init.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_irecv.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_irecv.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_irecv.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_isend.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_isend.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_isend.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_recv.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_recv.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_recv.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_send.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_send.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_send.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_wait.Plo b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_wait.Plo new file mode 100755 index 000000000..9ce06a81e --- /dev/null +++ b/modules/mpi/sci_gateway/c/.deps/libscimpi_la-sci_mpi_wait.Plo @@ -0,0 +1 @@ +# dummy diff --git a/modules/mpi/sci_gateway/c/gw_mpi.c b/modules/mpi/sci_gateway/c/gw_mpi.c new file mode 100755 index 000000000..3f07e2e1a --- /dev/null +++ b/modules/mpi/sci_gateway/c/gw_mpi.c @@ -0,0 +1,46 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2007-2009 - DIGITEO - Sylvestre LEDRU + * + * 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 "gw_mpi.h" +#include "api_scilab.h" +#include "MALLOC.h" +#include "callFunctionFromGateway.h" +/*-----------------------------------------------------------------------------------*/ +static gw_generic_table Tab[] = +{ + {sci_mpi_init, "MPI_Init"}, + {sci_mpi_finalize, "MPI_Finalize"}, + {sci_mpi_comm_size, "MPI_Comm_size"}, + {sci_mpi_comm_rank, "MPI_Comm_rank"}, + {sci_mpi_recv, "MPI_Recv"}, + {sci_mpi_send, "MPI_Send"}, + {sci_mpi_get_processor_name, "MPI_Get_processor_name"}, + {sci_mpi_bcast, "MPI_Bcast"}, + {sci_mpi_irecv, "MPI_Irecv"}, + {sci_mpi_isend, "MPI_Isend"}, + {sci_mpi_wait, "MPI_Wait"} +}; +/*-----------------------------------------------------------------------------------*/ +int gw_mpi(void) +{ + Rhs = Max(0, Rhs); + + if (pvApiCtx == NULL) + { + pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx)); + } + + pvApiCtx->pstName = (char*)Tab[Fin - 1].name; + callFunctionFromGateway(Tab, SIZE_CURRENT_GENERIC_TABLE(Tab)); + return 0; +} + +/*-----------------------------------------------------------------------------------*/ diff --git a/modules/mpi/sci_gateway/c/sci_mpi_bcast.c b/modules/mpi/sci_gateway/c/sci_mpi_bcast.c new file mode 100755 index 000000000..ab5c5a725 --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_bcast.c @@ -0,0 +1,118 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU + * + * 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 "api_scilab.h" +#include <stdio.h> +#include <mpi.h> +#include "gw_mpi.h" +#include "Scierror.h" +#include "MALLOC.h" +#include "localization.h" +#include "serialization.h" +#include "deserialization.h" + +int sci_mpi_bcast(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int iRet = 0; + int *piAddr = NULL; + int *piAddr2 = NULL; + + int *piBuffer = NULL; + int iBufferSize = 0; + double rootID = 0; + int rank = 0; + + CheckInputArgument(pvApiCtx, 2, 2); + CheckOutputArgument(pvApiCtx, 1, 1); + + sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr2, &rootID)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); + return 0; + } + + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + iRet = MPI_Comm_rank(MPI_COMM_WORLD, &rank); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string = 0; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not get communicator rank of the node %d: %s\n"), fname, rootID, error_string); + return 0; + } + + if (rank == rootID) + { + iRet = serialize_to_mpi(pvApiCtx, piAddr, &piBuffer, &iBufferSize); + if (iRet) + { + Scierror(999, _("Unable to serialize data\n")); + return 0; + } + } + + /* First, send the size of the data as broadcast */ + iRet = MPI_Bcast(&iBufferSize, 1, MPI_INT, (int)rootID, MPI_COMM_WORLD); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string = 0; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not broadcast the variable to the node %d: %s\n"), fname, rootID, error_string); + return 0; + } + + if (rank != rootID) + { + piBuffer = (int*)MALLOC(sizeof(int) * iBufferSize); + } + + /* Second, restore the data with the right size */ + iRet = MPI_Bcast(piBuffer, iBufferSize, MPI_INT, (int)rootID, MPI_COMM_WORLD); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string = 0; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not broadcast the variable to the node %d: %s\n"), fname, rootID, error_string); + return 0; + } + + iRet = deserialize_from_mpi(pvApiCtx, piBuffer, iBufferSize); + FREE(piBuffer); + if (iRet) + { + Scierror(999, _("%s: Unable to deserialize data.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_comm_rank.c b/modules/mpi/sci_gateway/c/sci_mpi_comm_rank.c new file mode 100755 index 000000000..9dd1e8bee --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_comm_rank.c @@ -0,0 +1,41 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2007-2009 - DIGITEO - Sylvestre LEDRU + * + * 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 "gw_mpi.h" +#include "sci_mpi.h" +#include "Scierror.h" +#include "localization.h" +#include "api_scilab.h" + +/** + * This function returns the rank of a process within + * the specified communicator. + */ +int sci_mpi_comm_rank (char *fname, unsigned long fname_len) +{ + int comm_rank = 0; + + CheckInputArgument(pvApiCtx, 0, 0); // Check the parameters of the function ... Here 0 + CheckOutputArgument(pvApiCtx, 1, 1); // The output of the function (1 parameter) + + MPI_Comm_rank(MPI_COMM_WORLD, &comm_rank); + + if (createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, (double)comm_rank)) + { + Scierror(999, _("%s: Unable to create variable.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} + diff --git a/modules/mpi/sci_gateway/c/sci_mpi_comm_size.c b/modules/mpi/sci_gateway/c/sci_mpi_comm_size.c new file mode 100755 index 000000000..7566e9189 --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_comm_size.c @@ -0,0 +1,64 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2007-2009 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include "gw_mpi.h" +#include "sci_mpi.h" +#include "api_scilab.h" +#include "stack-c.h" +#include "Scierror.h" +#include "localization.h" +#include "MALLOC.h" + +/** + * This function returns the rank of a process + */ +int sci_mpi_comm_size(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int comm_size; + MPI_Comm comm = MPI_COMM_WORLD; + int *piAddr = NULL; + double dblReal = 0; + + CheckInputArgument(pvApiCtx, 0, 1); // Check the parameters of the function ... Here 0 or 1 + CheckOutputArgument(pvApiCtx, 1, 1); // The output of the function (1 parameter) + + if (nbInputArgument(pvApiCtx) == 1) + { + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr, &dblReal)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); + return 0; + } + + comm = (MPI_Comm)(int)dblReal; + } + + MPI_Comm_size(comm, &comm_size); + if (createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, (double)comm_size)) + { + Scierror(999, _("%s: Memory allocation error.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_finalize.c b/modules/mpi/sci_gateway/c/sci_mpi_finalize.c new file mode 100755 index 000000000..e63334aec --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_finalize.c @@ -0,0 +1,49 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2007-2009 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include "gw_mpi.h" +#include "sci_mpi.h" +#include "Scierror.h" +#include "localization.h" +#include "api_scilab.h" +#include "MALLOC.h" + +static void mpi_finalize_internal() +{ + FREE(listRequestPointer); + FREE(listRequestPointerSize); + FREE(request); +} + +int sci_mpi_finalize(char *fname, unsigned long fname_len) +{ + int iRet = 0; + CheckInputArgument(pvApiCtx, 0, 0); + CheckOutputArgument(pvApiCtx, 1, 1); + mpi_finalize_internal(); + iRet = MPI_Finalize(); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not finalize the MPI instance: %s\n"), fname, error_string); + return 0; + } + + // TODO: catch les erreurs + AssignOutputVariable(pvApiCtx, 1) = 0; + ReturnArguments(pvApiCtx); + return 0; + +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_get_processor_name.c b/modules/mpi/sci_gateway/c/sci_mpi_get_processor_name.c new file mode 100755 index 000000000..8213befd2 --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_get_processor_name.c @@ -0,0 +1,51 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 20011 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include "gw_mpi.h" +#include "sci_mpi.h" +#include "stack-c.h" +#include "api_scilab.h" +#include "Scierror.h" +#include "localization.h" + +/** + * This function returns the rank of a process + */ +int sci_mpi_get_processor_name(char *fname, unsigned long fname_len) +{ + int iSizeProcessorName; + char processorName[MPI_MAX_PROCESSOR_NAME]; + int iRet = 0; + + CheckInputArgument(pvApiCtx, 0, 0); + CheckOutputArgument(pvApiCtx, 1, 1); // The output of the function (1 parameter) + + iRet = MPI_Get_processor_name(processorName, &iSizeProcessorName); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not get processor name: %s\n"), fname, error_string); + return 0; + } + + if (createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, processorName)) + { + Scierror(999, _("%s: Memory allocation error.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_init.c b/modules/mpi/sci_gateway/c/sci_mpi_init.c new file mode 100755 index 000000000..3b0e035bf --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_init.c @@ -0,0 +1,81 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2007-2009 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> // for NULL, fprintf, stderr +#include <mpi.h> +#include "MALLOC.h" +#include "BOOL.h" // for ::TRUE, ::FALSE, BOOL +#include "api_scilab.h" // for pvApiCtx, etc + +/* Create some static datastructure to store all the Request references */ +MPI_Request *request; +int **listRequestPointer; +int *listRequestPointerSize; +static int REQUEST_MAXSIZE = 10000; + +/** + * This function init the MPI env + */ +MPI_Errhandler errhdl; + +/* should be moved elsewhere */ +void MPIErrHandler(MPI_Comm * comm, int *errorcode, ...) +{ + char buffer[4096]; + int resultlen; + + MPI_Error_string(*errorcode, buffer, &resultlen); + buffer[resultlen] = 0; + fprintf(stderr, "MPI internal error: %s\n", buffer); +} + +BOOL mpi_initialized = FALSE; + +static void mpi_init_internal() +{ + int i = 0; + if (mpi_initialized == TRUE) + { + return; + } + + request = (MPI_Request *)MALLOC(REQUEST_MAXSIZE * sizeof(MPI_Request)); + listRequestPointer = (int**)MALLOC(REQUEST_MAXSIZE * sizeof(int*)); + listRequestPointerSize = (int*)MALLOC(REQUEST_MAXSIZE * sizeof(int)); + for (i = 0; i < REQUEST_MAXSIZE; i++) + { + request[i] = 0; + listRequestPointer[i] = NULL; + listRequestPointerSize[i] = 0; + } + + mpi_initialized = TRUE; + +} + +int sci_mpi_init(char *fname, unsigned long fname_len) +{ + int flag; + + CheckInputArgument(pvApiCtx, 0, 0); + CheckOutputArgument(pvApiCtx, 1, 1); + mpi_init_internal(); + MPI_Initialized(&flag); + if (!flag) + { + /* MPI Not yet initialized */ + MPI_Init(NULL, NULL); + MPI_Comm_create_errhandler(MPIErrHandler, &errhdl); + } + AssignOutputVariable(pvApiCtx, 1) = 0; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_irecv.c b/modules/mpi/sci_gateway/c/sci_mpi_irecv.c new file mode 100755 index 000000000..da7373bfb --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_irecv.c @@ -0,0 +1,139 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include <mpi.h> +#include "api_scilab.h" +#include "gw_mpi.h" +#include "sci_mpi.h" +#include "Scierror.h" +#include "localization.h" +#include "MALLOC.h" +#include "deserialization.h" + +int sci_mpi_irecv(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int iRet = 0; + int *piBuffer = NULL; + int iBufferSize = 0; + + int *piAddr1 = NULL; + int *piAddr2 = NULL; + int *piAddr3 = NULL; + double Tag = 0; + double Rank = 0; + int iRequestID = 0; + double dblRequestID = 0; + MPI_Status status; + + CheckInputArgument(pvApiCtx, 3, 3); + CheckOutputArgument(pvApiCtx, 0, 1); + + //Rank + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr1, &Rank)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); + return 0; + } + + //Tag + sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr2, &Tag)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 2); + return 0; + } + + + // Request + sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr3, &dblRequestID)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 3); + return 0; + } + + iRequestID = (int)dblRequestID; + if (iRequestID < 0) + { + Scierror(999, _("%s: Wrong values for input argument #%d: Positive value expected.\n"), fname, 3); + return 0; + } + + iRet = MPI_Probe((int)Rank, (int)Tag, MPI_COMM_WORLD, &status); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Probe failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); + return 0; + } + + iRet = MPI_Get_count(&status, MPI_INT, &iBufferSize); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Get_count failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); + return 0; + } + + piBuffer = (int *)MALLOC(sizeof(int) * iBufferSize); + if (piBuffer == NULL) + { + Scierror(999, "%s: Could not create the received variable.\n", fname); + return 0; + } + + iRet = MPI_Irecv(piBuffer, iBufferSize, MPI_INT, (int)Rank, (int)Tag, MPI_COMM_WORLD, &request[iRequestID]); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Irecv failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); + return 0; + } + + /* Store the pointer piBuffer */ + listRequestPointer[iRequestID] = piBuffer; + listRequestPointerSize[iRequestID] = iBufferSize; + + AssignOutputVariable(pvApiCtx, 1) = 0; + ReturnArguments(pvApiCtx); + return 0; +} + diff --git a/modules/mpi/sci_gateway/c/sci_mpi_isend.c b/modules/mpi/sci_gateway/c/sci_mpi_isend.c new file mode 100755 index 000000000..83ff915e6 --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_isend.c @@ -0,0 +1,112 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include <mpi.h> +#include "api_scilab.h" +#include "gw_mpi.h" +#include "sci_mpi.h" +#include "Scierror.h" +#include "localization.h" +#include "MALLOC.h" +#include "serialization.h" + +#define TAG 0 + + +int sci_mpi_isend(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int iRet = 0; + int *piAddr = NULL; + int *piAddr2 = NULL; + int *piAddr3 = NULL; + + int *piBuffer = NULL; + int iBufferSize = 0; + double NodeID = 0; + int iRequestID = 0; + double dblRequestID = 0; + + CheckInputArgument(pvApiCtx, 3, 3); + CheckOutputArgument(pvApiCtx, 1, 1); + + sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr2, &NodeID)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 2); + return 0; + } + + sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 3); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr3, &dblRequestID)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 3); + return 0; + } + + iRequestID = (int)dblRequestID; + if (iRequestID < 0) + { + Scierror(999, _("%s: Wrong values for input argument #%d: Positive value expected.\n"), fname, 3); + return 0; + } + + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + //convert data from Scilab to MPI + iRet = serialize_to_mpi(pvApiCtx, piAddr, &piBuffer, &iBufferSize); + if (iRet) + { + Scierror(999, _("Unable to serialize data\n")); + return 0; + } + + iRet = MPI_Isend(piBuffer, iBufferSize, MPI_INT, (int)NodeID, TAG, MPI_COMM_WORLD, &request[iRequestID]); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not send the variable to the node %d: %s\n"), fname, NodeID, error_string); + return 0; + } + + if (createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, !iRet)) + { + Scierror(999, _("%s: Memory allocation error.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_recv.c b/modules/mpi/sci_gateway/c/sci_mpi_recv.c new file mode 100755 index 000000000..1c7681f61 --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_recv.c @@ -0,0 +1,121 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include <mpi.h> +#include "api_scilab.h" +#include "gw_mpi.h" +#include "Scierror.h" +#include "MALLOC.h" +#include "localization.h" +#include "deserialization.h" + +int sci_mpi_recv(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int iRet = 0; + int *piBuffer = NULL; + int iBufferSize = 0; + + int *piAddr1 = NULL; + int *piAddr2 = NULL; + double Tag = 0; + double Rank = 0; + MPI_Status status; + + CheckInputArgument(pvApiCtx, 2, 2); + CheckOutputArgument(pvApiCtx, 1, 1); + + //Rank + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr1, &Rank)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); + return 0; + } + + //Tag + sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr2, &Tag)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 2); + return 0; + } + + //wait message "Rank" node + iRet = MPI_Probe((int)Rank, (int)Tag, MPI_COMM_WORLD, &status); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Probe failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); + return 0; + } + + //get data size + iRet = MPI_Get_count(&status, MPI_INT, &iBufferSize); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Get_count failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); + return 0; + } + + //alloc memory to receive data + piBuffer = (int *)MALLOC(sizeof(int) * iBufferSize); + if (piBuffer == NULL) + { + Scierror(999, _("%s: Could not create the received variable.\n"), fname); + return 0; + } + + //receive data + iRet = MPI_Recv(piBuffer, iBufferSize, MPI_INT, (int)Rank, (int)Tag, MPI_COMM_WORLD, &status); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Recv failed. Rank %d / Tag %d: %s\n"), fname, Rank, Tag, error_string); + return 0; + } + + //convert data from MPI to Scilab + iRet = deserialize_from_mpi(pvApiCtx, piBuffer, iBufferSize); + FREE(piBuffer); + if (iRet) + { + Scierror(999, _("%s: Unable to deserialize data !\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} + diff --git a/modules/mpi/sci_gateway/c/sci_mpi_send.c b/modules/mpi/sci_gateway/c/sci_mpi_send.c new file mode 100755 index 000000000..10fbad0ac --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_send.c @@ -0,0 +1,88 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include <mpi.h> +#include "api_scilab.h" +#include "gw_mpi.h" +#include "Scierror.h" +#include "localization.h" +#include "MALLOC.h" +#include "serialization.h" + +#define TAG 0 + +int sci_mpi_send(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int iRet = 0; + int *piAddr = NULL; + int *piAddr2 = NULL; + + int *piBuffer = NULL; + int iBufferSize = 0; + double NodeID = 0; + + CheckInputArgument(pvApiCtx, 2, 2); + CheckOutputArgument(pvApiCtx, 1, 1); + + sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr2, &NodeID)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); + return 0; + } + + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 2); + return 0; + } + + //convert data from Scilab to MPI + iRet = serialize_to_mpi(pvApiCtx, piAddr, &piBuffer, &iBufferSize); + if (iRet) + { + Scierror(999, _("Unable to serialize data\n")); + return 0; + } + + //send data + iRet = MPI_Send(piBuffer, iBufferSize, MPI_INT, (int)NodeID, TAG, MPI_COMM_WORLD); + FREE(piBuffer); + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: Could not send the variable to the node %d: %s\n"), fname, NodeID, error_string); + return 0; + } + + if (createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, !iRet)) + { + Scierror(999, _("%s: Memory allocation error.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/c/sci_mpi_wait.c b/modules/mpi/sci_gateway/c/sci_mpi_wait.c new file mode 100755 index 000000000..6e5042eb1 --- /dev/null +++ b/modules/mpi/sci_gateway/c/sci_mpi_wait.c @@ -0,0 +1,93 @@ +/* + * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab + * Copyright (C) 2011-2011 - DIGITEO - Sylvestre LEDRU + * + * 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 <stdio.h> +#include <mpi.h> +#include "api_scilab.h" +#include "gw_mpi.h" +#include "sci_mpi.h" +#include "Scierror.h" +#include "localization.h" +#include "MALLOC.h" +#include "serialization.h" +#include "deserialization.h" + +int sci_mpi_wait(char *fname, unsigned long fname_len) +{ + SciErr sciErr; + int iRet = 0; + int *piAddr = NULL; + int *piBuffer = NULL; + int iBufferSize = 0; + double NodeID = 0; + int iRequestID; + double dblRequestID; + + CheckInputArgument(pvApiCtx, 1, 1); + CheckOutputArgument(pvApiCtx, 1, 1); + + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); + if (sciErr.iErr) + { + printError(&sciErr, 0); + Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1); + return 0; + } + + if (getScalarDouble(pvApiCtx, piAddr, &dblRequestID)) + { + Scierror(999, _("%s: Wrong type for input argument #%d: A scalar integer value expected.\n"), fname, 1); + return 0; + } + + iRequestID = (int)dblRequestID; + + if (iRequestID < 0) + { + Scierror(999, _("%s: Wrong values for input argument #%d: Positive value expected.\n"), fname, 1); + return 0; + } + + iRet = MPI_Wait(&request[iRequestID], MPI_STATUS_IGNORE); /* TODO: MPI_COMM_WORLD should be changed */ + if (iRet != MPI_SUCCESS) + { + char error_string[MPI_MAX_ERROR_STRING]; + int length_of_error_string; + + MPI_Error_string(iRet, error_string, &length_of_error_string); + Scierror(999, _("%s: MPI_Wait failed while waiting %d: %s\n"), fname, NodeID, error_string); + return 0; + } + + /* Restore the list */ + piBuffer = listRequestPointer[iRequestID]; + iBufferSize = listRequestPointerSize[iRequestID]; + + if (iBufferSize == 0) + { + //wait on sender not on receiver + AssignOutputVariable(pvApiCtx, 1) = 0; + ReturnArguments(pvApiCtx); + return 0; + } + + iRet = deserialize_from_mpi(pvApiCtx, piBuffer, iBufferSize); + FREE(piBuffer); + if (iRet) + { + Scierror(999, _("%s: Unable to deserialize data.\n"), fname); + return 0; + } + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} diff --git a/modules/mpi/sci_gateway/mpi b/modules/mpi/sci_gateway/mpi new file mode 100755 index 000000000..bc79227ae --- /dev/null +++ b/modules/mpi/sci_gateway/mpi @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> + +<!DOCTYPE GATEWAY SYSTEM "../../functions/xml/gateway.dtd"> + +<GATEWAY> + +<!-- =================== --> +<!-- + Scilab + Sylvestre Ledru + INRIA 2007 + =================== + Don't edit if you aren't sure +--> +<!-- =================== --> + +<PRIMITIVE> + <GATEWAY_ID>52</GATEWAY_ID> + <PRIMITIVE_ID>1</PRIMITIVE_ID> + <PRIMITIVE_NAME>mpi_init</PRIMITIVE_NAME> +</PRIMITIVE> + +<PRIMITIVE> + <GATEWAY_ID>52</GATEWAY_ID> + <PRIMITIVE_ID>2</PRIMITIVE_ID> + <PRIMITIVE_NAME>mpi_finalize</PRIMITIVE_NAME> +</PRIMITIVE> + + +<PRIMITIVE> + <GATEWAY_ID>52</GATEWAY_ID> + <PRIMITIVE_ID>3</PRIMITIVE_ID> + <PRIMITIVE_NAME>mpi_comm_size</PRIMITIVE_NAME> +</PRIMITIVE> + +<!-- +;52 1 mpi_send +;52 2 mpi_recv +;52 3 mpi_isend +;52 4 mpi_irecv +;52 5 mpi_init +;52 6 mpi_finalize +;52 7 mpi_comm_rank +--> + +</GATEWAY> diff --git a/modules/mpi/sci_gateway/mpi_gateway.xml b/modules/mpi/sci_gateway/mpi_gateway.xml new file mode 100755 index 000000000..276218ada --- /dev/null +++ b/modules/mpi/sci_gateway/mpi_gateway.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE GATEWAY SYSTEM "../../functions/xml/gateway.dtd"> +<GATEWAY name="mpi"> + <!-- =================== --> + <!-- + Scilab + Interface description. In this file, we define the list of the function which + will be available into Scilab and the link to the "native" function. + + gatewayId is the position in the hashtable 'Interfaces' defined in the + file SCI/modules/core/src/c/callinterf.h + + primitiveId is the position in the hashtable '<module>Table Tab[]' defined + in the file modules/<module>/sci_gateway/c/gw_<module>.c + + primitiveName is the name of the Scilab function + + @author Allan CORNET + @author Sylvestre LEDRU + @date INRIA 2007 + =================== + Don't touch if you do not know what you are doing +--> + <!-- =================== --> + <PRIMITIVE gatewayId="73" primitiveId="1" primitiveName="MPI_Init"/> + <PRIMITIVE gatewayId="73" primitiveId="2" primitiveName="MPI_Finalize"/> + <PRIMITIVE gatewayId="73" primitiveId="3" primitiveName="MPI_Comm_size"/> + <PRIMITIVE gatewayId="73" primitiveId="4" primitiveName="MPI_Comm_rank"/> + <PRIMITIVE gatewayId="73" primitiveId="5" primitiveName="MPI_Recv"/> + <PRIMITIVE gatewayId="73" primitiveId="6" primitiveName="MPI_Send"/> + <PRIMITIVE gatewayId="73" primitiveId="7" primitiveName="MPI_Get_processor_name"/> + <PRIMITIVE gatewayId="73" primitiveId="8" primitiveName="MPI_Bcast"/> + <PRIMITIVE gatewayId="73" primitiveId="9" primitiveName="MPI_Irecv"/> + <PRIMITIVE gatewayId="73" primitiveId="10" primitiveName="MPI_Isend"/> + <PRIMITIVE gatewayId="73" primitiveId="11" primitiveName="MPI_Wait"/> +</GATEWAY> |