#include "iostream"
#include <mpi.h>


int main(int argc, char ** argv)
{
	int myRank = 0, size = 0;
	MPI_Comm parent;
	MPI_Comm interComm;

	MPI_Init(&argc, &argv);

	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &myRank);

	MPI_Comm_get_parent(&parent);
	if (parent == MPI_COMM_NULL)
	{
		char command[] = "tese";
		MPI_Comm_spawn(command, MPI_ARGV_NULL, 1, MPI_INFO_NULL, myRank, MPI_COMM_SELF, &interComm, MPI_ERRCODES_IGNORE);
		std::cout << "New process was created..." << std::endl;
	}
	else
	{
		std::cout << "Hi from new process!" << std::endl;
	}

	MPI_Finalize();
	return 0;
}

