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.
On Fri, Aug 22, 2014 at 2:17 PM, Oscar Vega-Gisbert <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> >> 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/ >> 25130.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/ > 25131.php > -- Saliya Ekanayake esal...@gmail.com Cell 812-391-4914 Home 812-961-6383 http://saliya.org