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

  • SEARCH
  • Home
  • 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 7420829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:18:25+00:00 2026-05-29T08:18:25+00:00

The following MPI program simply defines an MPI type for the message, and then

  • 0

The following MPI program simply defines an MPI type for the message, and then sends a message from process 0 to process 1. However, it crashes with a very uninformative error message. What’s wrong with it?

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

struct P {
    char choices[64];
    int next_choice;
};

typedef struct P Packing;

int main(int argc,char** argv) {
    int rank;
    MPI_Datatype PACKING_TYPE;
    MPI_Init(&argc,&argv);
    MPI_Comm_rank(MPI_COMM_WORLD,&rank);

    if (rank == 0) {
        /*Defines a new MPI datatype tag for Packings.*/
        int field_count = 2;
        int field_lengths[2] = {64,1};
        MPI_Aint field_offsets[2] = {0,64 * sizeof(char)};
        MPI_Datatype field_types[2] = {MPI_CHAR,MPI_INT};
        MPI_Type_struct(field_count,field_lengths,
            field_offsets,field_types,&PACKING_TYPE);
        MPI_Type_commit(&PACKING_TYPE);
    }
    MPI_Barrier(MPI_COMM_WORLD);

    if (rank == 0) {
        Packing pack;
        MPI_Status status;
        MPI_Send(&pack,1,PACKING_TYPE,1,0,MPI_COMM_WORLD);
        puts("Process 0 sent message.");
    }

    if (rank == 1) {
        Packing pack;
        MPI_Status status;
        MPI_Recv(&pack,1,PACKING_TYPE,MPI_ANY_SOURCE,
            MPI_ANY_TAG,MPI_COMM_WORLD,&status);
        puts("Process 1 recieved message.");
    }

    MPI_Barrier(MPI_COMM_WORLD);
    if(rank == 0) {
        MPI_Type_free(&PACKING_TYPE);
    }
    MPI_Finalize();
    return 0;
}
  • 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-29T08:18:26+00:00Added an answer on May 29, 2026 at 8:18 am

    Neither MPI_Type_struct() nor MPI_Type_commit() do any communicating (eg, there’s no communicator as part of the argument list); they’re purely local operations. So every process that uses the type must create it. (This makes sense; any process receiving data needs to understand its layout).

    So after getting rid of the if (rank == 0) test (and thus, the barriers) around the type creation and freeing operation, your code works.

    By the way — it’s always safest to actually measure the offsets (eg, using offsetof or similar) rather than assume them; the compiler is free to insert (eg) padding into the structure to help with alignment.

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

Sidebar

Related Questions

I am new to learning MPI and I coded up the following simple program
Following up from my previous question , why is CShell so different from C?
Following on from this question , I am interested in finding out how you
I am following these instructions trying to build Boost MPI .lib files, but I
following code is used to find url from a string with php. Here is
Following method is accepted if I set UIColor like: [tabBarController.tabBar setSelectedImageTintColor:[UIColor greenColor]]; However I
I had a problem with a program that uses MPI and I have just
I am a bit stuck during the building process of the MPI python v
EDIT following Ben's answer I'm trying to make something that should be very easy
I'm trying to compile my first legit program that I'm converting from Java (I

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.