On Tue, Nov 24, 2009 at 2:41 PM, Riccardo Corradini <
riccardocorrad...@yahoo.it> wrote:
> Yes, sure.
> I would propose this solution
>
> #include "mpi.h"
> #include <octave/oct.h>
> #include <octave/error.h>
>
> class mpicomm : public octave_base_value
> {
> public:
> // Constructor
> mpicomm (const std::string _name = "")
> : octave_base_value (), name (_name)
> {
> }
>
> void print (std::ostream& os, bool pr_as_read_syntax = false) const
> {
> os << name << std::endl;
> }
> bool is_defined (void) const { return true; }
>
> private:
> const std::string name;
>
> DECLARE_OCTAVE_ALLOCATOR
> DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
> };
>
> DEFINE_OCTAVE_ALLOCATOR (mpicomm);
> DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (mpicomm, "mpicomm", "mpicomm");
>
> static bool mpicomm_type_loaded = false;
>
> DEFUN_DLD(mpicomm, args, ,"")
> {
> if (!mpicomm_type_loaded)
> {
> mpicomm::register_type ();
> mpicomm_type_loaded = true;
> mlock ();
> }
>
> octave_value retval;
> if (args.length () != 1 || !args (0).is_string ())
> {
> error ("mpicomm: first argument must be a string");
> return retval;
> }
> const std::string name = args (0).string_value ();
> if( name == "MPI_COMM_WORLD" )
> {
> MPI_Comm Mine = MPI_COMM_WORLD;
> }
> else if( name == "MPI_COMM_SELF" )
> {
> MPI_Comm Mine = MPI_COMM_SELF;
> }
> else if( name == "MPI_COMM_NULL" )
> {
> MPI_Comm Mine = MPI_COMM_NULL;
> }
> else
> {
> // Error about invalid type
> error ("MPI: not a valid communicator");
> }
>
>
> retval = new mpicomm (name);
>
> return retval;
> }
>
> At least we get rid of raw pointer and abuse of reinterpret cast like here
> #if __ia64__ || __x86_64__ // IA-64 / EM64T/AMD64
> #define OpenMPI_OctPtrTyp octave_uint64
> #define OpenMPI_OctIntFcn uint64_scalar_value
> #define OpenMPI_64BIT 1
> #define OpenMPI_ST_offset 2
>
> #else // #elif __i386__ // IA-32
> #define OpenMPI_OctPtrTyp octave_uint32
> #define OpenMPI_OctIntFcn uint32_scalar_value
> #define OpenMPI_64BIT 0
> #define OpenMPI_ST_offset 1
> #endif
>
> #define OpenMPI_intcast(cptr) OpenMPI_OctPtrTyp (\
> reinterpret_cast <unsigned long> ( cptr ) )
>
>
> #include "mpi.h"
>
>
> #undef MPI_COMM_WORLD
> #define NAME MPI_COMM_WORLD
> DEFUN_DLD ( MPI_COMM_WORLD, args, nargout,
> "MPI_COMM_WORLD Openmpi_ext constant for corresponding communicator
> object\n\
> \n\
> Current value (openmpi-1.3.3) is:\n\
> \n\
> typedef struct ompi_communicator_t *MPI_Comm;\n\
> #define MPI_COMM_WORLD OMPI_PREDEFINED_GLOBAL( MPI_Comm,
> ompi_mpi_comm_world)\n\
> \n\
> SEE ALSO: comms\
> ")
> {
>
> octave_value result;
>
> // var = MPI_COMM_WORLD
> // Definition stolen from mpi.h
> // #define MPI_COMM_WORLD OMPI_PREDEFINED_GLOBAL( MPI_Comm,
> ompi_mpi_comm_world)
>
> result = (OpenMPI_intcast( NAME ) // defined -> expanded
> }
>
> that JWE would definitely rule out.
> We could consider the first as a temporary solution.
> What do you think Jarolaslav?
>
> Respectfully
> Riccardo
>
>
>
Yes, something like that would be nice. I don't think you need to pass the
strings as arguments, functions will do.
There doesn't need to be an extra .oct file per constant, we should use
autoloads. I was up to code it this week, but feel free to start ahead.
--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev