LAM/MPI logo

LAM/MPI General User's Mailing List Archives

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

From: Rita Zrour (ritazrour_at_[hidden])
Date: 2005-02-01 12:23:53


I have a problem while running an MPI program
actually when i put the dynamic allocation to the
pointer i'm not allowed to do the free. Even without
the free the program have problem is it because i used
the pointer in the structure?????

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>

#define IO_CRASH
#define DYNAMIC_ARRAY
#define USE_NEW

using namespace std;

#include "mpi.h"
#define NBBLOCKS 3
#define size 1000

typedef struct {
    float a;
    float b;
    int c[size];
  } data;

int main ( int argc, char *argv[])
{
//********************************************************************
MPI::Init(argc,argv);
int i, j, np, me,count,datatag=1,tag=2;
int Array_Of_Blocklength[NBBLOCKS]={1,1,size};

MPI::Status status;
MPI::Aint disparray[NBBLOCKS];
MPI::Datatype
array_of_types[NBBLOCKS]={MPI::FLOAT,MPI::FLOAT,MPI::INT};
MPI::Aint startaddress, address;

data indata,recdata;

MPI::Datatype newtype;

indata.c= new int [size];
recdata.c= new int [size];

  np=MPI::COMM_WORLD.Get_size();
  me=MPI::COMM_WORLD.Get_rank();

fprintf(stderr,"Me is %d\n",me);
printf("%d: %x, %x\n",me,indata.c,recdata.c);

if (me == 0) {
indata.a=100.33;
indata.b=99.5;
 for(i=0;i<size;i++)
        {
        indata.c[i]=i+1;
        //printf("%d ",indata.c[i]);
        }
}

  disparray[0] = 0;
  startaddress=MPI::Get_address(&indata.a);
  address=MPI::Get_address(&indata.b);
  disparray[1] = address-startaddress;
  address=MPI::Get_address(&indata.c);
  disparray[2] = address-startaddress;

newtype=MPI::Datatype::Create_struct(3,Array_Of_Blocklength,disparray,array_of_types);
newtype.Commit();

if (me==0)
{
 printf("%d: %x, %x\n",me,indata.c,recdata.c);
 MPI::COMM_WORLD.Send (&indata, 1, newtype, 1,
datatag);

MPI::COMM_WORLD.Recv(&recdata,1,newtype,1,tag,status);
 printf("%f\t%f\t\n",recdata.a,recdata.b);
}

  else {
  printf("%d: %x, %x\n",me,indata.c,recdata.c);
 
MPI::COMM_WORLD.Recv(&recdata,1,newtype,0,datatag,status);
  MPI::COMM_WORLD.Send (&recdata,1, newtype,0, tag);
  }

delete[] (recdata.c);
delete[] (indata.c);

  MPI::Finalize();
  return 0;
}

                
__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com