Ignore:
Timestamp:
2011-12-01T12:16:22+13:00 (12 years ago)
Author:
jmt12
Message:

Adding support for setting affinity of worker processes. Lots of debug statements (due to 1M doc parallel build issue)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/parallel-building/trunk/src/src/mpiimport-src/mpiimport.cpp

    r24699 r24833  
    2727using namespace std;
    2828
     29//#define HARDAFFINITY 1
    2930#define BUFFERSIZE 512
    3031
     
    7071  if (rank == 0)
    7172  {
     73    cerr << " * Master Starting" << endl;
    7274    char incoming[BUFFERSIZE];          // buffer for acknowledgments
    7375    char buffer[BUFFERSIZE];         // buffer to send tasks
     
    8486
    8587    // set initial status of all processors to idle
     88    cerr << " - initializing processor state" << endl;
    8689    for ( int j=0; j<BUFFERSIZE; j++ )
    8790    {
     
    9194    // scan through contents of file listing
    9295    int manifest_file_count = 1;
     96    cerr << " - processing contents of filelist.txt" << endl;
    9397    while (!infile.eof ())
    9498    {
     
    100104        int dest=0;
    101105        int found = 0;
     106        cerr << " - searching for idle processor" << endl;
    102107        while ((dest<(numtasks-1)) && (found == 0))
    103108        {
     
    115120        if (found == 0)
    116121        {
     122          cerr << " - waiting for processor to become idle" << endl;
    117123          MPI_Waitany (numtasks-1, request, &dest, status);
    118124        }
    119125
    120126        // construct manifest filename
     127        cerr << " - creating manifest file: number " << manifest_file_count << endl;
    121128    stringstream manifestfilename_strstr;
    122129    manifestfilename_strstr << gsdlhomedir << "/collect/" << collection << "/tmp/manifest." << manifest_file_count << ".xml";
     
    158165        manifestfile.close ();
    159166
     167        cerr << " - manifest file complete" << endl;
     168
    160169        // Store manifest filepath so we can remove it later
    161170        manifest_files.push_back(manifestfilename);
    162171
    163172        // Send the manifest filename as the instruction
     173        cerr << " - writing manifest filename as instruction to worker" << endl;
    164174        sprintf(buffer, "%s", manifestfilename);
    165175
     
    167177        incoming[dest] = 'B';
    168178        // send out the job to the processor
     179        cerr << " - asking worker to start" << endl;
    169180        MPI_Send (&buffer, strlen (buffer)+1, MPI_CHAR, dest+1, 1, MPI_COMM_WORLD);
    170181        // wait for a done acknowledgement
    171182        MPI_Irecv (&incoming[dest], 1, MPI_CHAR, dest+1, 1, MPI_COMM_WORLD, &request[dest]);
     183        cerr << " - worker replied that it has started" << endl;
    172184        // update counter of actual tasks
    173185        if (dest > actualTasks)
    174186        {
    175187          actualTasks = dest;
     188          cerr << " - increased the number of running workers to: " << actualTasks << endl;
    176189        }
    177190    // increase number of manifest files processed
     
    183196
    184197    // wait until all outstanding tasks are completed
     198    cerr << " - waiting for all outstanding tasks to complete" << endl;
    185199    int dest;
    186200    for ( int k=0; k<actualTasks; k++ )
     
    190204
    191205    // send message to end all processing engines
     206    cerr << " * Master asking children to exit" << endl;
    192207    char endstr[5] = "end";
    193208    for ( int i=1; i<numtasks; i++ )
     
    197212
    198213    // Free up manifest files
     214    cerr << " - freeing shared memory used by manifest files" << endl;
    199215    for ( int i = 0; i < manifest_files.size(); i++)
    200216    {
    201217      free(manifest_files[i]);
    202218    }
    203 
     219    cerr << " * Master Exiting" << endl;
    204220  }
    205221  // slave node processing
    206222  else
    207223  {
     224    ///out << "Worker Starting" << endl;
    208225    char incoming[BUFFERSIZE];
     226
     227    int counter = 0;
    209228
    210229    do
     
    217236        MPI_Abort(MPI_COMM_WORLD, rc);
    218237      }
     238      counter++;
    219239      if (strcmp (incoming, "end") != 0)
    220240      {
    221241        // process a received job
    222         cout << "Processing [" << rank << ":" << incoming << "]" << endl;
     242        cerr << "Worker Processing [" << rank << ":" << incoming << "]" << endl;
    223243
    224244        // create Greenstone import command
    225245        // - incoming now contains the name of the manifest file to process
    226246        char command[2048];
     247
     248#ifdef HARDAFFINITY
     249        int cpu = rank - 1;
     250        cerr << "Setting affinity for worker " << rank << " to cpu " << cpu << endl;
    227251        if (site != "")
    228252        {
    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);
    230254        }
    231255        else
    232256        {
    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;
    236272
    237273        // invoke Greenstone import with manifest file
    238274        system (command);
    239 
     275        cerr << "**** complete" << endl;
    240276        char line = ' ';
    241277        // send completed message
     
    245281    while (strcmp (incoming, "end") != 0);
    246282    // stop when "end" instruction is received
     283    cerr << "Worker Exiting" << endl;
    247284  }
    248285
    249286  // clean up MPI environment
     287  cerr << "Finalizing..." << endl;
    250288  MPI_Finalize();
    251289}
Note: See TracChangeset for help on using the changeset viewer.