MPI_Bcast problem, bug?

 
Thread Tools Search this Thread
Special Forums UNIX and Linux Applications High Performance Computing MPI_Bcast problem, bug?
# 1  
Old 03-21-2010
MPI_Bcast problem, bug?

Hi, I'm trying to define an MPI_datatype for a structure, then do message passing for this created datatype. However, when I tried to broadcast the initialized data from rank 0, I found that part of the received data at other ranks are not correct. Could you please help me take a look at my code and suggest possible errors I made? Thanks a lot!

-----------
//definition of datatype:
-----------
typedef struct paramtwo {
int exist;
double phi0;
double ap;
double r0;
double rc_low;
double rc;
} PARAMTWO;

PARAMTWO **para2;// global variable

//in main.cpp:
----------
void main(){
......
MPI_Datatype paramtwompi;
define_MPI_Paramtwo(&paramtwompi);

para2= (PARAMTWO **)(malloc(NTYPEMAX*sizeof(PARAMTWO*)));
for(i=0;i<NTYPEMAX;i++){
para2[i]=(PARAMTWO*)(malloc(NTYPEMAX*sizeof(PARAMTWO)));
}

if(myrank==0) initialize_para2(); //initialize para2[][] values at rank 0
MPI_Bcast(&(para2[0][0]), (NTYPEMAX*NTYPEMAX), paramtwompi, 0, MPI_COMM_WORLD);

...... output from all ranks ......

}

int define_MPI_Paramtwo(MPI_Datatype *paramtwompi){
int blocklen[6]={1,1,1,1,1,1};
MPI_Aint disp[6];
MPI_Datatype type[6]={MPI_INT,MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE};
PARAMTWO findsize[2];
MPI_Aint findsize_addr, exist_addr, phi0_addr, dumb_addr, ap_addr, r0_addr, rc_low_addr, rc_addr;

MPI_Get_address(&findsize[0], &findsize_addr);
MPI_Get_address(&(findsize[0]).exist, &exist_addr);
MPI_Get_address(&(findsize[0]).phi0, &phi0_addr);
MPI_Get_address(&(findsize[0]).ap, &ap_addr);
MPI_Get_address(&(findsize[0]).r0, &r0_addr);
MPI_Get_address(&(findsize[0]).rc_low, &rc_low_addr);
MPI_Get_address(&(findsize[0]).rc, &rc_addr);

disp[0]=exist_addr-findsize_addr;
disp[1]=phi0_addr-findsize_addr;
disp[2]=ap_addr-findsize_addr;
disp[3]=r0_addr-findsize_addr;
disp[4]=rc_low_addr-findsize_addr;
disp[5]=rc_addr-findsize_addr;


MPI_Type_create_struct(6, blocklen, disp, type, paramtwompi);
MPI_Type_commit(paramtwompi);

return 1;
}

void initialize_para2(){
for(i=1;i<=3;i++){
for(j=1;j<=3;j++){
para2[i][j].exist= ..;
para2[i][j].phi0 = ..;
... ...
para2[i][j].rc = ..;
}
}
}

==================================
From the output:

rank: 0 phi0,ap,r0,rc_low,rc: 0.075832 1.6752 3.64207 0 5
rank: 0 phi0,ap,r0,rc_low,rc: 0.807371 0.73124 4.49714 0 5.5
rank: 0 phi0,ap,r0,rc_low,rc: 0.974501 1.2846 3.08858 0 4
rank: 0 phi0,ap,r0,rc_low,rc: 0.807371 0.73124 4.49714 0 5.5
rank: 0 phi0,ap,r0,rc_low,rc: 0.066001 2.8757 4.31169 0 5
rank: 0 phi0,ap,r0,rc_low,rc: 0.581624 1.2566 3.25062 0 4
rank: 0 phi0,ap,r0,rc_low,rc: 0.974501 1.2846 3.08858 0 4
rank: 0 phi0,ap,r0,rc_low,rc: 0.581624 1.2566 3.25062 0 4
rank: 0 phi0,ap,r0,rc_low,rc: 0.085009 2.2124 4.20311 0 5.5

rank: 1 phi0,ap,r0,rc_low,rc: 0.075832 1.6752 3.64207 0 5
rank: 1 phi0,ap,r0,rc_low,rc: 0.807371 0.73124 4.49714 0 5.5
rank: 1 phi0,ap,r0,rc_low,rc: 0.974501 1.2846 3.08858 0 4
rank: 1 phi0,ap,r0,rc_low,rc: 0.807371 0 4.49714 0 5.5
rank: 1 phi0,ap,r0,rc_low,rc: 0.066001 0 4.31169 0 5
rank: 1 phi0,ap,r0,rc_low,rc: 0.581624 0 3.25062 0 4
rank: 1 phi0,ap,r0,rc_low,rc: 0.974501 1.2846 3.08858 0 4
rank: 1 phi0,ap,r0,rc_low,rc: 0.581624 1.2566 3.25062 0 4
rank: 1 phi0,ap,r0,rc_low,rc: 0.085009 2.2124 4.20311 0 5.5

the problem lies in the second data column, last 4~6 rows, their values are actually zero, while all other data are correct.
The partially correct data from other ranks indicates that the Broadcast has been performed, however, I don't understand how can partial data be wrong.
So my question is, why the broadcast partially fails? What did I do wrong in my coding? Thanks for the help!
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Programming

C++ Bug probably scope problem

Hello, I have some difficulty to understand the scope of this program adapted from C++ book of D.S. Malik I am reading. I put the header and the main program as attachment to save space. My problem is the output:$ ./prog1009_die Line 4: Not yet rolled, die1 gets default number: 1 Line 5: Not... (5 Replies)
Discussion started by: yifangt
5 Replies

2. Programming

is this a bug of g++?

Hello, Im using the g++(g++ Ubuntu/Linaro 4.4.4-14ubuntu5 4.4.5) and im trying to compile a small snippet code and got into an endless loop.I recompiled that in VS2010 under Windows 7 and the answer is as expected.so i wonder is this a bug of g++?here is my code. #include<iostream> using... (5 Replies)
Discussion started by: homeboy
5 Replies

3. UNIX for Dummies Questions & Answers

where's the bug?

#!/bin/bash if then #echo "infinite loop" exit 0 fi when I run this file I get the following error: ./test_infinite_loop: line 5: syntax error near unexpected token `fi' ./test_infinite_loop: line 5: `fi' :confused: (4 Replies)
Discussion started by: jon80
4 Replies

4. AIX

bug in 43 ???

xxxxserver# lsattr -El inet0 | grep 255.240.0.0,32.224.0.0,32.78.120.254 | grep '.40' route net,-hopcount,1,-netmask,255.240.0.0,32.224.0.0,32.78.120.254 How this is possible? (1 Reply)
Discussion started by: itik
1 Replies

5. Shell Programming and Scripting

Is it a bug ..?

Hi All, I am using Red Hat Linux on my servers. The problem that I am facing is, sometimes the /opt usage on the server shows used percentage as 100% , when actually it is simply 20%. When I reboot the system, it comes back to 20%.Is this a bug in the system or my settings have gone wrong... (1 Reply)
Discussion started by: nua7
1 Replies

6. Shell Programming and Scripting

Y2.038K bug

Does any1 hav the idea abt wat cause this bug in unix on jan 19th 2038??? please enlighten me abt it.... (2 Replies)
Discussion started by: bourne
2 Replies

7. UNIX for Dummies Questions & Answers

Sed bug in OS X?

I've been playing around with sed for a few days now and find that regular expressions never work inside sed s/// on Mac OS 10.2.5. Has anyone else bumped up against this problem? For example, the "sed" segment of the following always fails no matter how items are escaped: cd... (12 Replies)
Discussion started by: ktoz
12 Replies
Login or Register to Ask a Question