#include <MPI.h>


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

	if(sscanf(argv[1], "%u", &NumberOfWords) != 1)
		fprintf(stderr, "error - not an unsigned integer");

	int chid; // Channel ID
	chid = setupMPI();

	pid_t  pid;
    	pid = fork();
    	/* If fork is a success then it creates two process one with pid = 0 (child process) and other process parent server*/
    	if(pid == -1)
    	{
    		printf("Child process can not be created");
    		exit(EXIT_FAILURE);
    	}
    	else if(pid == 0)
    	{	/* For child process pid return by fork() is 0 */
  		int send_buff[NumberOfWords];
    		int ppid;
    		ppid= getppid();
    		writeData(send_buff, NumberOfWords);
    		sendDataSender(ppid,chid, send_buff, NumberOfWords);
    	
    	}
    	else
    	{
		int receive_buff[NumberOfWords];
        	receiveDataReceiever(chid, receive_buff, NumberOfWords);
        	printf("IPC used: MPI\n");
    	}
    	return EXIT_SUCCESS;
}

