00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <mpi.h>
00011
00012 #include "comm.h"
00013 #include "mess.h"
00014 #include "node.h"
00015 #include "param.h"
00016 #include "../../core/peo_debug.h"
00017 #include "../../core/runner.h"
00018 #include "send.h"
00019 #include "recv.h"
00020 #include "scheduler.h"
00021
00022 static sem_t sem_comm_init;
00023
00024 static Communicator * the_thread;
00025
00026 Communicator :: Communicator (int * __argc, char * * * __argv) {
00027
00028 the_thread = this;
00029 initNode (__argc, __argv);
00030 loadRMCParameters (* __argc, * __argv);
00031 sem_post (& sem_comm_init);
00032 }
00033
00034 void Communicator :: start () {
00035
00036 while (true) {
00037
00038
00039 sleep ();
00040 sendMessages ();
00041
00042 if (! atLeastOneActiveRunner ())
00043 break;
00044 receiveMessages ();
00045 }
00046 waitBuffers ();
00047 printDebugMessage ("finalizing");
00048 MPI_Finalize ();
00049 }
00050
00051 void initCommunication () {
00052
00053 sem_init (& sem_comm_init, 0, 0);
00054 }
00055
00056 void waitNodeInitialization () {
00057
00058 sem_wait (& sem_comm_init);
00059 }
00060
00061 void wakeUpCommunicator () {
00062
00063 the_thread -> wakeUp ();
00064 }
00065
00066
00067