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