Unix/Linux Go Back    

High Performance Computing Message Passing Interface (MPI) programming and tuning, MPI library installation and management, parallel administration tools, cluster monitoring, cluster optimization, and more HPC topics.

MPI - Error on sending argv

High Performance Computing

Thread Tools Search this Thread Display Modes
Old Unix and Linux 04-21-2010   -   Original Discussion by awiles
awiles's Unix or Linux Image
awiles awiles is offline
Registered User
Join Date: Apr 2010
Last Activity: 21 April 2010, 9:55 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
MPI - Error on sending argv

Hi all,
I write a simple MPI program to send a text message to another process. The code is below.

#include "mpi.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char* argv[]) {
    int dest, noProcesses, processId;
    MPI_Status status;
    char* buffer;
    char* text = "ABCDEF";
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &noProcesses);
    MPI_Comm_rank(MPI_COMM_WORLD, &processId);
    buffer = (char*) malloc(256 * sizeof(char));
    if (processId == 0) {
      fprintf(stdout, "Master: sending %s to %d\n", text, 1);
      MPI_Send((void *)&text, strlen(text) + 1, MPI_CHAR, 1, 0, MPI_COMM_WORLD);
    } else {
      MPI_Recv(&buffer, 128, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
      fprintf(stdout, "Slave: received %s from %d\n", buffer, status.MPI_SOURCE);
    return 0;

After compiling and executing it I get the following output:

[root@cluster Desktop]# mpicc -o test test.c
[root@cluster Desktop]# mpirun -np 2 test
Master: sending ABCDEF to 1
Slave: received ABCDEF from 0

In the source code above, I replace

char* text = "ABCDEF";


char* text = argv[1];

then compile and execute it again with the following commands:

[root@cluster Desktop]# mpicc -o test test.c
[root@cluster Desktop]# mpirun -np 2 test ABCDEF

Then I get the following output:

Master: sending ABCDEF to 1
[cluster:03917] *** Process received signal ***
[cluster:03917] Signal: Segmentation fault (11)
[cluster:03917] Signal code: Address not mapped (1)
[cluster:03917] Failing at address: 0xbfa445a2
[cluster:03917] [ 0] [0x959440]
[cluster:03917] [ 1] /lib/libc.so.6(_IO_fprintf+0x22) [0x76be02]
[cluster:03917] [ 2] test(main+0x143) [0x80488b7]
[cluster:03917] [ 3] /lib/libc.so.6(__libc_start_main+0xdc) [0x73be8c]
[cluster:03917] [ 4] test [0x80486c1]
[cluster:03917] *** End of error message ***
mpirun noticed that process rank 1 with PID 3917 on node cluster.hpc.org exited on signal 11 (Segmentation fault).

I’m very confused because the only difference between the two source codes is the difference between

char* text = "ABCDEF";


char* text = argv[1];

Can any one help me why the results are so different? How can I send argv[i] to another process?
Thank you very much!
Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error while sending email from solaris Danish Shakil Shell Programming and Scripting 0 03-05-2009 09:39 AM
error while sending mails through MKS Vrgurav Shell Programming and Scripting 0 03-07-2008 02:07 AM
sending mail error.. help kkc Shell Programming and Scripting 2 10-16-2007 12:11 PM
Sending Error msg from HP-UX to E-mail address cgege HP-UX 1 08-05-2004 07:41 AM
Error when sending mail attachment dbrundrett UNIX for Dummies Questions & Answers 1 01-08-2004 06:26 AM

All times are GMT -4. The time now is 03:16 PM.