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_Comm_rank(MPI_COMM_WORLD, &MYRANK);
        MPI_Comm_size(MPI_COMM_WORLD, &NP);

          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.

    Tuesday, October 6, 2009 4:59 PM


  • 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,

    • Marked as answer by Don Pattee Wednesday, December 9, 2009 6:20 AM
    Monday, October 12, 2009 4:22 PM