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