"Fossies" - the Fresh Open Source Software Archive

Member "NetPIPE-3.7.2/src/mpi.c" (19 Aug 2010, 4652 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 "mpi.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 /*     * MPI.c              ---- MPI calls source                            */
   12 /*****************************************************************************/
   13 #include    "netpipe.h"
   14 #include    <mpi.h>
   15 
   16 #ifdef BSEND
   17 char *messbuff;
   18 #define MAXBUFSIZE (10*1024*1024)
   19 #endif
   20 
   21 
   22 /* Initialize vars in Init() that may be changed by parsing the command args */
   23 
   24 void Init(ArgStruct *p, int* pargc, char*** pargv)
   25 {
   26   p->source_node = 0;  /* Default source node */
   27 
   28   MPI_Init(pargc, pargv);
   29 }
   30 
   31 void Setup(ArgStruct *p)
   32 {
   33     int nprocs;
   34 
   35     MPI_Comm_rank(MPI_COMM_WORLD, &p->prot.iproc);
   36     MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
   37 
   38     {
   39         char s[255], *ptr;
   40         gethostname(s,253);
   41         if( s[0] != '.' ) {                 /* just print the base name */
   42            ptr = strchr( s, '.');
   43            if( ptr != NULL ) *ptr = '\0';
   44         }
   45         printf("%d: %s\n",p->prot.iproc,s);
   46         fflush(stdout);
   47     }
   48 
   49     if (nprocs < 2)
   50     {
   51         printf("Need at least two processes (only given %d)\n", nprocs);
   52         exit(-2);
   53     }
   54 
   55     p->tr = p->rcv = 0;
   56     if( p->prot.iproc == 0 ) {
   57         p->tr = 1;
   58         p->prot.nbor = nprocs-1;
   59     } else if( p->prot.iproc == nprocs-1 ) {
   60         p->rcv = 1;
   61         p->prot.nbor = 0;
   62     }
   63 
   64        /* p->source_node may already have been set to -1 (MPI_ANY_SOURCE)
   65         * by specifying a -z on the command line.  If not, set the source
   66         * node normally. */
   67 
   68     if( p->source_node == 0 ) p->source_node = p->prot.nbor;
   69 
   70 #ifdef BSEND
   71     messbuff = (char *)malloc(MAXBUFSIZE * sizeof(char));
   72     if (messbuff == NULL)
   73     {
   74         printf("Can't allocate for message buffer\n");
   75         exit(-1);
   76     }
   77     MPI_Buffer_attach(messbuff, MAXBUFSIZE);
   78     p->upper = MAXBUFSIZE;
   79 #endif
   80 
   81     if( p->bidir ) {
   82         printf("MPI implementations do not have to guarantee message progress.\n");
   83         printf("You may need to run using -a to avoid locking up.\n\n");
   84     }
   85 }   
   86 
   87 void Sync(ArgStruct *p)
   88 {
   89     MPI_Barrier(MPI_COMM_WORLD);
   90 }
   91 
   92 static int recvPosted = 0;
   93 static MPI_Request recvRequest;
   94 
   95 void PrepareToReceive(ArgStruct *p)
   96 {
   97     /*
   98       Providing a buffer for reception of data in advance of
   99       the sender sending the data provides a major performance
  100       boost on some implementations of MPI, particularly shared
  101       memory implementations on the Cray T3E and Intel Paragon.
  102     */
  103     if (recvPosted)
  104     {
  105         printf("Can't prepare to receive: outstanding receive!\n");
  106         exit(-1);
  107     }
  108     MPI_Irecv(p->r_ptr, p->bufflen, MPI_BYTE,
  109     p->source_node, 1, MPI_COMM_WORLD, &recvRequest);
  110     recvPosted = -1;
  111 }
  112 
  113 void SendData(ArgStruct *p)
  114 {
  115 #ifdef BSEND
  116     MPI_Bsend(p->s_ptr, p->bufflen, MPI_BYTE, p->prot.nbor, 1, MPI_COMM_WORLD);
  117 #else
  118    if(p->syncflag)
  119       MPI_Ssend(p->s_ptr,p->bufflen, MPI_BYTE, p->prot.nbor,1,MPI_COMM_WORLD);
  120    else
  121       MPI_Send(p->s_ptr, p->bufflen, MPI_BYTE, p->prot.nbor, 1, MPI_COMM_WORLD);
  122 #endif
  123 }
  124 
  125 void RecvData(ArgStruct *p)
  126 {
  127     MPI_Status status;
  128     if (recvPosted)
  129     {
  130         MPI_Wait(&recvRequest, &status);
  131         recvPosted = 0;
  132     }
  133     else
  134     {
  135         MPI_Recv(p->r_ptr, p->bufflen, MPI_BYTE, 
  136         p->source_node, 1, MPI_COMM_WORLD, &status);
  137     }
  138 }
  139 
  140 
  141 void SendTime(ArgStruct *p, double *t)
  142 {
  143     MPI_Send(t, 1, MPI_DOUBLE, p->prot.nbor, 2, MPI_COMM_WORLD);
  144 }
  145 
  146 void RecvTime(ArgStruct *p, double *t)
  147 {
  148     MPI_Status status;
  149 
  150     MPI_Recv(t, 1, MPI_DOUBLE, p->prot.nbor, 2, MPI_COMM_WORLD, &status);
  151 }
  152 
  153 
  154 void SendRepeat(ArgStruct *p, int rpt)
  155 {
  156     MPI_Send(&rpt, 1, MPI_INT, p->prot.nbor, 2, MPI_COMM_WORLD);
  157 }
  158 
  159 void RecvRepeat(ArgStruct *p, int *rpt)
  160 {
  161     MPI_Status status;
  162 
  163     MPI_Recv(rpt, 1, MPI_INT, p->source_node, 2, MPI_COMM_WORLD, &status);
  164 }
  165 
  166 void CleanUp(ArgStruct *p)
  167 {
  168    MPI_Finalize();
  169 }
  170 
  171 
  172 
  173 void Reset(ArgStruct *p)
  174 {
  175 
  176 }
  177 
  178 void AfterAlignmentInit(ArgStruct *p)
  179 {
  180 
  181 }
  182