static void master(char *inputdir,char *outputdir,char *blastparameters, char *jobid) { int ntasks, rank; char *result; MPI_Status status; filelist *myfilelist; char *work; char *diestring; DIR *dfd; int count; struct direct **files; /* Find out how many processes there are in the default communicator */ diestring=(char *)malloc(sizeof(char)*SMALL_STRSIZE); result=(char *)malloc(sizeof(char)*MED_STRSIZE); work=(char *)malloc(sizeof(char)*BIG_STRSIZE); MPI_Comm_size(MPI_COMM_WORLD, &ntasks); /* Seed the slaves; send one unit of work to each slave. */ strcpy(diestring,"XXX"); //if work is null, it means the number of jobs are more than the processors printf("MASTER Master received the inputs\ninputdir is %s \noutputdir is %s\nblastparameters are %s\n",inputdir,outputdir,blastparameters); if ((dfd=opendir(inputdir))==NULL) { printf("Can't access %s \nSo I am quitting\n",inputdir); exit(0); // } closedir(dfd); count=scandir(inputdir,&files,file_select,alphasort); myfilelist=(filelist *) malloc(sizeof(filelist)*(count+1)); myfilelist=processtheinputlist_and_initialize(inputdir,outputdir); for (rank = 1; rank < ntasks; ++rank) { /* Find the next item of work to do */ printf("MASTER Forloop ranks\n"); work = get_next_work_item(inputdir,outputdir,blastparameters,jobid,&myfilelist); /* Send it to each rank */ if (work == _NULL) { MPI_Send(diestring, /* message buffer */ BIG_STRSIZE, /* one data item */ MPI_CHAR, /* data item is an integer */ rank, /* destination process rank */ DIETAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ printf("DIEstring sent \n"); } else { printf("MASTER work issssssssssssss %s \n",work); MPI_Send(work, /* message buffer */ BIG_STRSIZE, /* one data item */ MPI_CHAR, /* data item is an integer */ rank, /* destination process rank */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ strcpy(work,"\0"); //initialize it printf("MASTER sent success \n"); } fflush(stdout); } printf("MASTER First phase is completed\n"); /* Loop over getting new work requests until there is no more work to be done */ work = get_next_work_item(inputdir,outputdir,blastparameters,jobid,&myfilelist); while (work != _NULL) { /* Receive results from a slave */ MPI_Recv(result, /* message buffer */ MED_STRSIZE, /* one data item */ MPI_CHAR, /* of type double real */ MPI_ANY_SOURCE, /* receive from any sender */ MPI_ANY_TAG, /* any type of message */ MPI_COMM_WORLD, /* default communicator */ &status); /* info about the received message */ //process the result, update &myfilelist /* Send the slave a new work unit */ MPI_Send(work, /* message buffer */ BIG_STRSIZE, /* one data item */ MPI_CHAR, /* data item is an integer */ status.MPI_SOURCE, /* to who we just received from */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ /* Get the next unit of work to be done */ work = get_next_work_item(inputdir,outputdir,blastparameters,jobid,&myfilelist); fflush(stdout); } printf("MASTER While is skipped\n"); printf("still here\n"); /* There's no more work to be done, so receive all the outstanding results from the slaves. */ for (rank = 1; rank < ntasks; ++rank) { printf("Rank %d is done\n",rank); MPI_Recv(result, MED_STRSIZE, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); fflush(stdout); } printf("MASTER All the results are collected, now sending die signals to processors\n"); /* Tell all the slaves to exit by sending an empty message with the DIETAG. */ for (rank = 1; rank < ntasks; ++rank) { MPI_Send(diestring, BIG_STRSIZE, MPI_CHAR, rank, DIETAG, MPI_COMM_WORLD); } printf("MASTER Program finished succesfully \n"); }
static void master(void) { int ntasks, rank, realtasks; unit_of_work_t work; unit_of_work_t tmp_work; unit_result_t result; MPI_Status status; unit_result_t TotalWorkingTime = 0.0; fprintf(stderr, "Doing the simulations, please wait ...\n"); /* Find out how many processes there are in the default communicator */ MPI_Comm_size(MPI_COMM_WORLD, &ntasks); /* Seed the slaves; send one unit of work to each slave. */ realtasks = ntasks; for (rank = 1; rank < ntasks; ++rank) { timingNodeWork[rank] = 0.0; /* Find the next item of work to do */ work = get_next_work_item(); tmp_work = work; if(work == 0) { realtasks = rank; break; } /* Send it to each rank */ MPI_Send(&tmp_work, /* message buffer */ 1, /* one data item */ MPI_INT, /* data item is an integer */ rank, /* destination process rank */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ } /* Loop over getting new work requests until there is no more work to be done */ work = get_next_work_item(); while (work != 0) { /* Receive results from a slave */ MPI_Recv(&result, /* message buffer */ 1, /* one data item */ MPI_DOUBLE, /* of type double real */ MPI_ANY_SOURCE, /* receive from any sender */ MPI_ANY_TAG, /* any type of message */ MPI_COMM_WORLD, /* default communicator */ &status); /* info about the received message */ /*Get the total working time for each node*/ timingNodeWork[status.MPI_SOURCE] += result; /* Send the slave a new work unit */ tmp_work = work; MPI_Send(&tmp_work, /* message buffer */ 1, /* one data item */ MPI_INT, /* data item is an integer */ status.MPI_SOURCE, /* to who we just received from */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ /* Get the next unit of work to be done */ work = get_next_work_item(); } /* There's no more work to be done, so receive all the outstanding results from the slaves. */ for (rank = 1; rank < realtasks; ++rank) { MPI_Recv(&result, 1, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); timingNodeWork[status.MPI_SOURCE] += result; } /* Tell all the slaves to exit by sending an empty message with the DIETAG. */ for (rank = 1; rank < ntasks; ++rank) { MPI_Send(0, 0, MPI_INT, rank, DIETAG, MPI_COMM_WORLD); if(timingNodeWork[rank] !=0) fprintf(stderr, "Node %d working time: %f\n", rank, timingNodeWork[rank]); TotalWorkingTime += timingNodeWork[rank]; } fprintf(stderr, "\nTotal working time: %f \n\n", TotalWorkingTime); char command[40]=""; char DoCat[40]=""; /* fprintf(stderr, "\nPutting all the results in one file may cost lots of time,\n"); fprintf(stderr, "Do you need put all results in one file, y/n? \n"); scanf("%s", DoCat); fprintf(stderr, "This will take a little while, Please wait ... \n"); if((strcmp(DoCat,"y")==0)||(strcmp(DoCat,"Y")==0) ||(strcmp(DoCat,"yes")==0)||(strcmp(DoCat,"YES")==0)){ strcpy(command, "rm ./result/result.txt"); system(command); strcpy(command, "cat ./result/ > ./result/result.txt"); system(command); fprintf(stderr, "The results are all in in the ./result/result.txt\n\n"); } */ fprintf(stderr, "Finalizing, please wait ...\n\n"); for(rank = realtasks; rank < ntasks; rank++){ sprintf(command, "rm -rf ./result/%d%s", rank, ModelName); system(command); } }
static void master(void) { int ntasks, rank; unit_of_work_t work; unit_result_t result; MPI_Status status; /* Find out how many processes there are in the default communicator */ MPI_Comm_size(MPI_COMM_WORLD, &ntasks); /* Seed the slaves; send one unit of work to each slave. */ for (rank = 1; rank < ntasks; ++rank) { /* Find the next item of work to do */ work = get_next_work_item(); /* Send it to each rank */ MPI_Send(&work, /* message buffer */ 1, /* one data item */ MPI_INT, /* data item is an integer */ rank, /* destination process rank */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ } /* Loop over getting new work requests until there is no more work to be done */ work = get_next_work_item(); while (work != NULL) { /* Receive results from a slave */ MPI_Recv(&result, /* message buffer */ 1, /* one data item */ MPI_DOUBLE, /* of type double real */ MPI_ANY_SOURCE, /* receive from any sender */ MPI_ANY_TAG, /* any type of message */ MPI_COMM_WORLD, /* default communicator */ &status); /* info about the received message */ /* Send the slave a new work unit */ MPI_Send(&work, /* message buffer */ 1, /* one data item */ MPI_INT, /* data item is an integer */ status.MPI_SOURCE, /* to who we just received from */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ /* Get the next unit of work to be done */ work = get_next_work_item(); } /* There's no more work to be done, so receive all the outstanding results from the slaves. */ for (rank = 1; rank < ntasks; ++rank) { MPI_Recv(&result, 1, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); } /* Tell all the slaves to exit by sending an empty message with the DIETAG. */ for (rank = 1; rank < ntasks; ++rank) { MPI_Send(0, 0, MPI_INT, rank, DIETAG, MPI_COMM_WORLD); } }
static void master(char *commandsfile, char *jobid) { int ntasks, rank; char *result; MPI_Status status; int i; //for loop variable char *work; char *diestring; int count; int tot_commands; char** command_list; // pointer to char*--array of strings--array of commands to execute diestring=(char *)malloc(sizeof(char)*SMALL_STRSIZE); result=(char *)malloc(sizeof(char)*MED_STRSIZE); work=(char *)malloc(sizeof(char)*BIG_STRSIZE); /* Find out how many processes there are in the default communicator */ MPI_Comm_size(MPI_COMM_WORLD, &ntasks); /* Seed the slaves; send one unit of work to each slave. */ strcpy(diestring,"XXX"); //if work is null, it means the number of jobs are more than the processors printf("MASTER Master received the inputs\ncommands file is %s\n",commandsfile); command_list=read_command_list(commandsfile, &tot_commands); count=0; for (rank = 1; rank < ntasks; ++rank) { /* Find the next item of work to do */ printf("MASTER Forloop ranks\n"); work=get_next_work_item(command_list, count, tot_commands); count++; //increment count of how many work requests we have done /* Send it to each rank */ if (work == _NULL) { MPI_Send(diestring, /* message buffer */ BIG_STRSIZE, /* one data item */ MPI_CHAR, /* data item is an integer */ rank, /* destination process rank */ DIETAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ printf("DIEstring sent \n"); } //end if work == _NULL else { printf("MASTER work is %s \n",work); MPI_Send(work, /* message buffer */ BIG_STRSIZE, /* one data item */ MPI_CHAR, /* data item is an integer */ rank, /* destination process rank */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ strcpy(work,"\0"); //initialize it printf("MASTER sent success \n"); } fflush(stdout); } //end for rank=1..ntasks printf("MASTER First phase is completed\n"); /* Loop over getting new work requests until there is no more work to be done */ work=get_next_work_item(command_list, count, tot_commands); count++; //increment count of how many work requests we have done /* Send it to each rank */ while (work != _NULL) { /* Receive results from a slave */ MPI_Recv(result, /* message buffer */ MED_STRSIZE, /* one data item */ MPI_CHAR, /* of type double real */ MPI_ANY_SOURCE, /* receive from any sender */ MPI_ANY_TAG, /* any type of message */ MPI_COMM_WORLD, /* default communicator */ &status); /* info about the received message */ //process the result, update &myfilelist /* Send the slave a new work unit */ MPI_Send(work, /* message buffer */ BIG_STRSIZE, /* one data item */ MPI_CHAR, /* data item is an integer */ status.MPI_SOURCE, /* to who we just received from */ WORKTAG, /* user chosen message tag */ MPI_COMM_WORLD); /* default communicator */ /* Get the next unit of work to be done */ work=get_next_work_item(command_list, count, tot_commands); count++; //increment count of how many work requests we have done fflush(stdout); } printf("MASTER While is skipped\n"); printf("still here\n"); /* There's no more work to be done, so receive all the outstanding results from the slaves. */ for (rank = 1; rank < ntasks; ++rank) { printf("Rank %d is done\n",rank); MPI_Recv(result, MED_STRSIZE, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status); fflush(stdout); } printf("MASTER All the results are collected, now sending die signals to processors\n"); /* Tell all the slaves to exit by sending an empty message with the DIETAG. */ for (rank = 1; rank < ntasks; ++rank) { MPI_Send(diestring, BIG_STRSIZE, MPI_CHAR, rank, DIETAG, MPI_COMM_WORLD); } //clean up for(i=0;i<tot_commands;i++) { free(command_list[i]); } free(command_list); printf("MASTER Program finished succesfully \n"); }