![]() |
| | #1 |
| Registered User Join Date: Mar 2009
Posts: 3
| MPI in C I am using MPI and c programming. i want to collect strings from processors to root processor now i have writen the code as below but does not display the strings. Can anyone help me with this? The code is as below: Code:
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(int argc, char *argv[]){
int numProcs;
int myRank, a, *data, i;
char **DATA;
char *b;
//initialize MPI
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD,&myRank);
MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
// do some computation and MPI communications
a = 1000+myRank;
b = "sdfsd";
if (myRank == 1){
data = (int *) malloc(numProcs*sizeof(int));
DATA = (char **) calloc(numProcs, sizeof(char **));
for (i=0;i<numProcs;i++){
data[i] = 0;
DATA[i] = "helloP";
}
printf("\n contents of data array before gather:\n");
for (i=0;i<numProcs;i++)
printf("%s\n", DATA[i]);
}
MPI_Gather(&b, 5, MPI_CHAR, DATA, 5, MPI_CHAR,1, MPI_COMM_WORLD);
printf("here are contents %s\n",DATA[1]);
if (myRank == 1){
printf("\n contents of data array after gather:\n");
for (i=0;i<numProcs;i++){
printf("%s\n", DATA[i]);
/*printf("2. DATA[%d] = %s \n",i, DATA[i]);*/}}
//shutdown MPI
MPI_Finalize();
return 0;
}
|
| ltee is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Don't see anything DIRECTLY wrong. What are you actually receiving? -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Mar 2009
Posts: 3
| Thanks matsp for quick response. Actually bellow is the message i receive: rank 2 in job 8 cslab117-002_50788 caused collective abort of all ranks exit status of rank 2: killed by signal 11 rank 0 in job 8 cslab117-002_50788 caused collective abort of all ranks exit status of rank 0: killed by signal 11 |
| ltee is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| signal 11 is a "seg-fault", which means your app tried to write to memory that doesn't exist. I suspect it is because your DATA is actually pointing to read-only memory. Maybe you would be better off allocating some memory for DATA[i] instead of setting it to "HELLO". I don't KNOW that this is the problem, but it seems reasonable that your processes can not write to read-only memory, and that would cause a Seg-fault signal. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #5 |
| Registered User Join Date: Mar 2009
Posts: 3
| well, when i remove the line Code: DATA[i] = "helloP"; rank 1 in job 11 cslab117-002_50788 caused collective abort of all ranks exit status of rank 1: killed by signal 11 Clear allocation of memory is not a problem here. so im wondering exactly what i need to change. If you look at line: Code: MPI_Gather(&b, 5, MPI_CHAR, DATA, 5, MPI_CHAR,1, MPI_COMM_WORLD); |
| ltee is offline | |
| | #6 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| So where is DATA[i] pointing now? Just removing the assignment IS NOT ENOUGH. You need each process to have some space to write the data into. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
![]() |
| Tags |
| /code, code |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Communication using MPI | Cell | Linux Programming | 9 | 08-13-2009 02:28 AM |
| MPI, which way will be best? | maverick_starst | C++ Programming | 5 | 06-30-2009 02:17 PM |
| Sorting whit MPI | isato | C Programming | 0 | 03-03-2009 10:38 AM |
| Malloc and MPI | moddinati | C Programming | 17 | 03-07-2008 07:55 PM |
| MPI programming | kris.c | Tech Board | 1 | 12-08-2006 12:25 PM |