Ibrahim,

if you want to send the full array, then please replace
        MPI.COMM_WORLD.send(m1, 1, MPI.INT, 1, tag);
with
        MPI.COMM_WORLD.send(m1, m1.length, MPI.INT, 1, tag);

and do similar changes in recv

Cheers,

Gilles

On 11/5/2015 2:57 AM, Ibrahim Ikhlawi wrote:


Hello,

I want to send an array from process to another one. I send the array but I get only the first element of the array.
This is a section from my code:

int[] m1= new int[5];
if (0 == myrank) {
        for(int i= 0; i<m1.length ; i++){
            m1[i] = 100;
        System.out.println("m1["+i+"]"+m1[i]);
        }
        MPI.COMM_WORLD.send(m1, 1, MPI.INT, 1, tag);

    }else{
        MPI.COMM_WORLD.recv(m1 , 1 , MPI.INT , 0 ,tag);
        for(int i= 0; i<m1.length ; i++){
            m2[i] = 3*m1[i];
        System.out.println("m1["+i+"]"+m1[i]+" m2["+i+"]"+m2[i]);
        }
        MPI.COMM_WORLD.send(m2, 1 , MPI.INT, 0, tag);

    }

    if(0 == myrank){
        MPI.COMM_WORLD.recv(m2, 1 , MPI.INT, 1 ,tag);
        System.out.println(Arrays.toString(m2));
    }

the result of this program is:
m1[0]100
m1[1]100
m1[2]100
m1[3]100
m1[4]100
[300, 0, 0, 0, 0]
m1[0]100  m2[0]300
m1[1]0  m2[1]0
m1[2]0  m2[2]0
m1[3]0  m2[3]0
m1[4]0  m2[4]0


Thanks in advance


_______________________________________________
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/2015/11/27991.php

Reply via email to