MPI_Scatter structuire's field

This is a discussion on MPI_Scatter structuire's field within the C Programming forums, part of the General Programming Boards category; Hello, I would welcome some help in the code below. I would like to Scatter from the node 0,the genes' ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    79

    MPI_Scatter structuire's field

    Hello,

    I would welcome some help in the code below. I would like to Scatter from the node 0,the genes' field in different nodes in a chunk of 2.


    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <mpi.h>
    #include <math.h>
    #include <time.h>
    #include <limits.h>
    #include "mylib.h"
    
    #define NUM_OF_GENERATIONS 10000
    #define NUM_OF_GENES 3
    #define NUM_OF_CHROMES 5
    #define NUM_OF_FORCES 3
    
    struct chromosome{
     double fitness;
     double genes[NUM_OF_GENES];
     double up_limit[NUM_OF_GENES];
     double low_limit[NUM_OF_GENES];
    };
    struct chromosome  old_chrome[NUM_OF_CHROMES], new_chrome[NUM_OF_CHROMES], temp_chrome[NUM_OF_CHROMES];
    
    
     double forces[NUM_OF_FORCES];
     double matrix[NUM_OF_FORCES][NUM_OF_GENES];
     double matrix_local[NUM_OF_FORCES][NUM_OF_GENES];
     double forces_local[NUM_OF_FORCES];
     int CROSS_CHROME[NUM_OF_CHROMES];
    
    
    int main(int argc, char* argv[]) 
    
    {
    
      int size,rank,i,j,n;
    
    int blockCounts[4] = {1,NUM_OF_GENES,NUM_OF_GENES,NUM_OF_GENES};
    MPI_Datatype types[4];
    MPI_Aint displace[4];
    MPI_Datatype myStructType;
    int base;
    
     srand48(time(NULL));
    
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    MPI_Comm_size(MPI_COMM_WORLD, &size);
    
    
    
    MPI_Address(old_chrome,displace);
    MPI_Address(old_chrome[0].genes,displace+1 );
    MPI_Address(old_chrome[0].up_limit, displace+2);
    MPI_Address(old_chrome[0].low_limit, displace+3);
    
    types[0] = MPI_DOUBLE;
    types[1] = MPI_DOUBLE;
    types[2] = MPI_DOUBLE;
    types[3] = MPI_DOUBLE;
     
    base = displace[0];
    for(i=0; i<4; i++)
     {
      displace[i] -= base;
     }
    
    
    MPI_Type_struct(4, blockCounts, displace, types, &myStructType);
    MPI_Type_commit(&myStructType);
    
    if(rank == 0) 
     {
       for(i=0;i<4;i++)
         {
         for(j=0;j<2;j++)
         {
           old_chrome[i].genes[j]=drand48();
         }
         }
     }
    
     for(i=0;i<NUM_OF_CHROMES;i++)
        {  
          printf("%d old_chrome[%d].genes[0]= %lf\n",rank,i, old_chrome[i].genes[0]);
        }
    
     MPI_Barrier(MPI_COMM_WORLD);
    
     for(i=0;i<NUM_OF_CHROMES;i++)
       {
     
         MPI_Scatter(&old_chrome[0].genes[0],2,myStructType,&temp_chrome[0].genes[0],2,myStructType,0,MPI_COMM_WORLD);
      
       }
    MPI_Barrier(MPI_COMM_WORLD);
    
     for(i=0;i<NUM_OF_CHROMES;i++)
       {  for(j=0;j<2;j++)
           {
    	 printf("\n%d temp_chrome[%d].genes[%d] = %lf\n",rank,i,j, temp_chrome[i].genes[j]);
           }
       }
     MPI_Finalize();
    }

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    I recall you asking a similar question about a week ago, and it gathered no response. I think it's because you're asking for help on a library that we just aren't familiar with.

    You might try asking in the MPI Forum Mailing Lists. Check the archives to see if the list you're planning to ask to is still active --- mpi-22, for example, has seen activity this month whereas mpi-21 has been dead for well over a year (probably because it's for an old version?).
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    79
    thanks for the answer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for a little assistance with item class design...
    By Raigne in forum Game Programming
    Replies: 5
    Last Post: 10-22-2008, 09:55 AM
  2. Please critique and suggest improvements for parser
    By Queue in forum C Programming
    Replies: 14
    Last Post: 09-28-2006, 09:28 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  4. How can I parse data from a file
    By figo2476 in forum C Programming
    Replies: 5
    Last Post: 08-19-2005, 09:07 AM
  5. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 03:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21