/********************************************************************* * File: task_farm.c * Purpose: Parallel task farming on pre-compiled * executables specified as tasks in a file. * Usage example: mpiexec -machinefile xx -n yy ch -u task_farm.c zz * xx: host file * yy: number of processes * zz: task file *********************************************************************/ #include #include #include #include int main(int argc, char *argv[]) { int myid, numprocs, req = 1; char tmp[512]; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); if(myid == 0) { int numtasks, i, taskscompleted = 0, activeprocs = numprocs - 1; FILE *fptr; double time1, time2; fptr = fopen(argv[1], "r"); // get the name of the task file numtasks = atoi(fgets(tmp, sizeof(tmp), fptr)); // get the number of tasks specified // in the first line of the task file char line[numtasks][512]; // allocate a 2D char array to save the tasks for(i=0; i