Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6723099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:31:41+00:00 2026-05-26T09:31:41+00:00

I’m currently walking myself through some basic MPI examples to refresh my memory (using

  • 0

I’m currently walking myself through some basic MPI examples to refresh my memory (using Pacheco’s book as a guide), but I’m running into a problem I don’t quite understand. To demonstrate attribute caching, I’ve written the following program:

#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[]) {
    int rank, size;
    int key;
    int *value;
    void* extra_arg; /* unused */

    /* Broadcast value for sync */
    int x;

    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);
    MPI_Comm_size(MPI_COMM_WORLD,&size);
    MPI_Keyval_create(MPI_DUP_FN, MPI_NULL_DELETE_FN,
        &key, extra_arg);

    if (rank==0) {
        *value = 42;
        MPI_Attr_put(MPI_COMM_WORLD, key, value);
        x=17;
        MPI_Bcast(&x,1,MPI_INT,0,MPI_COMM_WORLD);
    } else {
        MPI_Bcast(&x,1,MPI_INT,0,MPI_COMM_WORLD);
        int* newval;
        int flag;
        MPI_Attr_get(MPI_COMM_WORLD,key,&newval,&flag);
        printf("Value = %d \n", *newval);
    }
    MPI_Finalize();
    return 0;
}

(The broadcast is just there to prevent MPI_Attr_get from occuring before the put.)

This, if I’m doing it properly, should result in all processes but rank 0 printing “Value = 42\n”. What I get, however, if I do “mpirun -np 2 ./a.out”, is

[exp:27936] *** Process received signal ***
[exp:27936] Signal: Segmentation fault (11)
[exp:27936] Signal code: Invalid permissions (2)
[exp:27936] Failing at address: 0xb763aff4
[exp:27936] [ 0] [0xf57fe40c]
[exp:27936] [ 1] ./a.out(main+0x74) [0x80488e8]
[exp:27936] [ 2] /lib/libc.so.6(__libc_start_main+0xdc) [0xb74fbe9c]
[exp:27936] [ 3] ./a.out [0x80487c1]
[exp:27936] *** End of error message ***
--------------------------------------------------------------------------
mpirun noticed that process rank 0 with PID 27936 on node exp exited on signal 11 (Segmentation fault).--------------------------------------------------------------------------

What I don’t understand is why this is segfaulting! The same error occurs whether I declare “int newval” at the top of main or inside the else, and only occurs when MPI_Attr_get is run: commenting this out and doing something else with newval is fine.

Thoughts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:31:41+00:00Added an answer on May 26, 2026 at 9:31 am

    The segfault is because of a C thing, not an MPI thing – you need newval to be an integer, not a pointer to one:

    #include <stdio.h>
    #include <mpi.h>
    
    int main(int argc, char *argv[]) {
        int rank, size;
        int key;
        void* extra_arg; /* unused */
    
        /* Broadcast value for sync */
        int x;
    
        MPI_Init(&argc,&argv);
        MPI_Comm_rank(MPI_COMM_WORLD,&rank);
        MPI_Comm_size(MPI_COMM_WORLD,&size);
        MPI_Keyval_create(MPI_DUP_FN, MPI_NULL_DELETE_FN,
            &key, NULL);
    
        if (rank==0) {
            int value = 42;
            MPI_Attr_put(MPI_COMM_WORLD, key, &value);
            x=17;
            MPI_Bcast(&x,1,MPI_INT,0,MPI_COMM_WORLD);
        } else {
            MPI_Bcast(&x,1,MPI_INT,0,MPI_COMM_WORLD);
            int newval;
            int flag;
            MPI_Attr_get(MPI_COMM_WORLD,key,&newval,&flag);
            if (flag)
                printf("Value = %d \n", newval);
        }
        MPI_Finalize();
        return 0;
    }
    

    I think this still doesn’t behave as you want; I’m not sure the attribute is broadcast to all processes associated with the communicator. (Also note that MPI_Attr_get/put have been deprecated as of MPI2 and replaced with MPI_Comm_get/set_attr()).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.