Luca Salucci <lucasalu...@libero.it> wrote on 03/03/2014 12:01:39 PM:
>
> Hello! I am trying to exploit some existing C code but the
> documentation I found for the external C code invocation does not
> solve some doubts I have. Here is the library I would like to use
> http://math.nist.gov/MatrixMarket/mmio-c.html#mm_read_mtx_crd_size;
> as you can see from the following function signatures I have to deal
> also with int* and int[]
>
> int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J
[],
> double val[], MM_typecode matcode);
> int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
> double val[], MM_typecode matcode);
> int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double
*img,
> MM_typecode matcode);
>
> int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int
*nz_,
> double **val_, int **I_, int **J_);
> I was wondering what should I pass to this functions within X10 in
> order to make them work? Are X10 Rail[Int] interoperable with int[]?
> I know the library is not that big or complex and I could rewrite it
> in X10, but I would like to save time and to experiment the
> interoperability with existing C/C++ code.
> Thanks,
Hi,
(1) Interop between X10's Rail[T] and a C T[].
An X10 Rail is a single C++ object containing the C++ vtbl, followed
by the size, followed by the raw data (a C T[] "off the end" of the
struct). If r is a Rail[int], then the C++ code you need to get access to
the int[] is r->raw(). The general way to do this is via an @Native
annotation, for example:
@Native("c++", "foo(#A->raw(), x, y)")
native def foo(A:Rail[int], x:min, y:min)
You can use a @NativeCPPInclude and/or @NativeCPPCompilationUnit
annotations on the enclosing class to add C files to the
include/compilation commands. For an example, see FT.x10 in
http://svn.code.sf.net/p/x10/code/benchmarks/trunk/PERCS/FT
A more stylized way to do this is to use the @NativeCPPExtern
annotation (for an example, see LU.x10 in
http://svn.code.sf.net/p/x10/code/benchmarks/trunk/PERCS/LU). Here the
compiler automatically generates the ->raw() for you based on the type of
the parameter; you don't have to write the detailed @Native annotation.
(2) mm_read_mtx_crd_entry wants a FILE*. It's friend
mm_read_unsymmetric_sparse is using pointers to get out parameters.
You can probably get both of these to work with very careful use of
@Native annotations (inside of @Native annotation inject fragments of C++
code to access a backing FILE* from an x10.io.FileReader; inject an & to
take the address of a local variable being passed as a parameter).
However this might be fragile. I would think about perhaps writing a
combined piece of C++/X10 code to provide a higher-level API to the matrix
input/output function and not try to cross back & forth at the lower-level
API that needs to deal with FILE* and returning multiple values via out
parameters.
hope this helps,
--dave
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users