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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:37:51+00:00 2026-06-06T16:37:51+00:00

Hi I have a program written in C++ in which one or two functions

  • 0

Hi I have a program written in C++ in which one or two functions out of many are using PETSc.

When I’m calling these functions which would be the proper approach while using PETSc

1) a)change all MPI_COMM_WORLD to PETSC_COMM_WORLD for my entire program
   b)change MPI_Init to PetscInitialize

..

2) create a separate comm world for petsc and pass that on to the function

    MPI_Init(&argc, &argv);
    ..
    //some many line of code
    ..

    MPI_Comm_split(MPI_COMM_WORLD, rank, 0, &PETSC_COMM_WORLD);

    petsc_function(PETSC_COMM_WORLD,.....

    //some how reverting the comm_split here to continue as normal so all the non petsc functions work

..

3) or can i simply get by just using MPI_COMM_WORLD with the Petsc function
..

4) or is there another approach I am unaware of?

  • 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-06T16:37:53+00:00Added an answer on June 6, 2026 at 4:37 pm

    You need to call PetscInitialize first. You can replace the call to MPI_Init with it.

    There is no need to set PETSC_COMM_WORLD unless you only want to use PETSc on a subset of the ranks. If you do not set PETSC_COMM_WORLD yourself, it will be set automatically by PetscInitialize to be a copy of MPI_COMM_WORLD.

    Then, when you call PETSc functions you can use PETSC_COMM_WORLD. At the end of the program call PetscFinalize, which will call MPI_Finalize for you unless you called MPI_Init manually instead of using PetscInitialize alone.

    There is no need to change MPI_COMM_WORLD to PETSC_COMM_WORLD in the rest of the program.

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

Sidebar

Related Questions

I have a program written in C, which includes 2 functions, one function is
I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have a program which i have myself written in java, but I want
I am beginning to port a program which is written in C and have
I have a debugging program which I've written to attach to a process and
I have a program written in C using ncurses. It let user input and
I have written a program a.exe which launches another program I wrote, b.exe ,
I have written a program which will serialize and de-serialize, it does this fine
I have a client and a host program (written in c) which I want
I have written a program which reads a file containing multidimensional data (most commonly

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.