- Timestamp:
- 2011-12-01T12:16:22+13:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gs2-extensions/parallel-building/trunk/src/src/mpiimport-src/mpiimport.cpp
r24699 r24833 27 27 using namespace std; 28 28 29 //#define HARDAFFINITY 1 29 30 #define BUFFERSIZE 512 30 31 … … 70 71 if (rank == 0) 71 72 { 73 cerr << " * Master Starting" << endl; 72 74 char incoming[BUFFERSIZE]; // buffer for acknowledgments 73 75 char buffer[BUFFERSIZE]; // buffer to send tasks … … 84 86 85 87 // set initial status of all processors to idle 88 cerr << " - initializing processor state" << endl; 86 89 for ( int j=0; j<BUFFERSIZE; j++ ) 87 90 { … … 91 94 // scan through contents of file listing 92 95 int manifest_file_count = 1; 96 cerr << " - processing contents of filelist.txt" << endl; 93 97 while (!infile.eof ()) 94 98 { … … 100 104 int dest=0; 101 105 int found = 0; 106 cerr << " - searching for idle processor" << endl; 102 107 while ((dest<(numtasks-1)) && (found == 0)) 103 108 { … … 115 120 if (found == 0) 116 121 { 122 cerr << " - waiting for processor to become idle" << endl; 117 123 MPI_Waitany (numtasks-1, request, &dest, status); 118 124 } 119 125 120 126 // construct manifest filename 127 cerr << " - creating manifest file: number " << manifest_file_count << endl; 121 128 stringstream manifestfilename_strstr; 122 129 manifestfilename_strstr << gsdlhomedir << "/collect/" << collection << "/tmp/manifest." << manifest_file_count << ".xml"; … … 158 165 manifestfile.close (); 159 166 167 cerr << " - manifest file complete" << endl; 168 160 169 // Store manifest filepath so we can remove it later 161 170 manifest_files.push_back(manifestfilename); 162 171 163 172 // Send the manifest filename as the instruction 173 cerr << " - writing manifest filename as instruction to worker" << endl; 164 174 sprintf(buffer, "%s", manifestfilename); 165 175 … … 167 177 incoming[dest] = 'B'; 168 178 // send out the job to the processor 179 cerr << " - asking worker to start" << endl; 169 180 MPI_Send (&buffer, strlen (buffer)+1, MPI_CHAR, dest+1, 1, MPI_COMM_WORLD); 170 181 // wait for a done acknowledgement 171 182 MPI_Irecv (&incoming[dest], 1, MPI_CHAR, dest+1, 1, MPI_COMM_WORLD, &request[dest]); 183 cerr << " - worker replied that it has started" << endl; 172 184 // update counter of actual tasks 173 185 if (dest > actualTasks) 174 186 { 175 187 actualTasks = dest; 188 cerr << " - increased the number of running workers to: " << actualTasks << endl; 176 189 } 177 190 // increase number of manifest files processed … … 183 196 184 197 // wait until all outstanding tasks are completed 198 cerr << " - waiting for all outstanding tasks to complete" << endl; 185 199 int dest; 186 200 for ( int k=0; k<actualTasks; k++ ) … … 190 204 191 205 // send message to end all processing engines 206 cerr << " * Master asking children to exit" << endl; 192 207 char endstr[5] = "end"; 193 208 for ( int i=1; i<numtasks; i++ ) … … 197 212 198 213 // Free up manifest files 214 cerr << " - freeing shared memory used by manifest files" << endl; 199 215 for ( int i = 0; i < manifest_files.size(); i++) 200 216 { 201 217 free(manifest_files[i]); 202 218 } 203 219 cerr << " * Master Exiting" << endl; 204 220 } 205 221 // slave node processing 206 222 else 207 223 { 224 ///out << "Worker Starting" << endl; 208 225 char incoming[BUFFERSIZE]; 226 227 int counter = 0; 209 228 210 229 do … … 217 236 MPI_Abort(MPI_COMM_WORLD, rc); 218 237 } 238 counter++; 219 239 if (strcmp (incoming, "end") != 0) 220 240 { 221 241 // process a received job 222 c out << "Processing [" << rank << ":" << incoming << "]" << endl;242 cerr << "Worker Processing [" << rank << ":" << incoming << "]" << endl; 223 243 224 244 // create Greenstone import command 225 245 // - incoming now contains the name of the manifest file to process 226 246 char command[2048]; 247 248 #ifdef HARDAFFINITY 249 int cpu = rank - 1; 250 cerr << "Setting affinity for worker " << rank << " to cpu " << cpu << endl; 227 251 if (site != "") 228 252 { 229 sprintf (command, " %s/bin/script/import.pl -keepold -manifest %s -site %s %s", gsdlhomedir, incoming, site, collection);253 sprintf (command, "taskset -c %d %s/bin/script/import.pl -verbosity 0 -keepold -manifest %s -site %s %s", cpu, gsdlhomedir, incoming, site, collection); 230 254 } 231 255 else 232 256 { 233 sprintf (command, "%s/bin/script/import.pl -keepold -manifest %s %s", gsdlhomedir, incoming, collection); 234 } 235 cout << "**** cmd = " << command << endl; 257 sprintf (command, "taskset -c %d %s/bin/script/import.pl -verbosity 0 -keepold -manifest %s %s", cpu, gsdlhomedir, incoming, collection); 258 } 259 #else 260 if (site != "") 261 { 262 sprintf (command, "%s/bin/script/import.pl -verbosity 0 -keepold -manifest %s -site %s %s", gsdlhomedir, incoming, site, collection); 263 } 264 else 265 { 266 //sprintf (command, "%s/bin/script/import.pl -verbosity 0 -keepold -manifest %s %s", gsdlhomedir, incoming, collection); 267 sprintf (command, "%s/bin/script/import.pl -keepold -manifest %s %s > %s/collect/%s/logs/import-p%d-%d.log 2>&1", gsdlhomedir, incoming, collection, gsdlhomedir, collection, rank, counter); 268 } 269 #endif 270 271 cerr << "**** cmd = " << command << endl; 236 272 237 273 // invoke Greenstone import with manifest file 238 274 system (command); 239 275 cerr << "**** complete" << endl; 240 276 char line = ' '; 241 277 // send completed message … … 245 281 while (strcmp (incoming, "end") != 0); 246 282 // stop when "end" instruction is received 283 cerr << "Worker Exiting" << endl; 247 284 } 248 285 249 286 // clean up MPI environment 287 cerr << "Finalizing..." << endl; 250 288 MPI_Finalize(); 251 289 }
Note:
See TracChangeset
for help on using the changeset viewer.