"Fossies" - the Fresh Open Source Software Archive

Member "NetPIPE-3.7.2/src/pvm.c" (19 Aug 2010, 8024 Bytes) of package /linux/privat/old/NetPIPE-3.7.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pvm.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.x_vs_3.7.2.

    1 /*****************************************************************************/
    2 /* "NetPIPE" -- Network Protocol Independent Performance Evaluator.          */
    3 /* Copyright 1997, 1998 Iowa State University Research Foundation, Inc.      */
    4 /*                                                                           */
    5 /* This program is free software; you can redistribute it and/or modify      */
    6 /* it under the terms of the GNU General Public License as published by      */
    7 /* the Free Software Foundation.  You should have received a copy of the     */
    8 /* GNU General Public License along with this program; if not, write to the  */
    9 /* Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   */
   10 /*                                                                           */
   11 /*     * pvm.c              ---- PVM calls source                            */
   12 /*****************************************************************************/
   13 #include    "netpipe.h"
   14 #include    <pvm3.h>
   15 
   16 #ifndef lint
   17 static const char rcsid[] =
   18     "$Id: pvm.c,v 1.7 2003/12/10 00:52:25 turner Exp $";
   19 #endif
   20 
   21 
   22 /**********************************************************************/
   23 /* Initialialization that needs to occur before                       */
   24 /* command args are parsed                                            */
   25 /**********************************************************************/
   26 void
   27 Init(ArgStruct *p, int* pargc, char*** pargv)
   28 {
   29    p->tr = 0;     /* The transmitter will be set using the -h host flag. */
   30    p->rcv = 1;
   31 }
   32 
   33 /**********************************************************************/
   34 /* Set up the communcations system.                                   */
   35 /*    In pvm, this means to join the parallel machine                 */
   36 /**********************************************************************/
   37 void
   38 Setup(ArgStruct *p)
   39 {
   40     p->prot.mytid = pvm_mytid();
   41 #ifdef DEBUG
   42     printf("My task id is %d \n",p->prot.mytid);
   43 #endif
   44 
   45     establish(p);
   46 }   
   47 
   48 /**********************************************************************/
   49 /* Establish a link with the other processor                          */
   50 /*    In pvm, this means to send a simple message, but to keep the    */
   51 /*    communication line open.  Since the assumption is that we are   */
   52 /*    starting it by hand on the other machine, we don't know what    */
   53 /*    the other task id is.                                           */
   54 /**********************************************************************/
   55 
   56 void establish(ArgStruct *p)
   57 {
   58     /* Task information for the entire parallel machine (if trans) */
   59     int                     tasks_status;
   60     struct pvmtaskinfo      *taskp;
   61     int                     ntasks;
   62 
   63         /* Received buffer (if receiver)  */
   64     int buffer_id;
   65 
   66     /*
   67         If we are the transmitting side, go find the other one and send
   68         it a message containing our tid. If we are the receiving side,
   69         just wait for a message.
   70     */
   71     if ( p->tr ) {
   72 #ifdef DEBUG
   73         printf("this is the transmitter\n");
   74 #endif
   75         tasks_status = pvm_tasks( 0, &ntasks, &taskp );
   76         if ( ntasks != 2 ) {
   77             printf("Error, too many processes in parallel machine \n");
   78             printf("Start a clean machine.  n=%d\n", ntasks);
   79             exit(-1);
   80         }
   81 
   82             /* Since there are two tasks, one is ours the other is the receiver */
   83 
   84         p->prot.othertid = -1;
   85         if ( taskp[0].ti_tid == p->prot.mytid ) {
   86             p->prot.othertid = taskp[1].ti_tid;
   87         }
   88         if ( taskp[1].ti_tid == p->prot.mytid ) {
   89             p->prot.othertid = taskp[0].ti_tid;
   90         }
   91         if ( p->prot.othertid == -1 ) {
   92             printf("Error, cannot find other (receiving) task \n");
   93             printf("Id's:  %d %d  \n",taskp[0].ti_tid,taskp[1].ti_tid);
   94         }
   95 
   96             /* Send the receiver a message.  Tell pvm to keep the channel open */
   97 
   98 #ifdef DEBUG
   99         printf("The receiver tid is %d \n",p->prot.othertid);
  100 #endif
  101 
  102            /* PVMDATA is defined in netpipe.h, choose wisely (PvmDataInPlace)
  103             * Also use PvmRouteDirect, otherwise the data goes through the
  104             * pvmd daemons which kills performance.
  105             */
  106 
  107         pvm_setopt( PvmRoute, PvmRouteDirect );
  108         pvm_initsend( PVMDATA );
  109 
  110         pvm_pkint( &p->prot.mytid, 1, 1 );
  111         pvm_send( p->prot.othertid, 1 );
  112     } else {
  113 #ifdef DEBUG
  114         printf("This is the receiver \n");
  115 #endif
  116                 
  117             /* Receive any message from any task */
  118 
  119         buffer_id = pvm_recv(-1, -1);
  120 
  121         if ( buffer_id < 0 ) {
  122         printf("Error on receive in receiver\n");
  123         exit(-1);
  124         }
  125         pvm_upkint( &p->prot.othertid, 1, 1 );
  126     }
  127 }
  128 
  129 /**********************************************************************/
  130 /* Prepare to receive                                                 */
  131 /*    In pvm, you cannot set up a reception buffer ahead of time      */
  132 /**********************************************************************/
  133 void
  134 PrepareToReceive(ArgStruct *p)
  135 {
  136 }
  137 
  138 /**********************************************************************/
  139 /* Synchronize                                                        */
  140 /*     In pvm, this is not necessary                                  */
  141 /**********************************************************************/
  142 void
  143 Sync(ArgStruct *p)
  144 {
  145 }
  146 
  147 /**********************************************************************/
  148 /* Send a buffer full of information                                  */
  149 /*    In pvm, we use pvm_pkbyte and then send it.                     */
  150 /**********************************************************************/
  151 void
  152 SendData(ArgStruct *p)
  153 {
  154 #ifdef DEBUG
  155     printf(" In send \n");
  156 #endif
  157     pvm_initsend( PVMDATA );
  158     pvm_pkbyte( p->s_ptr, p->bufflen, 1 );
  159     pvm_send( p->prot.othertid, 1 );
  160 #ifdef DEBUG
  161     printf(" message sent.  Size=%d\n",p->bufflen);
  162 #endif
  163 }
  164 
  165 /**********************************************************************/
  166 /* Receive a buffer full of information                               */
  167 /**********************************************************************/
  168 void
  169 RecvData(ArgStruct *p)
  170 {
  171 #ifdef DEBUG
  172     printf(" In receive \n");
  173 #endif
  174     pvm_recv( -1, -1);
  175     pvm_upkbyte( p->r_ptr, p->bufflen, 1);
  176 #ifdef DEBUG
  177     printf(" message received .  Size=%d \n", p->bufflen);
  178 #endif
  179 }
  180 
  181 /**********************************************************************/
  182 /* Send elapsed time to the other process                             */
  183 /**********************************************************************/
  184 void
  185 SendTime(ArgStruct *p, double *t)
  186 {
  187     pvm_initsend( PVMDATA );
  188     pvm_pkdouble( t, 1, 1 );
  189     pvm_send( p->prot.othertid, 1);
  190 }
  191 
  192 /**********************************************************************/
  193 /* Receive elapsed time from the other process                        */
  194 /**********************************************************************/
  195 void
  196 RecvTime(ArgStruct *p, double *t)
  197 {
  198     pvm_recv(-1, -1);
  199     pvm_upkdouble( t, 1, 1 );
  200 }
  201 
  202 /**********************************************************************/
  203 /* Send repeat count to the other process                             */
  204 /**********************************************************************/
  205 void
  206 SendRepeat(ArgStruct *p, int rpt)
  207 {
  208     pvm_initsend( PVMDATA );
  209     pvm_pkint( &rpt, 1, 1 );
  210     pvm_send( p->prot.othertid, 1);
  211 }
  212 
  213 /**********************************************************************/
  214 /* Receiver repeat count from other process                           */
  215 /**********************************************************************/
  216 void
  217 RecvRepeat(ArgStruct *p, int *rpt)
  218 {
  219     pvm_recv(-1, -1);
  220     pvm_upkint( rpt, 1, 1 );
  221 }
  222 
  223 /**********************************************************************/
  224 /* Close down the connection.
  225 /**********************************************************************/
  226 void
  227 CleanUp(ArgStruct *p)
  228 {
  229 }
  230 
  231 
  232 void Reset(ArgStruct *p)
  233 {
  234 
  235 }
  236 
  237 void AfterAlignmentInit(ArgStruct *p)
  238 {
  239 
  240 }
  241