My apologies, I think I wasn't clear on my question. My question was, given
that copying of data is necessary in both approaches (either by the system
with arrays or by programmer with buffers), is there a foreseeable
performance difference in terms of performance considering the time it
takes for copying?

Thank you,
Saliya


On Fri, Aug 22, 2014 at 3:24 PM, Oscar Vega-Gisbert <ov...@dsic.upv.es>
wrote:

> El 22/08/14 20:44, Saliya Ekanayake escribió:
>
>  Thank you Oscar for the detailed information, but I'm still wondering how
>> would the copying in 2 would be different than what's done here with
>> copying to a buffer.
>>
>
> If you have a buffer array like this:
>
>     double buffer[] = new double[m * n];
>
> Copy the 2D matrix to the buffer:
>
>
>     for(int i = 0; i < m; i++)
>         System.arraycopy(matrix[i], 0, buffer, i * n, n);
>
> Copy from the buffer to the 2D matrix:
>
>
>     for(int i = 0; i < m; i++)
>         System.arraycopy(buffer, i * n, matrix[i], 0, n);
>
>
>> On Fri, Aug 22, 2014 at 2:17 PM, Oscar Vega-Gisbert <ov...@dsic.upv.es
>> <mailto:ov...@dsic.upv.es>> wrote:
>>
>>     El 22/08/14 17:10, Saliya Ekanayake escribió:
>>
>>         Hi,
>>
>>         I've a quick question about the usage of Java binding.
>>
>>         Say there's a 2 dimensional double array (size m x n) that
>>         needs to be sent to another rank. I see two options to get
>>         this done,
>>
>>         1. Copy values to a direct buffer of size m*n and send it
>>         2. Copy values to a 1D array of size m*n and send it
>>
>>         I guess 2 would internally do the copying to a buffer and use
>>         it, so suggesting 1. is the best option. Is this the case or
>>         is there a better way to do this?
>>
>>
>>     The best option is 1 because 2 requires one extra copy to C heap.
>>     Supposing the matrix is the following:
>>
>>         double matrix[][] = new double[m][n];
>>
>>     Then you can allocate a direct DoubleBuffer:
>>
>>         DoubleBuffer buffer = MPI.newDoubleBuffer(m * n);
>>
>>     In order to send/receive the matrix I suggest to use the bulk
>>     put/get methods:
>>
>>         for(int i = 0; i < m; i++)
>>             buffer.put(matrix[i]); // Copy to the buffer.
>>
>>         MPI.COMM_WORLD.send(buffer, m*n, MPI.DOUBLE, 1, 0);
>>
>>     The receive code:
>>
>>         MPI.COMM_WORLD.recv(buffer, m*n, MPI.DOUBLE, 0, 0);
>>
>>         for(int i = 0; i < m; i++)
>>             buffer.get(matrix[i]); // Copy from the buffer.
>>
>>     Note that bulk get/put methods increment the buffer position in n.
>>     So if you want reuse the buffer you must set the buffer position
>>     to 0 before copy the matrix:
>>
>>         buffer.position(0);
>>
>>     Regards,
>>     Oscar
>>
>>
>>         Thank you,
>>         Saliya
>>         --         Saliya Ekanayake esal...@gmail.com <mailto:
>> esal...@gmail.com>
>>         <mailto:esal...@gmail.com <mailto:esal...@gmail.com>>
>>
>>         http://saliya.org
>>
>>
>>         _______________________________________________
>>         users mailing list
>>         us...@open-mpi.org <mailto:us...@open-mpi.org>
>>
>>         Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
>>         Link to this post:
>>         http://www.open-mpi.org/community/lists/users/2014/08/25130.php
>>
>>
>>     _______________________________________________
>>     users mailing list
>>     us...@open-mpi.org <mailto:us...@open-mpi.org>
>>
>>     Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
>>     Link to this post:
>>     http://www.open-mpi.org/community/lists/users/2014/08/25131.php
>>
>>
>>
>>
>> --
>> Saliya Ekanayake esal...@gmail.com <mailto:esal...@gmail.com>
>>
>> Cell 812-391-4914 Home 812-961-6383
>> http://saliya.org
>>
>>
>> _______________________________________________
>> users mailing list
>> us...@open-mpi.org
>> Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
>> Link to this post: http://www.open-mpi.org/community/lists/users/2014/08/
>> 25132.php
>>
>
> _______________________________________________
> users mailing list
> us...@open-mpi.org
> Subscription: http://www.open-mpi.org/mailman/listinfo.cgi/users
> Link to this post: http://www.open-mpi.org/community/lists/users/2014/08/
> 25133.php
>



-- 
Saliya Ekanayake esal...@gmail.com
Cell 812-391-4914 Home 812-961-6383
http://saliya.org

Reply via email to