Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

scatter3_slave.C

Go to the documentation of this file.
00001 
00002 // scatter3_pvm.C: Perform three-body scattering experiments.
00003 //
00004 // Input is an initial state, output is intermediate and final states.
00005 // All data are received and returned via PVM message-passing calls.
00006 // 
00007 // Note the function scatter3 is completely deterministic.
00008 // No randomization is performed at this level.
00009 
00010 #ifdef HAS_PVM
00011 
00012 #include "scatter3.h"
00013 #include "pvm_scatt.h"
00014 #include "pvm3.h"
00015 #include <unistd.h>
00016 
00017 extern "C" int gethostname(char*, unsigned int);
00018 
00019 #define FORCE_TIMEOUT   0
00020 #define TIME_TIMEOUT    100     // (seconds)
00021 
00022 void main()
00023 {
00024     // Start by echoing our hostname back to the parent process.
00025 
00026     char name[100];
00027     gethostname(name, 100);
00028 
00029     pvm_initsend(PvmDataRaw);
00030     pvm_pkstr(name);
00031     pvm_send(pvm_parent(), HANDSHAKE_MSG);
00032 
00033     while (1) {
00034 
00035         // Pick up the next message from parent and act accordingly.
00036 
00037         int bufid = pvm_recv(pvm_parent(), -1);
00038 
00039         int length, msgid, source;
00040         int info = pvm_bufinfo(bufid, &length, &msgid, &source);
00041 
00042         if (info < 0 || msgid != SEND_DATA_MSG || source != pvm_parent()) {
00043             pvm_exit();
00044             exit(0);
00045         }
00046 
00047         // Unpack the data.
00048 
00049         int n_rand;
00050         pvm_upkint(&n_rand, 1, 1);
00051 
00052         initial_state3 init;
00053         unpack(init);
00054 
00055         real cpu_time_check, dt_out, dt_snap, snap_cube_size;
00056         pvm_upkdouble(&cpu_time_check, 1, 1);
00057         pvm_upkdouble(&dt_snap, 1, 1);
00058         pvm_upkdouble(&snap_cube_size, 1, 1);
00059 
00060         // cerr << "unpacked data: m2, m3 = " << init.m2 <<" "<< init.m3
00061         //      << endl;
00062         // cerr << "starting scattering..." << endl << flush;
00063 
00064         // Perform the scattering.
00065 
00066         intermediate_state3 inter;
00067         final_state3 final;
00068         real cpu_scatter = cpu_time();
00069 
00070         int result = single_scatter(init, inter, final,
00071                                     cpu_time_check, dt_snap, snap_cube_size);
00072         cpu_scatter = cpu_time() - cpu_scatter;
00073 
00074         // cerr << "...back" << endl;
00075         // cerr << "cpu time = " << cpu_scatter << endl << flush;
00076 
00077 #if FORCE_TIMEOUT
00078 
00079         // Temporary only...
00080 
00081         if (cpu_scatter > TIME_TIMEOUT) {
00082 
00083             // Force a timeout: waste a lot of time...
00084 
00085             real x = 0;
00086             for (int j = 0; j < 1000000; j++)
00087                 for (int i = 0; i < 1000000000; i++)
00088                     x += sqrt(0.1*i + j);
00089 
00090             cpu_scatter = x;
00091 
00092         }
00093 
00094 #endif
00095 
00096         // Return the results.
00097 
00098         pvm_initsend(PvmDataRaw);
00099 
00100         pvm_pkint(&n_rand, 1, 1);
00101 
00102         pack(init);
00103         pack(inter);
00104         pack(final);
00105 
00106         pvm_pkint(&result, 1, 1);
00107         pvm_pkdouble(&cpu_scatter, 1, 1);
00108 
00109         // Send the data as message RETURN_DATA_MSG.
00110 
00111         if (pvm_send(pvm_parent(), RETURN_DATA_MSG) < 0) {
00112             cerr << "Error returning data from " << name << endl;
00113             cerr << "CPU time = " << cpu_scatter << endl;
00114         }
00115 
00116     }
00117 }
00118 
00119 #else
00120 
00121 #include "stdinc.h"
00122 
00123 void main()
00124 {
00125     err_exit("PVM not available");
00126 }
00127 
00128 #endif

Generated at Sun Feb 24 09:57:14 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001