From: <cd...@us...> - 2012-08-22 02:46:48
|
Revision: 10894 http://octave.svn.sourceforge.net/octave/?rev=10894&view=rev Author: cdf Date: 2012-08-22 02:46:39 +0000 (Wed, 22 Aug 2012) Log Message: ----------- code maintainance, simplification and cleanup before new release Modified Paths: -------------- trunk/octave-forge/main/openmpi_ext/inst/Pi.m trunk/octave-forge/main/openmpi_ext/inst/helloworld.m trunk/octave-forge/main/openmpi_ext/src/MPI_Barrier.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Load.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Test.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_rank.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_size.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Finalize.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Finalized.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Get_processor_name.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Init.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Initialized.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Iprobe.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Load.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Test.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Probe.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Recv.cc trunk/octave-forge/main/openmpi_ext/src/MPI_Send.cc trunk/octave-forge/main/openmpi_ext/src/Makefile trunk/octave-forge/main/openmpi_ext/src/simple.h Modified: trunk/octave-forge/main/openmpi_ext/inst/Pi.m =================================================================== --- trunk/octave-forge/main/openmpi_ext/inst/Pi.m 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/inst/Pi.m 2012-08-22 02:46:39 UTC (rev 10894) @@ -18,7 +18,7 @@ # For instance addpath("../src"); # mpirun -np 5 octave -q --eval "Pi(2E7,'s')" -function Pi(N,mod) +function results = Pi(N,mod) addpath("../src"); # Pi: Classic PI computation by numeric integration of arctan'(x) in [0..1] # Modified: trunk/octave-forge/main/openmpi_ext/inst/helloworld.m =================================================================== --- trunk/octave-forge/main/openmpi_ext/inst/helloworld.m 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/inst/helloworld.m 2012-08-22 02:46:39 UTC (rev 10894) @@ -15,7 +15,7 @@ # Please add the oct files openmpi_ext folder # For instance -addpath("../src"); +addpath('../src'); # if you have 4 cores or a network of 4 computers with a ssh connection with no password and same openmpi 1.3.3 installation # type at the terminal mpirun -np 4 octave --eval helloworld Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Barrier.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Barrier.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Barrier.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Barrier +#define NAME MPI_Barrier /* * ---------------------------------------------------- * Blocks until all processes in the communicator have reached this routine @@ -23,61 +23,64 @@ * ---------------------------------------------------- */ +#include "simple.h" -#include "simple.h" -DEFUN_DLD(NAME, args, ,"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} @var{INFO} = MPI_Barrier (@var{COMM})\n\ -Blocks until all processes in the communicator have reached this routine.\n\ -If @var{COMM} octave comunicator object loaded with MPI_Comm_Load is omitted \n\ -returns an error. \n\ - @example\n\ - @group\n\ - @var{INFO} (int) return code\n\ - 0 MPI_SUCCESS No error\n\ - 5 MPI_ERR_COMM Invalid communicator (NULL?)\n\ - 13 MPI_ERR_ARG Invalid argument (typically a NULL pointer?)\n\ -@end group\n\ -@end example\n\ +DEFUN_DLD (NAME, args, , +"-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} @var{INFO} = MPI_Barrier (@var{COMM})\n \ +Blocks until all processes in the communicator have reached this routine.\n \ +If @var{COMM} octave comunicator object loaded with MPI_Comm_Load is omitted \n \ +returns an error. \n \ + @example\n \ + @group\n \ + @var{INFO} (int) return code\n \ + 0 MPI_SUCCESS No error\n \ + 5 MPI_ERR_COMM Invalid communicator (NULL?)\n \ + 13 MPI_ERR_ARG Invalid argument (typically a NULL pointer?)\n \ +@end group\n \ +@end example\n \ @end deftypefn") { - octave_value results; - int nargin = args.length (); - if (nargin != 1) - { - error ("expecting 1 input argument"); - return results; - } + octave_value results; + int nargin = args.length (); - if (!simple_type_loaded) + if (nargin != 1) + print_usage (); + else { - simple::register_type (); - simple_type_loaded = true; - mlock (); + if((args.length () != 1) + || args(0).type_id () != simple::static_type_id ()) + { + error ("MPI_Barrier: Please enter octave comunicator object"); + results(0) = octave_value(-1); + } + else + { + if (! simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } + + const octave_base_value& rep = args(0).get_rep(); + const simple& B = ((const simple &)rep); + MPI_Comm comm = ((const simple&) B).comunicator_value (); + if (! error_state) + { + int my_size; + int info = MPI_Barrier (comm); + + results = info; + } + else + print_usage (); + } } - - if((args.length() != 1 ) - || args(0).type_id()!=simple::static_type_id()){ - - error("Please enter octave comunicator object!"); - return octave_value(-1); - } - - const octave_base_value& rep = args(0).get_rep(); - const simple& B = ((const simple &)rep); - MPI_Comm comm = ((const simple&) B).comunicator_value (); - if (! error_state) - { - int my_size; - int info = MPI_Barrier (comm); - - results = info; - } - else - print_usage (); - comm= NULL; - /* [info] = MPI_Barrier (comm) */ + comm= NULL; + /* [info] = MPI_Barrier (comm) */ - return results; + return results; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Load.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Load.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Load.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -35,22 +35,19 @@ @end example\n\ @end deftypefn") { - if (!simple_type_loaded) - { - simple::register_type (); - simple_type_loaded = true; - mlock (); - } - octave_value retval; - if (args.length () != 1 || !args (0).is_string ()) + if (args.length () != 1 || ! args (0).is_string ()) + print_usage (); + else { - error ("MPI_Comm_Load: first argument must be a string"); - return retval; - } - - const std::string name = args (0).string_value (); - retval = new simple (name,MPI_COMM_WORLD); - + if (!simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } + const std::string name = args (0).string_value (); + retval = new simple (name,MPI_COMM_WORLD); + } return retval; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Test.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Test.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_Test.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -33,24 +33,26 @@ @end example\n\ @end deftypefn") { - if (!simple_type_loaded) + octave_value retval; + if(args.length() != 1 + || args(0).type_id () != simple::static_type_id ()) { - simple::register_type (); - simple_type_loaded = true; - mlock (); + print_usage (); + results = octave_value (-1); } - - octave_value retval; - if(args.length() != 1 - || args(0).type_id()!=simple::static_type_id()){ - - error("usage: MPI_Comm_Test(octave_comunicator_object)"); - return octave_value(-1); - } - const octave_base_value& rep = args(0).get_rep(); - const simple& b = ((const simple &)rep); - octave_stdout << "MPI_Comm_Test has " << b.name_value() << " output arguments.\n"; - MPI_Comm res = b.comunicator_value(); - retval = b.name_value(); + else + { + if (! simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } + const octave_base_value& rep = args(0).get_rep (); + const simple& b = ((const simple &)rep); + //octave_stdout << "MPI_Comm_Test has " << b.name_value() << " output arguments.\n"; + MPI_Comm res = b.comunicator_value (); + retval = b.name_value (); + } return retval; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_rank.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_rank.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_rank.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Comm_rank +#define NAME MPI_Comm_rank /* * ---------------------------------------------------- * Determines the rank of the calling process in the communicator @@ -40,46 +40,40 @@ @end group\n\ @end example\n\ @end deftypefn") - { - octave_value_list results; - int nargin = args.length (); - if (nargin != 1) - { - error ("expecting 1 input argument"); - return results; - } + octave_value_list results; + int nargin = args.length (); - if (!simple_type_loaded) + if (nargin != 1) + print_usage (); + else { - simple::register_type (); - simple_type_loaded = true; - mlock (); - } + if (! simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } - if((args.length() != 1 ) - || args(0).type_id()!=simple::static_type_id()){ - - error("Please enter octave comunicator object!"); - return octave_value(-1); - } + if (args(0).type_id () == simple::static_type_id ()) + { + const octave_base_value& rep = args(0).get_rep (); + const simple& B = ((const simple &)rep); + MPI_Comm comm = ((const simple&) B).comunicator_value (); + if (! error_state) + { + int my_rank; + int info = MPI_Comm_rank (comm, &my_rank); + if (nargout > 1) + results(1) = info; - const octave_base_value& rep = args(0).get_rep(); - const simple& B = ((const simple &)rep); - MPI_Comm comm = ((const simple&) B).comunicator_value (); - if (! error_state) - { - int my_rank; - int info = MPI_Comm_rank (comm, &my_rank); - if (nargout > 1) - results(1) = info; - results(0) = my_rank; - } - else - print_usage (); - comm= NULL; - /* [rank info] = MPI_Comm_rank (comm) */ - - return results; - + results(0) = my_rank; + } + else + print_usage (); + } + else + error ("MPI_Comm_rank: Please enter octave comunicator object"); + } + return results; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_size.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_size.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Comm_size.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Comm_size +#define NAME MPI_Comm_size /* * ---------------------------------------------------- * Determines the size of the calling process in the communicator @@ -42,46 +42,45 @@ @end deftypefn") { - octave_value_list results; - int nargin = args.length (); - if (nargin != 1) - { - error ("expecting 1 input argument"); - return results; - } - - if (!simple_type_loaded) + octave_value_list results; + int nargin = args.length (); + if (nargin != 1) + print_usage (); + else { - simple::register_type (); - simple_type_loaded = true; - mlock (); - } + if (! simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } - if((args.length() != 1 ) - || args(0).type_id()!=simple::static_type_id()){ - - error("Please enter octave comunicator object!"); - return octave_value(-1); + if ((args.length() != 1 ) + || args(0).type_id () != simple::static_type_id ()) + { + error("MPI_Comm_size: Please enter octave comunicator object"); + results(0) = octave_value(-1); } - - const octave_base_value& rep = args(0).get_rep(); - const simple& B = ((const simple &)rep); - MPI_Comm comm = ((const simple&) B).comunicator_value (); - - - if (! error_state) - { - int my_size; - int info = MPI_Comm_size (comm, &my_size); - if (nargout > 1) - results(1) = info; - results(0) = my_size; - } - else - print_usage (); - comm= NULL; - /* [size info] = MPI_Comm_size (comm) */ - - return results; + else + { + const octave_base_value& rep = args(0).get_rep (); + const simple& B = ((const simple &)rep); + MPI_Comm comm = ((const simple&) B).comunicator_value (); + + if (! error_state) + { + int my_size; + int info = MPI_Comm_size (comm, &my_size); + if (nargout > 1) + results(1) = info; + results(0) = my_size; + } + else + print_usage (); + } + comm = NULL; + /* [size info] = MPI_Comm_size (comm) */ + } + return results; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Finalize.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Finalize.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Finalize.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Finalize +#define NAME MPI_Finalize + /* * ---------------------------------------------------- * Terminates MPI execution environment * info = MPI_Finalize * ---------------------------------------------------- */ + #include "mpi.h" #include <octave/oct.h> @@ -39,8 +41,6 @@ @end example\n\ @end deftypefn") { - - int info = MPI_Finalize(); - - return octave_value(info); + int info = MPI_Finalize (); + return octave_value (info); } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Finalized.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Finalized.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Finalized.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Finalized +#define NAME MPI_Finalized /* * ---------------------------------------------------- * Indicates whether MPI_Finalize has completed @@ -39,14 +39,15 @@ @end example\n\ @end deftypefn") { - octave_value_list results; - int flag; + octave_value_list results; + int flag; + + int info = MPI_Finalized (&flag); + if (nargout > 1) + results(1) = info; - int info = MPI_Finalized(&flag); - if (nargout > 1) - results(1) = info; - results(0) = flag != 0; - return results; + results(0) = flag != 0; + return results; - /* [flag info] = MPI_Finalized */ + /* [flag info] = MPI_Finalized */ } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Get_processor_name.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Get_processor_name.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Get_processor_name.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -17,6 +17,7 @@ #include "mpi.h" #include <octave/oct.h> + DEFUN_DLD(MPI_Get_processor_name, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} @var{name,resultlen,INFO} = MPI_Get_processor_name()\n\ Get the name of the processor that is using MPI\n\ @@ -33,24 +34,26 @@ @end example\n\ @end deftypefn") { - int info; - int nargin = args.length(); - for (int i=0; i<nargin; i++){ - if( nargin != 0 ) { - error("MPI_Get_processor_name: please do not enter arguments"); - return octave_value (MPI_ERR_ARG); // error returns nothing + int info; + int nargin = args.length (); + octave_value_list results; + if (nargin != 0) + { + print_usage (); + results(0) = octave_value (MPI_ERR_ARG); } + else + { + std::string cpp_string; + char argv[MPI_MAX_PROCESSOR_NAME]; + int resultlen = 0; + + info = MPI_Get_processor_name (argv, &resultlen); + cpp_string = argv; + results(0) = cpp_string; + results(1) = resultlen; + results(2) = info; } - octave_value_list results; - std::string cpp_string; - char argv[MPI_MAX_PROCESSOR_NAME]; - int resultlen=0; - - info = MPI_Get_processor_name(argv, &resultlen); - cpp_string = argv; - results(0) = cpp_string; - results(1) = resultlen; - results(2) = info; - return results; + return results; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Init.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Init.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Init.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -21,10 +21,11 @@ * ---------------------------------------------------- */ -#define NAME MPI_Init +#define NAME MPI_Init #include "mpi.h" // mpi.h, oct.h #include <octave/oct.h> + DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} @var{INFO} = MPI_Init()\n\ Initialize the MPI execution environment\n\ @@ -41,22 +42,21 @@ @end example\n\ @end deftypefn") { - int nargin = args.length(); - for (int i=0; i<nargin; i++){ - if( ! args(i).is_string() ) { - error("MPI_Init: args must be strings"); - return octave_value (MPI_ERR_ARG); // error returns nothing + int nargin = args.length(); + for (int i = 0; i < nargin; i++) + { + if (! args(i).is_string ()) + { + error ("MPI_Init: args must be strings"); + return octave_value (MPI_ERR_ARG); // error returns nothing + } } - } - string_vector argvec = args.make_argv("MPI_Init"); - char **argve= argvec.c_str_vec(); - char **argv =&argve[1]; - -// printf("args: "); for (int i=0; i<nargin; i++) printf("%s ",argv[i]); -// printf("\n"); - - int info = MPI_Init(&nargin, &argv); + string_vector argvec = args.make_argv ("MPI_Init"); + char **argve= argvec.c_str_vec (); + char **argv = &argve[1]; + + int info = MPI_Init (&nargin, &argv); free(argve); return octave_value (info); } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Initialized.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Initialized.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Initialized.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -14,15 +14,17 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Initialized +#define NAME MPI_Initialized /* * ---------------------------------------------------- * Indicates whether MPI_Initialize has been called * [info flag] = MPI_Initialized * ---------------------------------------------------- */ + #include "mpi.h" #include <octave/oct.h> + DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} [@var{FLAG} @var{INFO}] = MPI_Initialized\n\ Indicates whether MPI_Init has been called\n\ @@ -41,12 +43,12 @@ { octave_value_list results; int flag; + int info = MPI_Initialized (&flag); + if (nargout > 1) + results (1) = info; - int info = MPI_Initialized(&flag); - if (nargout > 1) - results(1) = info; - results(0) = flag != 0; + results(0) = octave_value (flag != 0); + return results; - /* [flag info] = MPI_Initialized */ } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Iprobe.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Iprobe.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Iprobe.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -14,37 +14,37 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Iprobe +#define NAME MPI_Iprobe /* * ---------------------------------------------------- * Nonblocking test for a message * [info flag stat] = MPI_Iprobe (src, tag, comm) * ---------------------------------------------------- */ + #include "simple.h" #include <octave/ov-struct.h> -Octave_map put_MPI_Stat (const MPI_Status &stat){ -/*---------------------------------------------*/ - Octave_map map; - octave_value tmp = stat.MPI_SOURCE; - map.assign("src", tmp); - tmp = stat.MPI_TAG; - map.assign("tag", tmp ); - tmp = stat.MPI_ERROR; - map.assign("err", tmp ); - tmp = stat._count; - map.assign("cnt", tmp); - tmp = stat._cancelled; - map.assign("can", tmp); +Octave_map put_MPI_Stat (const MPI_Status &stat) +{ + /*---------------------------------------------*/ + Octave_map map; + octave_value tmp = stat.MPI_SOURCE; + map.assign ("src", tmp); + tmp = stat.MPI_TAG; + map.assign ("tag", tmp ); + tmp = stat.MPI_ERROR; + map.assign ("err", tmp ); + tmp = stat._count; + map.assign ("cnt", tmp); + tmp = stat._cancelled; + map.assign ("can", tmp); - return map; + return map; } - - DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} [@var{FLAG} @var{STAT} @var{INFO}] = MPI_Iprobe(@var{SRCRANK}, @var{TAG}, @var{COMM})\n\ +@deftypefn {Loadable Function} {} [@var{FLAG} @var{STAT} @var{INFO}] = MPI_Iprobe(@var{SRCRANK}, @var{TAG}, @var{COMM})\n \ Nonblocking test for a message\n\ @example\n\ @group\n\ @@ -70,58 +70,47 @@ SEE ALSO: MPI_Probe, MPI_Recv, MPI documentation for examples\n\ @end deftypefn") { - octave_value_list results; - int nargin = args.length (); - if (nargin != 3) - { - error ("expecting 3 input arguments"); - return results; - } - - - - - if (!simple_type_loaded) + octave_value_list results; + int nargin = args.length (); + if (nargin != 3) + print_usage (); + else { - simple::register_type (); - simple_type_loaded = true; - mlock (); - } + if (! simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } - if( args(2).type_id()!=simple::static_type_id()){ - - error("Please enter octave comunicator object!"); - return octave_value(-1); - } - - const octave_base_value& rep = args(2).get_rep(); - const simple& B = ((const simple &)rep); - MPI_Comm comm = ((const simple&) B).comunicator_value (); - if (error_state) - return results; - - int src = args(0).int_value(); - if (error_state) - { - error ("expecting first argument to be an integer"); - return results; + if (args(2).type_id() != simple::static_type_id ()) + { + error ("MPI_Iprobe: Please enter octave comunicator object"); + results = octave_value (-1); + } + else + { + const octave_base_value& rep = args(2).get_rep(); + const simple& B = ((const simple &)rep); + MPI_Comm comm = ((const simple&) B).comunicator_value (); + int src = args(0).int_value(); + int tag = args(1).int_value(); + if (! error_state) + { + int flag; + MPI_Status stat = {0, 0, 0, 0}; + int info = MPI_Iprobe (src, tag, comm, &flag, &stat); + comm = NULL; + results(0) = flag; + results(1) = put_MPI_Stat (stat); + results(2) = info; + } + else + print_usage (); + } } - - int tag = args(1).int_value(); - if (error_state) - { - error ("expecting second argument to be an integer"); - return results; - } - int flag; - MPI_Status stat = {0,0,0,0}; - int info = MPI_Iprobe(src,tag,comm,&flag,&stat); - comm= NULL; - results(0) = flag; - results(1) = put_MPI_Stat(stat); - results(2) = info; - return results; - /* [flag stat info] = MPI_Iprobe (src, tag, comm) */ + return results; + /* [flag stat info] = MPI_Iprobe (src, tag, comm) */ } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Load.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Load.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Load.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -17,23 +17,23 @@ DEFUN_DLD(MPI_Op_Load, args, ,"") { - if (!simpleop_type_loaded) + octave_value_list retval; + if (! simpleop_type_loaded) { simpleop::register_type (); simpleop_type_loaded = true; mlock (); } - + octave_value retval; - if (args.length () != 1 || !args (0).is_string ()) + if (args.length () != 1 + || ! args (0).is_string ()) + print_usage (); + else { - error ("simpleop: first argument must be a string"); - return retval; + const std::string name = args (0).string_value (); + MPI_Op OP; + retval = new simpleop (name, OP); } - - const std::string name = args (0).string_value (); - MPI_Op OP; - retval = new simpleop (name,OP); - return retval; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Test.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Test.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Op_Test.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -17,7 +17,8 @@ DEFUN_DLD(MPI_Op_Test, args, ,"") { - if (!simpleop_type_loaded) + + if (! simpleop_type_loaded) { simpleop::register_type (); simpleop_type_loaded = true; @@ -25,16 +26,19 @@ } octave_value retval; - if(args.length() != 1 - || args(0).type_id()!=simpleop::static_type_id()){ - - error("usage: simpleoptest(simpleopobject)"); - return octave_value(-1); - } - const octave_base_value& rep = args(0).get_rep(); - const simpleop& b = ((const simpleop &)rep); - octave_stdout << "simpleoptest has " << b.name_value() << " output arguments.\n"; - MPI_Op res = b.operator_value(); - + if (args.length () != 1 + || args(0).type_id() != simpleop::static_type_id () + || error_state) + { + print_usage (); + retval = octave_value (-1); + } + else + { + const octave_base_value& rep = args(0).get_rep(); + const simpleop& b = ((const simpleop &)rep); + octave_stdout << "simpleoptest has " << b.name_value() << " output arguments.\n"; + MPI_Op res = b.operator_value(); + } return retval; } Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Probe.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Probe.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Probe.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License along with // this program; if not, see <http://www.gnu.org/licenses/>. -#define NAME MPI_Probe +#define NAME MPI_Probe /* * ---------------------------------------------------- * Blocking test for a message @@ -22,30 +22,28 @@ * ---------------------------------------------------- */ #include "simple.h" - #include <octave/ov-struct.h> - - -Octave_map put_MPI_Stat (const MPI_Status &stat){ -/*---------------------------------------------*/ - Octave_map map; - octave_value tmp = stat.MPI_SOURCE; - map.assign("src", tmp); - tmp = stat.MPI_TAG; - map.assign("tag", tmp ); - tmp = stat.MPI_ERROR; - map.assign("err", tmp ); - tmp = stat._count; - map.assign("cnt", tmp); - tmp = stat._cancelled; - map.assign("can", tmp); - - return map; +Octave_map put_MPI_Stat (const MPI_Status &stat) +{ + /*---------------------------------------------*/ + Octave_map map; + octave_value tmp = stat.MPI_SOURCE; + map.assign ("src", tmp); + tmp = stat.MPI_TAG; + map.assign ("tag", tmp); + tmp = stat.MPI_ERROR; + map.assign ("err", tmp); + tmp = stat._count; + map.assign("cnt", tmp); + tmp = stat._cancelled; + map.assign("can", tmp); + + return map; } DEFUN_DLD(NAME, args, nargout,"-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} [@var{STAT} @var{INFO}] = MPI_Probe(@var{SRCRANK}, @var{TAG}, @var{COMM})\n\ +@deftypefn {Loadable Function} {} [@var{STAT} @var{INFO}] = MPI_Probe(@var{SRCRANK}, @var{TAG}, @var{COMM})\n \ blocking test for a message\n\ @example\n\ @group\n\ @@ -68,57 +66,46 @@ SEE ALSO: MPI_Iprobe, MPI_Recv, and MPI documentation for C examples\n\ @end deftypefn") { - octave_value_list results; - int nargin = args.length (); - if (nargin != 3) - { - error ("expecting 3 input arguments"); - return results; - } - - - - - - - if (!simple_type_loaded) + octave_value_list results; + int nargin = args.length (); + if (nargin != 3) + print_usage (); + else { - simple::register_type (); - simple_type_loaded = true; - mlock (); - } + if (!simple_type_loaded) + { + simple::register_type (); + simple_type_loaded = true; + mlock (); + } - if( args(2).type_id()!=simple::static_type_id()){ - - error("Please enter octave comunicator object!"); - return octave_value(-1); - } + if (args(2).type_id () == simple::static_type_id ()) + { + const octave_base_value& rep = args(2).get_rep (); + const simple& B = ((const simple &)rep); + MPI_Comm comm = ((const simple&) B).comunicator_value (); + int src = args(0).int_value (); + int tag = args(1).int_value (); + + if (! error_status) + { + MPI_Status stat = {0, 0, 0, 0}; + int info = MPI_Probe (src, tag, comm, &stat); + comm= NULL; + results(0) = put_MPI_Stat (stat); + results(1) = info; + } + } + else + { + print_usage (); + results = octave_value (-1); + } - const octave_base_value& rep = args(2).get_rep(); - const simple& B = ((const simple &)rep); - MPI_Comm comm = ((const simple&) B).comunicator_value (); - int src = args(0).int_value(); - if (error_state) - { - error ("expecting first argument to be an integer"); return results; + + /* [ stat info ] = MPI_Probe (src, tag, comm) */ } - - int tag = args(1).int_value(); - if (error_state) - { - error ("expecting second argument to be an integer"); - return results; - } - MPI_Status stat = {0,0,0,0}; - int info = MPI_Probe(src,tag,comm,&stat); - comm= NULL; - results(0) = put_MPI_Stat(stat); - results(1) = info; - return results; - /* [ stat info ] = MPI_Probe (src, tag, comm) */ } - - Modified: trunk/octave-forge/main/openmpi_ext/src/MPI_Recv.cc =================================================================== --- trunk/octave-forge/main/openmpi_ext/src/MPI_Recv.cc 2012-08-21 01:12:21 UTC (rev 10893) +++ trunk/octave-forge/main/openmpi_ext/src/MPI_Recv.cc 2012-08-22 02:46:39 UTC (rev 10894) @@ -1,5 +1,6 @@ // Copyright (C) 2009 Riccardo Corradini <ric...@ya...> // Copyright (C) 2009 VZLU Prague +// Copyright (C) 2012 Carlo de Falco // // This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software @@ -18,38 +19,41 @@ #include <ov-cell.h> // avoid errmsg "cell -- incomplete datatype" #include <oct-map.h> // avoid errmsg "Oct.map -- invalid use undef type" +/*---------------------*/ +/* forward declaration */ +int recv_class (MPI_Comm comm, octave_value &ov, int source, int mytag); -/*----------------------------------*/ /* forward declaration */ +/*-----------------------------*/ +/* along the datatype */ +/* to receive any octave_value */ +int recv_cell (MPI_Comm comm, octave_value &ov, int source, int mytag); +int recv_struct ( MPI_Comm comm, octave_value &ov, int source, int mytag); +int recv_string ( MPI_Comm comm, octave_value &ov, int source, int mytag); +int recv_range (MPI_Comm comm, octave_value &ov, int source, int mytag); - -int recv_class( MPI_Comm comm, octave_value &ov, int source, int mytag); /* along the datatype */ -/*----------------------------------*/ /* to receive any octave_value */ - -int recv_cell(MPI_Comm comm,octave_value &ov, int source, int mytag); -int recv_struct( MPI_Comm comm, octave_value &ov, int source, int mytag); -int recv_string( MPI_Comm comm, octave_value &ov,int source, int mytag); -int recv_range(MPI_Comm comm, octave_value &ov,int source, int mytag); - template<class AnyElem> -int recv_vec(MPI_Comm comm, AnyElem &LBNDA, int nitem, MPI_Datatype TRCV ,int source, int mytag); +int recv_vec (MPI_Comm comm, AnyElem &LBNDA, int nitem, MPI_Datatype TRCV, int source, int mytag); -int recv_matrix(bool is_complex,MPI_Datatype TRcv, MPI_Comm comm, octave_value &ov,int source, int mytag); -int recv_sp_mat(bool is_complex,MPI_Datatype TRcv, MPI_Comm comm, octave_value &ov,int source, int mytag); +int recv_matrix (bool is_complex, MPI_Datatype TRcv, MPI_Comm comm, octave_value &ov, int source, int mytag); +int recv_sp_mat (bool is_complex, MPI_Datatype TRcv, MPI_Comm comm, octave_value &ov, int source, int mytag); template <class Any> int recv_scalar(MPI_Datatype TRcv, MPI_Comm comm, Any *d, int source, int mytag); + template <class Any> int recv_scalar(MPI_Datatype TRcv, MPI_Comm comm, std::complex<Any> *d, int source, int mytag); - - -int recv_range(MPI_Comm comm, octave_value &ov,int source, int mytag){ /* put base,limit,incr,nelem */ -/*-------------------------------*/ /* just 3 doubles + 1 int */ -// octave_range (double base, double limit, double inc) +int recv_range (MPI_Comm comm, octave_value &ov, int source, int mytag) +{ + /*---------------------------*/ + /* put base,limit,incr,nelem */ + /* just 3 doubles + 1 int */ + + // octave_range (double base, double limit, double inc) MPI_Status stat; OCTAVE_LOCAL_BUFFER(int,tanktag,3); tanktag[0] = mytag; @@ -58,578 +62,629 @@ OCTAVE_LOCAL_BUFFER(double,d,2); // first receive - int info = MPI_Recv(d, 3, MPI_DOUBLE, source, tanktag[1] , comm,&stat); - if (info !=MPI_SUCCESS) return info; - int nelem=0; - info = MPI_Recv(&nelem, 1, MPI_INT, source, tanktag[2] , comm,&stat); - if (info !=MPI_SUCCESS) return info; -// b = d[0]; -// l = d[1]; -// i = d[2]; - Range r(d[0],d[2],nelem); - ov =r; -return(info); + int info = MPI_Recv (d, 3, MPI_DOUBLE, source, tanktag[1], comm, &stat); + if (info != MPI_SUCCESS) + return info; + + int nelem = 0; + info = MPI_Recv (&nelem, 1, MPI_INT, source, tanktag[2], comm, &stat); + + if (info != MPI_SUCCESS) + return info; + + Range r (d[0], d[2], nelem); + ov = r; + + return info; } // This will get the fortran_vec vector for Any type Octave can handle template<class AnyElem> -int recv_vec(MPI_Comm comm, AnyElem &LBNDA, int nitem ,MPI_Datatype TRCV ,int source, int mytag) +int recv_vec (MPI_Comm comm, AnyElem &LBNDA, int nitem, MPI_Datatype TRCV, int source, int mytag) { - MPI_Datatype fortvec; - MPI_Type_contiguous(nitem,TRCV, &fortvec); - MPI_Type_commit(&fortvec); - MPI_Status stat; - int info = MPI_Recv((LBNDA), 1,fortvec, source, mytag , comm,&stat); - return(info); + MPI_Datatype fortvec; + MPI_Type_contiguous (nitem, TRCV, &fortvec); + MPI_Type_commit (&fortvec); + MPI_Status stat; + int info = MPI_Recv ((LBNDA), 1, fortvec, source, mytag, comm, &stat); + return (info); } - - // template specialization for complex case template <class Any> -int recv_scalar(MPI_Datatype TRcv ,MPI_Comm comm, std::complex<Any> &d, int source, int mytag){ +int recv_scalar (MPI_Datatype TRcv, MPI_Comm comm, std::complex<Any> &d, int source, int mytag) +{ int info; MPI_Status stat; OCTAVE_LOCAL_BUFFER(int,tanktag,2); tanktag[0] = mytag; tanktag[1] = mytag+1; OCTAVE_LOCAL_BUFFER(std::complex<Any>,Deco,2); - Deco[0] = real(d); - Deco[1] = imag(d); + Deco[0] = real (d); + Deco[1] = imag (d); - info = MPI_Recv((&Deco), 2,TRcv, source, tanktag[1] , comm,&stat); - if (info !=MPI_SUCCESS) return info; + info = MPI_Recv ((&Deco), 2, TRcv, source, tanktag[1], comm, &stat); - return(info); + return info; } template <class Any> -int recv_scalar(MPI_Datatype TRcv , MPI_Comm comm, Any &d, int source, int mytag){ /* directly MPI_Recv it, */ -/*-----------------------------*/ /* it's just a value */ -OCTAVE_LOCAL_BUFFER(int,tanktag,2); +int recv_scalar (MPI_Datatype TRcv, MPI_Comm comm, Any &d, int source, int mytag) +{ + /*-----------------------*/ + /* it's just a value */ + /* directly MPI_Recv it, */ + + OCTAVE_LOCAL_BUFFER(int,tanktag,2); tanktag[0]=mytag; tanktag[1]=mytag+1; int info; MPI_Status stat; - info = MPI_Recv((&d), 1,TRcv, source, tanktag[1] , comm,&stat); - if (info !=MPI_SUCCESS) return info; - return(info); + info = MPI_Recv (&d, 1, TRcv, source, tanktag[1], comm, &stat); + + return info; } -int recv_string( MPI_Comm comm, octave_value &ov,int source, int mytag){ -/*-----------------------------*/ /* it's just a string value */ -std::string cpp_string; -OCTAVE_LOCAL_BUFFER(int, tanktag, 2); -tanktag[0]=mytag; -tanktag[1]=mytag+1; -tanktag[2]=mytag+2; +int recv_string (MPI_Comm comm, octave_value &ov, int source, int mytag) +{ + /*---------------------------*/ + /* it's just a string value */ + std::string cpp_string; + OCTAVE_LOCAL_BUFFER(int, tanktag, 2); + tanktag[0]=mytag; + tanktag[1]=mytag+1; + tanktag[2]=mytag+2; + int info,nitem; MPI_Status stat; - info = MPI_Recv((&nitem), 1,MPI_INT, source, tanktag[1] , comm,&stat); -// printf("I have received number of elements %i \n",nitem); + info = MPI_Recv ((&nitem), 1, MPI_INT, source, tanktag[1], comm, &stat); OCTAVE_LOCAL_BUFFER(char,mess,nitem+1); - if (info !=MPI_SUCCESS) return info; + if (info != MPI_SUCCESS) + return info; MPI_Datatype fortvec; - MPI_Type_contiguous(nitem+1,MPI_CHAR, &fortvec); - MPI_Type_commit(&fortvec); + MPI_Type_contiguous (nitem + 1, MPI_CHAR, &fortvec); + MPI_Type_commit (&fortvec); - - info = MPI_Recv(mess, 1,fortvec, source, tanktag[2] , comm,&stat); -// printf("Flag for string received %i \n",info); - - cpp_string = mess; - ov = cpp_string; - if (info !=MPI_SUCCESS) return info; - return(MPI_SUCCESS); + info = MPI_Recv (mess, 1, fortvec, source, tanktag[2], comm, &stat); + if (info != MPI_SUCCESS) + return info; + + cpp_string = mess; + ov = cpp_string; + + return info; } -int recv_matrix( bool is_complex,MPI_Datatype TRCV,const MPI_Comm comm, octave_value &ov, int source, int mytag){ +int recv_matrix (bool is_complex, MPI_Datatype TRCV, const MPI_Comm comm, octave_value &ov, int source, int mytag) +{ -OCTAVE_LOCAL_BUFFER(int, tanktag, 6); -tanktag[0] = mytag; -tanktag[1] = mytag+1; -tanktag[2] = mytag+2; -tanktag[3] = mytag+3; -tanktag[4] = mytag+4; -tanktag[5] = mytag+5; + OCTAVE_LOCAL_BUFFER(int, tanktag, 6); + tanktag[0] = mytag; + tanktag[1] = mytag+1; + tanktag[2] = mytag+2; + tanktag[3] = mytag+3; + tanktag[4] = mytag+4; + tanktag[5] = mytag+5; int info; int nitem,nd; MPI_Status stat; dim_vector dv; - info = MPI_Recv((&nitem), 1,MPI_INT, source, tanktag[1] , comm,&stat); -// printf("info for nitem=%i\n",info); -// printf("nitem=%i\n",nitem); - if (info !=MPI_SUCCESS) return info; - info = MPI_Recv((&nd), 1,MPI_INT, source, tanktag[2] , comm,&stat); -// printf("info for nd=%i\n",info); -// printf("nd=%i\n",nd); - if (info !=MPI_SUCCESS) return info; + info = MPI_Recv ((&nitem), 1, MPI_INT, source, tanktag[1], comm, &stat); + if (info != MPI_SUCCESS) + return info; + + info = MPI_Recv (&nd, 1, MPI_INT, source, tanktag[2], comm, &stat); + if (info != MPI_SUCCESS) + return info; -// Now create contiguous datatype for dim vector - dv.resize(nd); + // Now create contiguous datatype for dim vector + dv.resize (nd); OCTAVE_LOCAL_BUFFER(int,dimV,nd); MPI_Datatype dimvec; - MPI_Type_contiguous(nd,MPI_INT, &dimvec); - MPI_Type_commit(&dimvec); + MPI_Type_contiguous (nd, MPI_INT, &dimvec); + MPI_Type_commit (&dimvec); - info = MPI_Recv((dimV), 1,dimvec, source, tanktag[3] , comm,&stat); -// printf("info for dim vector=%i\n",info); - if (info !=MPI_SUCCESS) return info; + info = MPI_Recv (dimV, 1, dimvec, source, tanktag[3], comm, &stat); + if (info != MPI_SUCCESS) + return info; -// Now reverse the content of int vector into dim vector - for (octave_idx_type i=0; i<nd; i++) - { - dv(i) = dimV[i] ; - } - if (TRCV == MPI_DOUBLE and is_complex == false ) - { - NDArray myNDA(dv); - OCTAVE_LOCAL_BUFFER(double, LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - - else if (TRCV == MPI_DOUBLE and is_complex== true ) - { - OCTAVE_LOCAL_BUFFER(double,LBNDA1,nitem); - info = recv_vec(comm, LBNDA1,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - ComplexNDArray myNDA(dv); - OCTAVE_LOCAL_BUFFER(double,LBNDA2,nitem); - info = recv_vec(comm, LBNDA2,nitem ,TRCV ,source, tanktag[5]); - if (info !=MPI_SUCCESS) return info; - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=real(LBNDA1[i])+imag(LBNDA2[i]); - } - ov=myNDA; - } - else if (TRCV == MPI_INT) - { - OCTAVE_LOCAL_BUFFER(bool,LBNDA,nitem);// tested on Octave 3.2.4 - TRCV = MPI_INT; - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - int32NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - else if (TRCV == MPI_FLOAT) - { - OCTAVE_LOCAL_BUFFER(float,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - FloatNDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - else if (TRCV == MPI_FLOAT and is_complex == true) - { - OCTAVE_LOCAL_BUFFER(float,LBNDA1,nitem); - info = recv_vec(comm, LBNDA1,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - OCTAVE_LOCAL_BUFFER(float,LBNDA2,nitem); - info = recv_vec(comm, LBNDA2,nitem ,TRCV ,source, tanktag[5]); - if (info !=MPI_SUCCESS) return info; - FloatComplexNDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=real(LBNDA1[i])+imag(LBNDA2[i]); - } - ov=myNDA; - } - else if (TRCV == MPI_BYTE ) - { - OCTAVE_LOCAL_BUFFER(octave_int8,LBNDA1,nitem); - info = recv_vec(comm, LBNDA1,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - int8NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA1[i]; - } - ov=myNDA; - } - else if (TRCV == MPI_SHORT) - { - OCTAVE_LOCAL_BUFFER(octave_int16,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - int16NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - - else if (TRCV == MPI_LONG_LONG) - { - OCTAVE_LOCAL_BUFFER(octave_int64,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - int64NDArray myNDA(dv); - if (info !=MPI_SUCCESS) return info; - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - else if (TRCV == MPI_UNSIGNED_CHAR) - { - OCTAVE_LOCAL_BUFFER(octave_uint8,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - uint8NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - else if (TRCV == MPI_UNSIGNED_SHORT) - { - OCTAVE_LOCAL_BUFFER(octave_uint16,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - uint16NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } - else if (TRCV == MPI_UNSIGNED) { - OCTAVE_LOCAL_BUFFER(octave_uint32,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - uint32NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov = myNDA; - } - else if (TRCV == MPI_UNSIGNED_LONG_LONG) - { - OCTAVE_LOCAL_BUFFER(octave_uint64,LBNDA,nitem); - info = recv_vec(comm, LBNDA,nitem ,TRCV ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - uint64NDArray myNDA(dv); - for (octave_idx_type i=0; i<nitem; i++) - { - myNDA(i)=LBNDA[i]; - } - ov=myNDA; - } -return(info); + // Now reverse the content of int vector into dim vector + for (octave_idx_type i = 0; i < nd; i++) + dv(i) = dimV[i] ; + + if (is_complex) + { + // FIXME : it should be easy to avoid the extra memory allocation and copying +#define __MAKE_CMPLX_TYPE_BRANCH__(TMPI,T1,A1) \ + if (TRCV == TMPI) \ + { \ + OCTAVE_LOCAL_BUFFER(T1,LBNDA1,nitem); \ + info = recv_vec (comm, LBNDA1, nitem, TRCV, \ + source, tanktag[4]); \ + if (info != MPI_SUCCESS) \ + return info; \ + A1 myNDA (dv); \ + OCTAVE_LOCAL_BUFFER(T1,LBNDA2,nitem); \ + info = recv_vec (comm, LBNDA2, nitem, TRCV, \ + source, tanktag[5]); \ + if (info != MPI_SUCCESS) \ + return info; \ + for (octave_idx_type i = 0; i < nitem; i++) \ + myNDA(i) = real (LBNDA1[i]) + imag (LBNDA2[i]); \ + \ + ov=myNDA; \ + } + + __MAKE_CMPLX_TYPE_BRANCH__(MPI_DOUBLE,double,ComplexNDArray) + else __MAKE_CMPLX_TYPE_BRANCH__(MPI_FLOAT,float,FloatComplexNDArray) +#undef __MAKE_CMPLX_TYPE_BRANCH__ + } + else + { + // FIXME : it should be easy to avoid the extra memory allocation and copying +#define __MAKE_TYPE_BRANCH__(TMPI,T1,A1) \ + if (TRCV == TMPI) \ + { \ + A1 myNDA (dv); \ + OCTAVE_LOCAL_BUFFER(T1, LBNDA,nitem); \ + info = recv_vec(comm, LBNDA, nitem, TRCV, \ + source, tanktag[4]); \ + if (info != MPI_SUCCESS) \ + return info; \ + \ + for (octave_idx_type i=0; i<nitem; i++) \ + myNDA(i) = LBNDA[i]; \ + ov=myNDA; \ + } + + __MAKE_TYPE_BRANCH__(MPI_DOUBLE,double,NDArray) + else __MAKE_TYPE_BRANCH__(MPI_INT,bool,boolNDArray) + else __MAKE_TYPE_BRANCH__(MPI_FLOAT,float,FloatNDArray) + else __MAKE_TYPE_BRANCH__(MPI_BYTE,octave_int8,int8NDArray) + else __MAKE_TYPE_BRANCH__(MPI_SHORT,octave_int16,int16NDArray) + else __MAKE_TYPE_BRANCH__(MPI_INT,octave_int32,int32NDArray) + else __MAKE_TYPE_BRANCH__(MPI_LONG_LONG,octave_int64,int64NDArray) + else __MAKE_TYPE_BRANCH__(MPI_UNSIGNED_CHAR,octave_uint8,uint8NDArray) + else __MAKE_TYPE_BRANCH__(MPI_UNSIGNED_SHORT,octave_uint16,uint16NDArray) + else __MAKE_TYPE_BRANCH__(MPI_UNSIGNED,octave_uint32,uint32NDArray) + else __MAKE_TYPE_BRANCH__(MPI_UNSIGNED_LONG_LONG,octave_uint64,uint64NDArray) + +#undef __MAKE_TYPE_BRANCH__ + } + + return info; } -int recv_sp_mat(bool is_complex,MPI_Datatype TRcv, MPI_Comm comm, octave_value &ov,int source, int mytag){ -int info; +int recv_sp_mat (bool is_complex, MPI_Datatype TRcv, MPI_Comm comm, octave_value &ov, int source, int mytag) +{ + int info; -OCTAVE_LOCAL_BUFFER(int, tanktag,6); -tanktag[0] = mytag; -tanktag[1] = mytag+1; -tanktag[2] = mytag+2; -tanktag[3] = mytag+3; -tanktag[4] = mytag+4; -tanktag[5] = mytag+5; + OCTAVE_LOCAL_BUFFER(int, tanktag,6); + tanktag[0] = mytag; + tanktag[1] = mytag+1; + tanktag[2] = mytag+2; + tanktag[3] = mytag+3; + tanktag[4] = mytag+4; + tanktag[5] = mytag+5; -MPI_Status stat; + MPI_Status stat; -OCTAVE_LOCAL_BUFFER(int,s,3); + OCTAVE_LOCAL_BUFFER(int,s,3); + + // Create a contiguous derived datatype + MPI_Datatype sintsparse; + MPI_Type_contiguous (3, MPI_INT, &sintsparse); + MPI_Type_commit (&sintsparse); -// Create a contiguous derived datatype -MPI_Datatype sintsparse; -MPI_Type_contiguous(3,MPI_INT, &sintsparse); -MPI_Type_commit(&sintsparse); + // receive the sintsparse vector named s + info = MPI_Recv (s, 1, sintsparse, source, tanktag[1], comm, &stat); + if (info != MPI_SUCCESS) + return info; + // Create a contiguous derived datatype for row and column index + OCTAVE_LOCAL_BUFFER(int,sridx,s[2]); + MPI_Datatype rowindex; + MPI_Type_contiguous (s[2], MPI_INT, &rowindex); + MPI_Type_commit (&rowindex); + OCTAVE_LOCAL_BUFFER(int,scidx,s[1]+1); + MPI_Datatype columnindex; + MPI_Type_contiguous (s[1] + 1, MPI_INT, &columnindex); + MPI_Type_commit (&columnindex); -// receive the sintsparse vector named s -info = MPI_Recv(s, 1, sintsparse, source, tanktag[1], comm, &stat); -// printf("This is info for sintsparse %i\n",info); -if (info !=MPI_SUCCESS) return info; -// MPI_Datatype datavect1; -// MPI_Type_contiguous(s[2],TRcv, &datavect1); -// MPI_Type_commit(&datavect1); -// printf("This is info for sintsparse %i\n"); -// Create a contiguous derived datatype for row and column index - -OCTAVE_LOCAL_BUFFER(int,sridx,s[2]); -MPI_Datatype rowindex; -MPI_Type_contiguous(s[2],MPI_INT, &rowindex); -MPI_Type_commit(&rowindex); + info = MPI_Recv (sridx, 1, rowindex, source, tanktag[2], comm, &stat); -OCTAVE_LOCAL_BUFFER(int,scidx,s[1]+1); -MPI_Datatype columnindex; -MPI_Type_contiguous(s[1]+1,MPI_INT, &columnindex); -MPI_Type_commit(&columnindex); + if (info != MPI_SUCCESS) + return info; + // receive the vector with column indexes + info = MPI_Recv (scidx, 1, columnindex, source, tanktag[3], comm, &stat); - info = MPI_Recv(sridx,1,rowindex,source,tanktag[2],comm,&stat); -// printf("Hope everything is fine here with ridx %i =\n",info); - if (info !=MPI_SUCCESS) return info; + if (info != MPI_SUCCESS) + return info; -// receive the vector with column indexes - info = MPI_Recv(scidx,1,columnindex,source,tanktag[3],comm, &stat); -// printf("Hope everything is fine here with scidx %i =\n",info); - if (info !=MPI_SUCCESS) return info; + // Now we have a different vector of non zero elements according to datatype +#define __MAKE_TYPE_BRANCH__(TMPI,T1,A1) \ + if (TRcv == TMPI) \ + { \ + A1 m (s[0], s[1], s[2]); \ + OCTAVE_LOCAL_BUFFER(T1,LBNDA,s[2]); \ + info = recv_vec (comm, LBNDA,s[2] ,TRcv ,source, tanktag[4]); \ + if (info != MPI_SUCCESS) \ + return info; \ + for (octave_idx_type i = 0; i < s[1]+1; i++) \ + m.cidx(i) = scidx[i]; \ + for (octave_idx_type i = 0; i < s[2]; i++) \ + { \ + m.ridx(i) = sridx[i]; \ + m.data(i) = LBNDA[i]; \ + } \ + ov = m; \ + } -// Now we have a different vector of non zero elements according to datatype + if (is_complex) + { + if (TRcv == MPI_DOUBLE) + { + TRcv = MPI_DOUBLE; + SparseComplexMatrix m (s[0], s[1], s[2]); + OCTAVE_LOCAL_BUFFER(double,LBNDA1,s[2]); + OCTAVE_LOCAL_BUFFER(double,LBNDA2,s[2]); - if (TRcv == MPI_INT) - { - SparseBoolMatrix m(s[0],s[1],s[2]); - OCTAVE_LOCAL_BUFFER(bool,LBNDA,s[2]); - //Now receive the vector of non zero elements - info = recv_vec(comm, LBNDA,s[2] ,TRcv ,source, tanktag[4]); -// printf("This is info for vector of non zero elements %i\n",info); - if (info !=MPI_SUCCESS) return info; - for (octave_idx_type i = 0; i < s[1]+1; i++) - { - m.cidx(i) = scidx[i]; - } - for (octave_idx_type i = 0; i < s[2]; i++) - { - m.ridx(i) = sridx[i]; -// printf("LBNDA[i]= %f\n",LBNDA[i]); - m.data(i) = LBNDA[i]; - } - ov = m; - } - if (TRcv == MPI_DOUBLE and is_complex==false) - { - SparseMatrix m(s[0],s[1],s[2]); - OCTAVE_LOCAL_BUFFER(double,LBNDA,s[2]); - //Now receive the vector of non zero elements - info = recv_vec(comm, LBNDA,s[2] ,TRcv ,source, tanktag[4]); -// printf("This is info for receiving vector of non zero elements %i\n",info); - if (info !=MPI_SUCCESS) return info; - for (octave_idx_type i = 0; i < s[1]+1; i++) - { - m.cidx(i) = scidx[i]; - } - for (octave_idx_type i = 0; i < s[2]; i++) - { - m.ridx(i) = sridx[i]; -// printf("LBNDA[i]= %f\n",LBNDA[i]); - m.data(i) = LBNDA[i]; - } - ov = m; - } - if (TRcv == MPI_DOUBLE and is_complex==true) - { - TRcv = MPI_DOUBLE; - SparseComplexMatrix m(s[0],s[1],s[2]); - OCTAVE_LOCAL_BUFFER(double,LBNDA1,s[2]); - OCTAVE_LOCAL_BUFFER(double,LBNDA2,s[2]); - info = recv_vec(comm, LBNDA1,s[2] ,TRcv ,source, tanktag[4]); - if (info !=MPI_SUCCESS) return info; - info = recv_vec(comm, LBNDA2,s[2] ,TRcv ,source, tanktag[5]); - if (info !=MPI_SUCCESS) return info; - for (octave_idx_type i = 0; i < s[1]+1; i++) - { - m.cidx(i) = scidx[i]; - } - for (octave_idx_type i = 0; i < s[2]; i++) - { - m.ridx(i) = sridx[i]; - m.data(i) = real(LBNDA1[i])+imag(LBNDA2[i]); - } - ov = m; + info = recv_vec (comm, LBNDA1, s[2], TRcv, source, tanktag[4]); + if (info != MPI_SUCCESS) + return info; - } -return(info); + info = recv_vec (comm, LBNDA2, s[2], TRcv, source, tanktag[5]); + if (info != MPI_SUCCESS) + return info; + + for (octave_idx_type i = 0; i < s[1] + 1; i++) + m.cidx(i) = scidx[i]; + + for (octave_idx_type i = 0; i < s[2]; i++) + { + m.ridx(i) = sridx[i]; + m.data(i) = real(LBNDA1[i])+imag(LBNDA2[i]); + } + + ov = m; + } + } + else + { + __MAKE_TYPE_BRANCH__(MPI_INT,bool,SparseBoolMatrix) + else __MAKE_TYPE_BRANCH__(MPI_DOUBLE,double,SparseMatrix) + } +#undef __MAKE_TYPE_BRANCH__ + return info; } -int recv_cell(MPI_Comm comm,octave_value &ov, int source, int mytag){ -// Not tested yet -OCTAVE_LOCAL_BUFFER(int, tanktag, 5); -tanktag[0] = mytag; -tanktag[1] = mytag+1; -tanktag[2] = mytag+2; -tanktag[3] = mytag+3; -tanktag[4] = mytag+4; +int recv_cell (MPI_Comm comm, octave_value &ov, int source, int mytag) +{ + + OCTAVE_LOCAL_BUFFER(int, tanktag, 5); + tanktag[0] = mytag; + tanktag[1] = mytag+1; + tanktag[2] = mytag+2; + tanktag[3] = mytag+3; + tanktag[4] = mytag+4; + int ... [truncated message content] |