LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Karlos Bohan (kartle_at_[hidden])
Date: 2005-02-18 06:59:04


Hello,

I'm a final year student trying currently working on my thesis in
which I'm attempting to implement a global optimization algorithm in
parallel.

I'm new to LAM and parallel programming in general.

I'm attempting to define a struct in C which will be passed to the
different processors on the cluster I'm implementing it on.

The stuct has three elements,

1. A multidimensional Array of type double, which holds the current
population of solution vectors
2. A vector array of type double which holds the best current vector
3. A double which holds the result of the target function on the best
current vector

When I started out I was using the source code for a general
Master/Slave skeleton at:

http://www.lam-mpi.org/tutorials/one-step/ezstart.php

I originally attempted to fit the code for my algorthim into this
skeleton, however this proved extremely difficult to compile and debug
and so I've now reverted to building up my own version from scratch
with the idea of having as few compile errors as I go, and building up
the program eliminating them as I go.

I've already run into problems defining the MPI_Datatype which I'll
need to pass, this is before I can even start to actually use it!!

The code for defining it is as follows and is based on section 5.6
"Using MPI Derived Types for User-Defined Types" of the NCSA tutorial
reccomended on the LAM/MPI site

The Code I have is as follows for the user defined struct Kstruct:

//Kstruct definition:
struct kstruct{
        double population[MAXPOP][MAXDIM];
        double bestPopVector[MAXDIM];
        double bestCostValue;
};

typedef struct kstruct Kstruct;

//This is the code then running in Main()

Kstruct masterKstruct; /* a representative variable of this type */
   int lena[3]; /* the three arrays used to describe an MPI derived type */
   MPI_Aint loca[3]; /* their size reflects the number of
components in SparseElt */
   MPI_Datatype typa[3];

   MPI_Aint baseaddress;
   MPI_Datatype MPI_Kstruct; /* a variable to hold the MPI type
indicator for SparseElt */
   /* set up the MPI description of SparseElt */
   MPI_Address(&masterKstruct, &baseaddress);
   lena[0] = 3; MPI_Address(&masterKstruct.population,&loca[0]);
   loca[0] -= baseaddress; typa[0] = MPI_DOUBLE;
   lena[1] = 2; MPI_Address(&masterKstruct.bestPopVector,&loca[1]);
   loca[1] -= baseaddress; typa[1] = MPI_DOUBLE;
   lena[2] = 1; MPI_Address(&masterKstruct.bestCostValue ,&loca[2]);
   loca[2] -= baseaddress; typa[2] = MPI_DOUBLE;

   MPI_Type_struct(3, lena, loca, typa, &MPI_Kstruct);
   MPI_Type_commit(&MPI_Kstruct);

  MPI_Status status;

  MPI_Init(&argc, &argv);
  MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
  MPI_Comm_rank(MPI_COMM_WORLD,&myid);

....

When I try to compile this program I get the following error:

mpitest2.c:234: parse error before `status'

Could anyone tell me where I'm going wrong with this?

Also, assuming I can get this working, would it be fair to say that
comparison operations on the struct once its defined as an MPI type
will be relatively straight forward as all I'll be doing then is
comparison functions?

Many thanks
k