/* Physics Institute for Nuclear Research 95123 - Catania - ITALY +39 095.378.55.03 giuseppe.larocca@ct.infn.it Copyright (C) 2005, 2006 -- All rights reserved. */ #include #include #include #include "mpi.h" int create_file(char *filename, int operation) { FILE *fp; /* input byte stream */ char *buffer; char str1[5], str2[10], str3[10], *string; switch (operation) { case 1 : /* try to create the file */ fp = fopen(filename, "w"); if (!fp){ perror(filename); return -1; } return 0; break; case 2 : /* try to read the file */ fp = fopen(filename, "r"); if (!fp){ perror(filename); return -1; } while (!feof(fp)){ fscanf(fp,"%s",str1);fscanf(fp,"%s",str2);fscanf(fp,"%s",str3); printf("%s", str1);printf("%s", str2);printf("%s\n", str3); } fclose(fp); return 0; break; default : printf(" Operation NOT supported.\n"); } } int main (int argc, char **argv) { char nodename[BUFSIZ], string[80]; char CPU_file[BUFSIZ]="CPU_"; char *buf; int myrank, nproc,length,err,nextnode,prevnode; int m,n,i,number,value,newvalue; int exit_code=0; MPI_Status status; /* Initialisation the MPI Environment. */ err=MPI_Init(&argc,&argv); /* Specify the number of processor associated with a commnunicator. */ err=MPI_Comm_size(MPI_COMM_WORLD, &nproc); /* Specify the ID of a processor in a group. */ err=MPI_Comm_rank(MPI_COMM_WORLD, &myrank); /*** INSERT YOUR PARALLEL CODE HERE ***/ MPI_Get_processor_name(nodename,&length); printf("+------------------------------------------------------------------------------------------+\n"); printf("| Running MPI job on.. |\n"); printf(" Processor Name = %s\t\tRank = %d\t\t#Proc. = %d \n",nodename,myrank,nproc); /* Insert a blank line */ printf(" \t\t\t\t\t\t\t\t\t\t\t \n"); /* Creation of the CPU_nodename file which will store the info for each machine */ sprintf(CPU_file,"CPU_%s.dat",nodename); printf(" Creation of %s file.. \n",CPU_file); exit_code=create_file(CPU_file,1); if (exit_code==0){ system("echo -ne '\e[30;49m' ["); system("echo -ne '\e[32;49m' OK"); system("echo -e '\e[30;49m' ]"); } /* Retrieving info about the machine */ printf("\n Retrieving info about the machine\n"); /* sprintf(string,"cat /proc/meminfo | grep MemTotal"); exit_code=system(string); if (exit_code==0){ system("echo -ne '\e[30;49m' ["); system("echo -ne '\e[32;49m' OK"); system("echo -e '\e[30;49m' ]"); } else { system("echo -ne '\e[30;49m' ["); system("echo -ne '\e[31;49m' Failure"); system("echo -e '\e[30;49m' ]"); } printf("MemTotal=%s",s); exit_code=create_file(CPU_file,2); */ printf("| |\n"); printf("+------------------------------------------------------------------------------------------+\n"); /*** INSERT YOUR PARALLEL CODE HERE ***/ /* Finalization of mpi */ err=MPI_Finalize(); return 0; }