- Main Page
- Namespaces
- Classes
- Files

- Search for |

# send.cpp

    00001 /*
    00002 * <send.cpp>
    00003 * Copyright (C) DOLPHIN Project-Team, INRIA Futurs, 2006-2007
    00004 * (C) OPAC Team, LIFL, 2002-2007
    00005 *
    00006 * Sebastien Cahon, Alexandru-Adrian Tantar
    00007 *
    00008 * This software is governed by the CeCILL license under French law and
    00009 * abiding by the rules of distribution of free software.  You can  use,
    00010 * modify and/ or redistribute the software under the terms of the CeCILL
    00011 * license as circulated by CEA, CNRS and INRIA at the following URL
    00012 * "http://www.cecill.info".
    00013 *
    00014 * As a counterpart to the access to the source code and  rights to copy,
    00015 * modify and redistribute granted by the license, users are provided only
    00016 * with a limited warranty  and the software's author,  the holder of the
    00017 * economic rights,  and the successive licensors  have only  limited liability.
    00018 *
    00019 * In this respect, the user's attention is drawn to the risks associated
    00020 * with loading,  using,  modifying and/or developing or reproducing the
    00021 * software by the user in light of its specific status of free software,
    00022 * that may mean  that it is complicated to manipulate,  and  that  also
    00023 * therefore means  that it is reserved for developers  and  experienced
    00024 * professionals having in-depth computer knowledge. Users are therefore
    00025 * encouraged to load and test the software's suitability as regards their
    00026 * requirements in conditions enabling the security of their systems and/or
    00027 * data to be ensured and,  more generally, to use and operate it in the
    00028 * same conditions as regards security.
    00029 * The fact that you are presently reading this means that you have had
    00030 * knowledge of the CeCILL license and that you accept its terms.
    00031 *
    00032 * ParadisEO WebSite : http://paradiseo.gforge.inria.fr
    00033 * Contact: paradiseo-help@lists.gforge.inria.fr
    00034 *
    00035 */
    00036
    00037 #include <mpi.h>
    00038 #include <semaphore.h>
    00039 #include <queue>
    00040
    00041 #include "tags.h"
    00042 #include "comm.h"
    00043 #include "worker.h"
    00044 #include "scheduler.h"
    00045 #include "mess.h"
    00046 #include "node.h"
    00047 #include "../../core/cooperative.h"
    00048 #include "../../core/peo_debug.h"
    00049
    00050 #define TO_ALL -1
    00051
    00052 typedef struct {
    00053
    00054   Communicable * comm;
    00055   int to;
    00056   int tag;
    00057
    00058 } SEND_REQUEST;
    00059
    00060 static std :: queue <SEND_REQUEST> mess;
    00061
    00062 static sem_t sem_send;
    00063
    00064 void initSending () {
    00065
    00066   sem_init (& sem_send, 0, 1);
    00067 }
    00068
    00069 void send (Communicable * __comm, int __to, int __tag) {
    00070
    00071   SEND_REQUEST req;
    00072   req.comm = __comm;
    00073   req.to = __to;
    00074   req.tag = __tag;
    00075
    00076   sem_wait (& sem_send);
    00077   mess.push (req);
    00078   sem_post (& sem_send);
    00079   wakeUpCommunicator ();
    00080 }
    00081
    00082 void sendToAll (Communicable * __comm, int __tag) {
    00083
    00084   send (__comm, TO_ALL, __tag);
    00085 }
    00086
    00087 void sendMessages () {
    00088
    00089   sem_wait (& sem_send);
    00090
    00091   while (! mess.empty ()) {
    00092
    00093     SEND_REQUEST req = mess.front ();
    00094     /*
    00095     char b [1000];
    00096     sprintf (b, "traitement send %d\n", req.tag);
    00097     printDebugMessage (b);
    00098     */
    00099
    00100     Communicable * comm = req.comm;
    00101
    00102     initMessage ();
    00103
    00104     switch (req.tag) {
    00105
    00106     case RUNNER_STOP_TAG:
    00107       dynamic_cast <Runner *> (comm) -> packTermination ();
    00108       dynamic_cast <Runner *> (comm) -> notifySendingTermination ();
    00109       break;
    00110
    00111     case COOP_TAG:
    00112       dynamic_cast <Cooperative *> (comm) -> pack ();
    00113       dynamic_cast <Cooperative *> (comm) -> notifySending ();
    00114       break;
    00115
    00116     case SCHED_REQUEST_TAG:
    00117       dynamic_cast <Service *> (comm) -> packResourceRequest ();
    00118       dynamic_cast <Service *> (comm) -> notifySendingResourceRequest ();
    00119       break;
    00120
    00121     case TASK_RESULT_TAG:
    00122       dynamic_cast <Worker *> (comm) -> packResult ();
    00123       dynamic_cast <Worker *> (comm) -> notifySendingResult ();
    00124       break;
    00125
    00126     case TASK_DONE_TAG:
    00127       dynamic_cast <Worker *> (comm) -> packTaskDone ();
    00128       dynamic_cast <Worker *> (comm) -> notifySendingTaskDone ();
    00129       break;
    00130
    00131     default :
    00132       break;
    00133
    00134     };
    00135
    00136     if (req.to == TO_ALL)
    00137       sendMessageToAll (req.tag);
    00138     else
    00139       sendMessage (req.to, req.tag);
    00140     mess.pop ();
    00141   }
    00142
    00143   sem_post (& sem_send);
    00144 }