On Feb 1, 2005, at 12:23 PM, Rita Zrour wrote:
> 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?????
>
>
delete[] operator is used to free memory which is allocated dynamically
on the heap. Since the memory you are trying to free is not allocated
in this fashion, your program is failing. Both recdata and indata are
automatic variables allocated on the stack. Hence,
delete[] (recdata.c) is incorrect.
Please refer to the man pages on new() and delete() operators for more
information. We also suggest that you post only LAM/MPI specific
questions on this list. For details on how to post questions, please
refer to
http://www.lam-mpi.org/using/support/
Anju
> #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
>
>
> _______________________________________________
> This list is archived at http://www.lam-mpi.org/MailArchives/lam/
|