/********************************************************************** * III TTTTTTT U U * * I T U U * * I T U U * * I T U U * * III T UUUUUUU * * * * ITU Informatics Institute * * Computational Science & Engineering Dept. * * Istanbul / TURKIYE * * * * By: Ozden AKINCI * * E-mail: akinci@be.itu.edu.tr * * Date: 13.10.2005 * * * * Program: * * When the program runs on the nodes, it creates a log file * * on each node with named "Log_processor_...". The file * * contains hostname and proccessor number. After that, nodes* * sends the name of the their files to the master node with * * zero id. Master node writes down the name of the files to * * the file named as "FileNames", and the program will * * finish. * * After that, the script named "mpi.sh" will go on to * * run, and copy the files listed in "FileNames" file to the * * specified directory (e.g. "output" directory). After * * copying process, the script will archive the directory. * * * **********************************************************************/ #include #include #include #include "mpi.h" #define MASTER 0 #define TAG 1000 #define TAG2 1001 int main(int argc, char **argv) { int my_gid, n_procs,id; MPI_Status status; char I_LogFile[300], /* individual log filename of the node */ TempLogFileName[300], /* log filenames of the nodes */ Hostname[50], /* hostname of the node */ TempHostname[50], /* hostname of the node */ Logs[300], cwd[200]; FILE *log_file,*FileNames; MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &n_procs); MPI_Comm_rank(MPI_COMM_WORLD, &my_gid); gethostname(Hostname, 50); getcwd(cwd,200); printf("I am processor: %d at %s running at %s\n",my_gid,Hostname,cwd); if ( my_gid == 0 ) { /* * the file names "FileNames" is created on the master node * to hold names of the individual log filenames */ sprintf(Logs, "%s/FileNames",cwd); FileNames = fopen(Logs,"w"); if (FileNames == NULL ) { fprintf(stderr, "Error opening %s file",Logs); MPI_Abort(MPI_COMM_WORLD,1); return -1; } } sprintf(I_LogFile, "%s/Log_processor_%d",cwd,my_gid); /* individual log file created */ log_file = fopen(I_LogFile, "w"); if (log_file == NULL) { fprintf(stderr, "Error opening log file\n"); MPI_Abort(MPI_COMM_WORLD, 1); return -1; } MPI_Send(&I_LogFile,300,MPI_CHAR,MASTER,TAG,MPI_COMM_WORLD); MPI_Send(&Hostname,50,MPI_CHAR,MASTER,TAG2,MPI_COMM_WORLD); if ( my_gid == 0) { for (id=0; id>>>: LogFileName: %s\n",id,TempLogFileName); MPI_Recv(&TempHostname,50,MPI_CHAR,id,TAG2,MPI_COMM_WORLD,&status); fprintf(FileNames,"%s:%s\n",TempHostname,TempLogFileName); } } fprintf(log_file, ">>>>>>>>>>>>>>>>>\nHost:%s Processor_number:%d\n",Hostname, my_gid); if (my_gid == 0) fclose(FileNames); fclose(log_file); MPI_Finalize(); return(0); }