none
Building a function out of a mpi program and inserting it into the new main function....? RRS feed

  • Question

  • Hi:
    I have a mpi program with its bash file which works completely fine. It is as follows:

        int main(int argc, char *argv[])
    {

        MPI_Status status;
        MPI_Init(&argc,&argv);
        MPI_Comm_rank(MPI_COMM_WORLD, &MYRANK);
        MPI_Comm_size(MPI_COMM_WORLD, &NP);
        
      .......CODES.......

         MPI_Finalize();
          return 0;
    }


    Its final results is a double vector that I need. Now what I want to do is to write a function out of it (for example changing the int main(int argc, char *argv[]) to double foo("some arguments")) so I use it couple of times in another main program. I don't know how to do it. I inserted the function foo as it was (with all mpi stuff) in the new main program that has not mpi stuff but it doesn't work (it takes the error on arguments of MPI_Init(&argc,&argv) since they are not defined in foo ofcourse. I have even tried to pass these arguments from the new main to foo but it doesn't work.).
    Any help is really appreciated.
    Thanks,
    Amin

    Tuesday, October 6, 2009 4:59 PM

Answers

  • You can pass in a 0 to argc and a NULL to argv. Most MPI implementations don't use these parameters.

    Your other options is to put MPI_Init and MPI_Finalize in your outer functions, that is your new main function.

    hope this helps,
    .Erez

    Monday, October 12, 2009 4:22 PM