]> git.mxchange.org Git - flightgear.git/commitdiff
Refinements to the parallelization tools
authorcurt <curt>
Sat, 22 May 1999 01:15:32 +0000 (01:15 +0000)
committercurt <curt>
Sat, 22 May 1999 01:15:32 +0000 (01:15 +0000)
Tools/Construct/Array/Makefile.am
Tools/Construct/Clipper/Makefile.am
Tools/Construct/Main/Makefile.am
Tools/Construct/Parallel/Makefile.am
Tools/Construct/Parallel/client.cxx
Tools/Construct/Parallel/server.cxx

index eb3f1af73736742c05e61252c6e29ee5539602dc..01ad7dc14c924d846d46fd14235adc8d51fe2e9a 100644 (file)
@@ -2,7 +2,7 @@ noinst_LIBRARIES = libArray.a
 
 libArray_a_SOURCES = array.cxx array.hxx
 
-bin_PROGRAMS = testarray
+noinst_PROGRAMS = testarray
 
 testarray_SOURCES = testarray.cxx
 
index 87a59e28bf05add9999447c75bc32656bc0ab346..abeabbf9fbdcd9ecdb5dde6321641eeb080d54bd 100644 (file)
@@ -2,7 +2,7 @@ noinst_LIBRARIES = libClipper.a
 
 libClipper_a_SOURCES = clipper.cxx clipper.hxx
 
-bin_PROGRAMS = testclipper
+noinst_PROGRAMS = testclipper
 
 testclipper_SOURCES = testclipper.cxx
 
index cf570b43ca10efe09a6f65b1fdbcd86f3b3b501b..955e9da5e8651695e7a199693d18644d4fad68e9 100644 (file)
@@ -1,8 +1,11 @@
-bin_PROGRAMS = construct master
+bin_PROGRAMS = fgfs-construct fgfs-master
 
-construct_SOURCES = construct.cxx construct.hxx main.cxx construct_types.hxx
+fgfs_construct_SOURCES = \
+       construct_types.hxx \
+       construct.cxx construct.hxx \
+       main.cxx
 
-construct_LDADD = \
+fgfs_construct_LDADD = \
        $(top_builddir)/Tools/Construct/Array/libArray.a \
        $(top_builddir)/Tools/Construct/Clipper/libClipper.a \
        $(top_builddir)/Tools/Construct/GenOutput/libGenOutput.a \
@@ -18,9 +21,9 @@ construct_LDADD = \
        $(top_builddir)/Lib/zlib/libz.a \
        -lgpc -lgfc
 
-master_SOURCES = master.cxx
+fgfs_master_SOURCES = master.cxx
 
-master_LDADD = \
+fgfs_master_LDADD = \
        $(top_builddir)/Lib/Bucket/libBucket.a \
        $(top_builddir)/Lib/Misc/libMisc.a
 
index 352376bd2857d8a41e221db902e06d51ea7379c7..a42f809904c1e21538e77c5d7b655e265a585e4a 100644 (file)
@@ -1,14 +1,14 @@
-bin_PROGRAMS = server client
+bin_PROGRAMS = fgfs-tools-server fgfs-tools-client
 
-server_SOURCES = server.cxx
+fgfs_tools_server_SOURCES = server.cxx
 
-server_LDADD = \
+fgfs_tools_server_LDADD = \
        $(top_builddir)/Lib/Bucket/libBucket.a \
        $(top_builddir)/Lib/Misc/libMisc.a
 
-client_SOURCES = client.cxx
+fgfs_tools_client_SOURCES = client.cxx
 
-client_LDADD = \
+fgfs_tools_client_LDADD = \
        $(top_builddir)/Lib/Bucket/libBucket.a \
        $(top_builddir)/Lib/Misc/libMisc.a
 
index 541947bfdde75260461d44f83752090e6d9ee4c1..c52e890f4354bd982deeba8d8a7ac49634384f03 100644 (file)
@@ -9,6 +9,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 
+#include <utmp.h>
+
 #include <stdio.h>
 #include <stdlib.h>  // atoi()
 #include <string.h>  // bcopy()
 
 
 #define MAXBUF 1024
+#define BUSY_WAIT_TIME 30
+
+
+string work_base = "";
+string output_base = "";
+
+
+// check if it is ok to run
+void check_master_switch() {
+    string file = work_base + ".status/MASTER_ON";
+
+    FILE *fp = fopen( file.c_str(), "r" );
+    if ( fp == NULL ) {
+       cout << "MASTER_ON file not found ... exiting." << endl;
+       exit(0);
+    }
+
+    fclose( fp );
+}
+
+
+// check if the host system is free of interactive users
+int system_free() {
+    struct utmp *uptr;
+
+    setutent();
+
+    while ( (uptr = getutent()) != NULL ) {
+       // cout << "NULL = " << NULL << "  uptr = " << uptr << endl;
+       // cout << "user =  ut_user = " << uptr->ut_user << endl;
+       // cout << "user =  ut_type = " << uptr->ut_type << endl;
+       if (uptr->ut_type == USER_PROCESS) {
+           // found someone
+           endutent();
+           return 0;
+       }
+    }
+
+    endutent();
+    return 1;
+}
 
 
 int make_socket (char *host, unsigned short int port) {
@@ -64,8 +107,11 @@ long int get_next_task( const string& host, int port, long int last_tile ) {
     fd_set ready;
     char message[256];
 
+    // loop till we get a socket connection
     while ( (sock = make_socket( host.c_str(), port )) < 0 ) {
-       // loop till we get a socket connection
+       // check if the master switch is on
+       check_master_switch();
+
        sleep(1);
     }
 
@@ -108,8 +154,7 @@ long int get_next_task( const string& host, int port, long int last_tile ) {
 
 // build the specified tile, return true if contruction completed
 // successfully
-bool construct_tile( const string& work_base, const string& output_base, 
-                    const FGBucket& b, const string& result_file ) {
+bool construct_tile( const FGBucket& b, const string& result_file ) {
     double angle = 10.0;
     bool still_trying = true;
 
@@ -117,7 +162,7 @@ bool construct_tile( const string& work_base, const string& output_base,
        still_trying = false; 
        char angle_str[256];
        sprintf(angle_str, "%.0f", angle);
-       string command = "../Main/construct ";
+       string command = "fgfs-construct ";
        command += angle_str;
        command += " " + work_base + " " + output_base + " "
            + b.gen_index_str() + " > " + result_file + " 2>&1";
@@ -130,7 +175,7 @@ bool construct_tile( const string& work_base, const string& output_base,
        while ( fgets( line, 256, fp ) != NULL ) {
            string line_str = line;
            line_str = line_str.substr(0, line_str.length() - 1);
-           cout << line_str << endl;
+           // cout << line_str << endl;
            if ( line_str == "[Finished successfully]" ) {
                fclose(fp);
                return true;
@@ -163,20 +208,28 @@ bool construct_tile( const string& work_base, const string& output_base,
 
 main(int argc, char *argv[]) {
     long int tile, last_tile;
+    bool rude = false;
     bool result;
 
     // Check usage
     if ( argc < 5 ) {
-       printf("Usage: %s remote_machine port work_base output_base\n",
+       printf("Usage: %s remote_machine port work_base output_base [ -r ]\n",
               argv[0]);
        exit(1);
     }
 
     string host = argv[1];
     int port = atoi( argv[2] );
-    string work_base = argv[3];
-    string output_base = argv[4];
-
+    work_base = argv[3];
+    output_base = argv[4];
+
+    if ( argc == 6 ) {
+       string option = argv[5];
+       if ( option == "-r" ) {
+           cout << "Running in RUDE mode!" << endl;
+           rude = true;
+       }
+    }
     // get hostname and pid
     char hostname[MAXBUF];
     gethostname( hostname, MAXBUF );
@@ -188,13 +241,28 @@ main(int argc, char *argv[]) {
 
     last_tile = 0;
 
+    // check if the master switch is on
+    check_master_switch();
+
     while ( (tile = get_next_task( host, port, last_tile )) >= 0 ) {
-       result = construct_tile( work_base, output_base, 
-                                FGBucket(tile), result_file );
+       result = construct_tile( FGBucket(tile), result_file );
        if ( result ) {
            last_tile = tile;
        } else {
            last_tile = -tile;
        }
+
+       // check if the master switch is on
+       check_master_switch();
+
+       // niceness policy: This whole process should run niced.  But
+       // additionally, if there is interactive use, we will sleep
+       // for 60 seconds between each tile to stagger out the load
+       // and impose less of an impact on the machine.
+       if ( !system_free() && !rude) {
+           cout << "System has interactive use, sleeping for " 
+                << BUSY_WAIT_TIME << " seconds..." << endl;
+           sleep( BUSY_WAIT_TIME );
+       }
     }
 }
index 66cc9b3942068afb38566350bd7d6da65d791021..f3e64c5c45317ad369dced42e1d14680b5a7b757 100644 (file)
@@ -26,7 +26,7 @@ static double lat = 0.0;
 static double lon = 0.0;
 static double dy = 0.0;
 static int pass = 0;
-
+static bool first_time = false;
 
 int make_socket (unsigned short int* port) {
     int sock;
@@ -134,7 +134,12 @@ long int get_next_tile( const string& work_base )
        // reset lat
        // lat = -89.0 + (shift_up*dy) - (dy*0.5);
        // lat = 27.0 + (0*dy) + (dy*0.5);
-       lat = 15.0 + (shift_up*dy) + (dy*0.5);
+       if ( first_time ) {
+           first_time = false;
+           lat = 54.0 + (dy*0.5);
+       } else {
+           lat = 15.0 + (shift_up*dy) + (dy*0.5);
+        }
 
        // reset lon
        FGBucket tmp( 0.0, lat );
@@ -164,7 +169,6 @@ long int get_next_tile( const string& work_base )
     }
 
     b = FGBucket( lon, lat );
-    cout << "Bucket = " << b << " (" << pass << ")" << endl;
 
     // increment to next tile
     FGBucket tmp( 0.0, lat );
@@ -264,6 +268,9 @@ int main( int argc, char **argv ) {
                next_tile = get_next_tile( work_base );
            }
 
+           cout << "Bucket = " << FGBucket(next_tile) 
+                << " (" << pass << ")" << endl;
+    
            log_pending_tile( status_dir, next_tile );
            // cout << "next tile = " << next_tile << endl;;