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 8023475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:34:22+00:00 2026-06-04T22:34:22+00:00

For hours im trying to send 2D array over MPI to diffrent thread. Code

  • 0

For hours im trying to send 2D array over MPI to diffrent thread. Code looks like this (i’ll leave comments to show tricks that i have already tryed):

Type definition:

// Define datatype
//MPI_Type_contiguous(N, MPI_INT, &mpi_vector);
//MPI_Type_vector(N, N, N, mpi_vector, &mpi_matrix);
//MPI_Type_vector(N, N, N, MPI_INT, &mpi_matrix);
//MPI_Type_contiguous(N, MPI_INTEGER, &mpi_vector);
//MPI_Type_contiguous(N, mpi_vector, &mpi_matrix);
MPI_Type_vector(N, N, 0, MPI_INTEGER, &mpi_matrix);
//MPI_Type_commit(&mpi_vector);
MPI_Type_commit(&mpi_matrix);

Sending and recieving:

int** tmp = new int*[N];
switch(r) {
case T1:
    inputMatrix(tmp, 2);
    MPI_Send(tmp, 1, mpi_matrix, T2, 0, MPI_COMM_WORLD);
    //task_T1();
    break;
case T2:
    //task_T2();
    inputMatrix(tmp, -1);
    MPI_Recv(tmp, 1, mpi_matrix, T1, 0, MPI_COMM_WORLD, &s);
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N; j++) {
            cout << "  " << tmp[i][j];
        }
        cout << endl;
    }
    break;
}

I need to have this done till morning (in 7 hours), i hope smb is able to help me.

  • 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-06-04T22:34:25+00:00Added an answer on June 4, 2026 at 10:34 pm

    MPI DOES NOT SUPPORT matrices in which each row is allocated separately, a.k.a. array of pointers to rows. MPI works only with flat arrays where rows are stored consecutively in memory. Use a flat array:

    int** tmp = ...
    

    should become

    int* tmp = new int[rows*cols];
    

    and then tmp[row][col] should be accessed as tmp[row*cols + col].

    You can construct a contiguous type from MPI_INT for a single row and then construct a contiguous type from the previous contiguous type for the whole matrix. You can also construct a single contiguous type of rows*cols MPI_INT elements. The first approach is more flexible as you might need to send individual rows later.

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

Sidebar

Related Questions

I've spent hours trying to debug this code. I want to get the second-to-last
I've spent ~6 hours trying to figure this out. I'm hoping a perl guru
I took many hours trying to solve this problem I have attempted, without success.
i spent last few hours trying to find what is wrong in my code(?)
I have spent the past 6 hours trying to solve this ! and i
I've been trying to figure this out for hours now, and I'm at my
I've spent a couple hours trying to find a good answer to this.. How
I've got an app where a thread is trying to send lots of Location
I've been struggling for several hours trying to figure out how to get this
After banging my head against the wall over this for the past few hours

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.