I have two openmpi programs which I start like this
mpirun -n 4 ./prog1 : -n 2 ./prog2
Now how do I use MPI_Comm_size(MPI_COMM_WORLD,
Since you are using Open MPI, there is a very simple OMPI-specific solution:
#include
MPI_Comm appcomm;
int app_id = atoi(getenv("OMPI_MCA_orte_app_num"));
MPI_Comm_split(MPI_COMM_WORLD, app_id, 0, &appcomm);
There will be now as many different appcomm communicators as there are application contexts.