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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:45:06+00:00 2026-06-15T23:45:06+00:00

I want to parallelize an numerical integration function. I want to use this function

  • 0

I want to parallelize an numerical integration function. I want to use this function in the middle of calculation. The work before should be done in root process. Is this possible to do in MPI?

 double integral_count_MPI(double (*function)(double) , double beginX, double endX, int      count)
 {
    double step, result;
    int i;
    if (endX - beginX <= 0) return 0;
    step = (endX - beginX) / count;
    result = 0;

    double *input = (double*)malloc((count+1) *sizeof(double));
    for (i = 0; i <= count; i ++)
    {
       input[i] = beginX + i*step;
    }
    // Calculate and gather
 }

EDIT

algorithm:

  1 process calculation;
while:
  1 process calculation;
  integration very complex function with many processes;
  1 process calculation;
end while;
1 process calculation;
  • 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-15T23:45:06+00:00Added an answer on June 15, 2026 at 11:45 pm

    MPI provides various means to build libraries that use it “behind the scenes”. For starters, you can initialise MPI on demand. MPI-2 modified the requirements for calling MPI_Init so every compliant implementation should be able to correctly initialise with NULL arguments to MPI_Init (because the actual program arguments might not be available to the library). Since MPI should only be initialised once, the library must check if it was already initialised by calling MPI_Initialized. The code basically looks like this:

    void library_init(void)
    {
       int flag;
    
       MPI_Initialized(&flag);
       if (!inited)
       {
          MPI_Init(NULL, NULL);
          atexit(library_onexit);
       }
    }
    

    The initialisation code also registers an exit handler by calling atexit() from the C standard library. Within this exit handler it finalises the MPI library if it not already finalised. Failure to do so might result in mpiexec terminating the whole MPI job with a message that at least one process has exited without finalising MPI:

    void library_onexit(void)
    {
       int flag;
    
       MPI_Finalized(&flag);
       if (!flag)
          MPI_Finalize();
    }
    

    This arrangement allows you to write your integral_count_MPI function simply like:

    double integral_count_MPI(...)
    {
        library_init();
    
        ... MPI computations ...
    }
    

    integral_count_MPI will demand-initialise the MPI library on the first call. Later calls will not result in reinitialisation because of the way library_init is written. Also no explicit finalisation is necessary – the exit handler will take care.

    Note that you will still need to launch the code via the MPI process launcher (mpirun, mpiexec, etc.) and will have to be careful with doing I/O, since the serial part of the code would execute in each instance. Many MPI-enabled libraries provide their own I/O routines for that purpose that filter on the process rank and allow only rank 0 to perform the actual I/O. You can also use the dynamic process management facilities of MPI to spawn additional processes on demand, but that would require that you abstract a huge portion of the process management into the library that performs the integration, which would make it quite complex (and the code of your main program would look awkward).

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

Sidebar

Related Questions

I want to use MPI to parallelize a function that is being called multiple
I create a QFuture that I want to use to parallelize calls to a
Following to this post , I want parallelize this method : public IEnumerable<string> GetAllLogs(IEnumerable<IComputer>
I want to get the community's perspective on this. If I have a process
I want to parallelize a function using IPython.parallel, and when I define it in
I'm trying to get this function for making it easy to parallelize my bash
I want to parallelize a loop in a class member function. However there are
I have a function that I eventually want to parallelize. Currently, I call things
I have the following nested for loops. I want to parallelize the first loop
Want to run javascript function from parent window in child window Example I have

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.