Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Adding elements into a set of array lists

    Hi i wonder if there's a more efficient way to do this in java MPI:
    Code:
    public void receiveBlock(int nproc){
    
      int[][] blockData = new int[block_size][numCols];
      MPI.COMM_WORLD.Recv(blockData, 0, block_size, MPI.Int, 0, 99);
    
      ArrayList a = new ArrayList();
      ArrayList b = new ArrayList();
      ArrayList c = new ArrayList();
    
      for (int i=0; i< block_size; i++){
    
        int id = blockData[i][0];
        int nodeID = id % nproc;
    
        if (nodeID == 0)
          a.add(blockData[i]);
        else if (nodeID == 1)
          b.add(blockData[i]);
        else
          c.add(blockData[i]);
      }
    
      
    int[][] arrayA = new int[a.size()][numCols];
    arrayA = a.toArray();
    int[][] arrayB = new int[b.size()][numCols];
    arrayB = b.toArray();
    int[][] arrayC = new int[c.size()][numCols];
    arrayC = c.toArray();
    
      // ...
    
    }
    basically, i have to hash the id field from an array and put those rows with the same hashed value into the same array. but i can't use arrays to do this as i can't determine how many rows each array will have before the hashing is complete. so i'm using arraylists to add the elements and then converting it into arrays. but this code seems so inefficient.
    thanks for any help.

    Edit: Put your code in some [ code ] tags. Try to use them in the future, they help out a lot. Antoniohawk
    Last edited by Antoniohawk; 11-18-2004 at 02:00 AM.

  • #2
    New to the CF scene
    Join Date
    Nov 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Array Lists (continued)

    Sorry, the bottom section of the code should be this:

    int[][] arrayA = new int[a.size()][numCols];
    arrayA = a.toArray();
    int[][] arrayB = new int[b.size()][numCols];
    arrayB = b.toArray();
    int[][] arrayC = new int[c.size()][numCols];
    arrayC = c.toArray();


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •