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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:21:30+00:00 2026-06-13T12:21:30+00:00

I have 3 function and 4 cores. I want execute each function in new

  • 0

I have 3 function and 4 cores. I want execute each function in new thread using MPI and C++
I write this

int rank, size;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
size--;
if (rank == 0)
{
    Thread1();
}
else 
{
    if(rank == 1)
    {
        Thread2();
    }
    else
    {
        Thread3();
    }
}
MPI_Finalize();

But it execute just Thread1(). How i must change code?

Thanks!

  • 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-13T12:21:31+00:00Added an answer on June 13, 2026 at 12:21 pm

    Print to screen the current value of variable size (possibly without decrementing it) and you will find 1. That is: “there is 1 process running”.

    You are likely running your compiled code the wrong way. Consider to use mpirun (or mpiexec, depending on your MPI implementation) to execute it, i.e.

     mpirun -np 4 ./MyCompiledCode
    

    the -np parameter specifies the number of processes you will start (doing so, your MPI_Comm_size will be 4 as you expect).


    Currently, though, you are not using anything explicitly owing to C++. You can consider some C++ binding of MPI such as Boost.MPI.


    I worked a little bit on the code you provided. I changed it a little bit producing this working mpi code (I provided some needed correction in capital letters).

    FYI:

    • compilation (under gcc, mpich):

       $ mpicxx -c mpi1.cpp 
       $ mpicxx -o mpi1 mpi1.o
      
    • execution

      $ mpirun -np 4 ./mpi1
      
    • output

      size is 4
      size is 4
      size is 4
      2 function started.
      thread2
      3 function started.
      thread3
      3 function ended.
      2 function ended.
      size is 4
      1 function started.
      thread1
      1 function ended.
      

    be aware that stdout is likely messed out.

    Are you sure you are compiling your code the right way?

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

Sidebar

Related Questions

I'm trying to find out where this function comes from. Any one have any
I have function like this: function ypg_delete_img($id, $img) { $q = $this->ypg_get_one($id); $imgs =
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have function getCartItems in cart.js and I want to call that function in
I have function like this: function gi_insert() { if(!IS_AJAX){ $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'Naslov', 'trim|required|strip_tags'); $this->form_validation->set_rules('body',
Let's say I have a function like this: function z($zzz){ for($c=0;$c<5;$c++){ $zzz[$c]= 10; //more
Let's say I have this $(.a).animate( {left:100%}, {duration:50000, complete:function(){ $(.a).css(background-color,black); }} ); $(.b).mouseover(function(){ $(.a).stop();
I have a embarrassingly parallel problem that I want to execute on multiple processors.
I'm using vim with the vim-golang plugin. This plugin comes with a function called
In this thread I found a JavaScript code snippet which I want to use.

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.