1 #include <mpi.h> 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <unistd.h> 5 #include <set> 6 #include <string> 7 #include <sstream> 8 #include "phIO.h" 9 #include "posixio.h" 10 #include "phio_posix.h" 11 12 int main(int argc, char* argv[]) { 13 MPI_Init(&argc,&argv); 14 int commrank,commsize; 15 MPI_Comm_rank(MPI_COMM_WORLD,&commrank); 16 MPI_Comm_size(MPI_COMM_WORLD,&commsize); 17 if( argc != 5 ) { 18 if( !commrank ) 19 fprintf(stderr, "Usage: %s <geombc posix file> <verbosity=0|1|2> <rankoffset> <outfile>\n",argv[0]); 20 fprintf(stderr, "verbosity=0 will only write to the specified \'outfile\'\n",argv[0]); 21 fprintf(stderr, "verbosity>0 will write to the specified \'outfile\' and to stdout\n",argv[0]); 22 MPI_Finalize(); 23 return 1; 24 } 25 const char* filename = argv[1]; 26 const int verbosity = atoi(argv[2]); 27 const int rankoffset = atoi(argv[3]); 28 char* outfilename = argv[4]; 29 const char* phrase = "ilwork"; 30 const char* type = "integer"; 31 const char* iotype = "binary"; 32 int* ilwork = NULL; 33 int len = 0; 34 int one = 2; 35 36 37 int phastarank = commrank+1+rankoffset; 38 39 char geomfilename[4096]; 40 sprintf(geomfilename, "%s/geombc.dat.%d",filename,phastarank); 41 42 phio_fp file; 43 posixio_setup(&(file), 'r'); 44 posix_openfile_single(geomfilename, file); 45 phio_readheader(file, phrase, &len, &one, type, iotype); 46 ilwork = (int*) malloc(len*sizeof(int)); 47 phio_readdatablock(file, phrase, ilwork, &len, type, iotype); 48 phio_closefile(file); 49 50 // Initialization 51 int itkbeg = 0; 52 int m = 0; 53 int idl = 0; 54 std::set<int> neighbors; 55 56 // Compute summary info first such as number of communication tasks, neighboring parts, onwer parts, etc 57 int numtask = ilwork[0]; 58 int numowner = 0; 59 for(int itask=0;itask<numtask;itask++) { 60 int iacc = ilwork [itkbeg + 2]; 61 int iother = ilwork [itkbeg + 3]; 62 int numseg = ilwork [itkbeg + 4]; 63 if(iacc == 1) numowner++; 64 neighbors.insert(iother); 65 itkbeg = itkbeg + 4 + 2*numseg; 66 } 67 const int numints = 5; 68 MPI_Status status; 69 MPI_File outfile; 70 MPI_File_open(MPI_COMM_WORLD,outfilename, 71 MPI_MODE_CREATE|MPI_MODE_WRONLY,MPI_INFO_NULL,&outfile); 72 std::string header("rank peers tasks owned notowned\n"); 73 if( !commrank ) //write header 74 MPI_File_write_at(outfile,0,(void*)header.c_str(),header.size(),MPI_CHAR,&status); 75 std::stringstream ss; 76 ss << phastarank << "," 77 << neighbors.size() << "," 78 << numtask << "," 79 << numowner << "," 80 << numtask-numowner << "\n"; 81 std::string s = ss.str(); 82 int size = s.size(); 83 int offset = 0; 84 MPI_Exscan(&size,&offset,1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); 85 offset += header.size(); 86 MPI_File_write_at(outfile,offset,(void*)s.c_str(),s.size(),MPI_CHAR,&status); 87 if( verbosity > 0 ) { 88 // Print now communication info 89 printf("\n"); 90 printf("Communication info for this part:\n"); 91 itkbeg = 0; 92 for(int itask=0;itask<numtask;itask++) { 93 int itag = ilwork [itkbeg + 1]; 94 int iacc = ilwork [itkbeg + 2]; 95 int iother = ilwork [itkbeg + 3]; 96 int numseg = ilwork [itkbeg + 4]; 97 int isgbeg = ilwork [itkbeg + 5]; 98 99 // Toal number of nodes involved in this communication (lfront), including all segments 100 int lfront = 0; 101 for(int is=1;is<=numseg;is++) { 102 int lenseg = ilwork [itkbeg + 4 + 2*is]; 103 lfront = lfront + lenseg; 104 } 105 printf("Communication %d:\ttag %d\townership %d\trank %d\tnumseg %d\tnumvtx %d\n",itask,itag,iacc,iother,numseg,lfront); 106 itkbeg = itkbeg + 4 + 2*numseg; 107 } 108 printf("\n"); 109 } 110 111 // Print now the raw ilwork array 112 if( verbosity > 1 ) { 113 printf("ilwork array:\n"); 114 for(int i=0;i<len;i++) { 115 printf("%d\n",ilwork[i]); 116 } 117 } 118 119 free(ilwork); 120 MPI_File_close(&outfile); 121 MPI_Finalize(); 122 return 0; 123 } 124