/[escript]/trunk/paso/src/Paso_MPI.c
ViewVC logotype

Diff of /trunk/paso/src/Paso_MPI.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1347 by ksteube, Fri Nov 16 05:37:07 2007 UTC revision 2126 by ksteube, Thu Dec 4 00:13:03 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #include <stdlib.h>  #include <stdlib.h>
16  #include <stdio.h>  #include <stdio.h>
# Line 24  Line 23 
23  /* allocate memory for an mpi_comm, and find the communicator details */  /* allocate memory for an mpi_comm, and find the communicator details */
24  Paso_MPIInfo* Paso_MPIInfo_alloc( MPI_Comm comm )  Paso_MPIInfo* Paso_MPIInfo_alloc( MPI_Comm comm )
25  {  {
26    int error;    #ifdef PASO_MPI
27        int error;
28      #endif
29    
30    Paso_MPIInfo *out=NULL;    Paso_MPIInfo *out=NULL;
31    
32    out = MEMALLOC( 1, Paso_MPIInfo );    out = MEMALLOC( 1, Paso_MPIInfo );
# Line 98  dim_t Paso_MPIInfo_setDistribution(Paso_ Line 100  dim_t Paso_MPIInfo_setDistribution(Paso_
100     dim_t out;     dim_t out;
101     int s=mpi_info->size;     int s=mpi_info->size;
102     dim_t N=max_id-min_id+1;     dim_t N=max_id-min_id+1;
103     int local_N=N/s;     if (N>0) {
104     rest=N-local_N*s;        int local_N=N/s;
105     for (p=0; p<s; ++p) {        rest=N-local_N*s;
106        if (p<rest) {        for (p=0; p<s; ++p) {
107            distribution[p]=min_id+(local_N+1)*p;           if (p<rest) {
108            out=local_N+1;               distribution[p]=min_id+(local_N+1)*p;
109                 out=local_N+1;
110             } else {
111                 distribution[p]=min_id+rest+local_N*p;
112             }
113          }
114          distribution[s]=max_id+1;
115          if (rest==0) {
116             return local_N;
117        } else {        } else {
118            distribution[p]=min_id+rest+local_N*p;           return local_N+1;
119        }        }
120     }    } else {
121     distribution[s]=max_id+1;        for (p=0; p<s+1; ++p) distribution[p]=min_id;
122     if (rest==0) {        return 0;
123        return local_N;    }
    } else {  
       return local_N+1;  
    }  
124  }  }
125    
126  /* checks that there is no error accross all processes in a communicator */  /* checks that there is no error accross all processes in a communicator */
127  /* NOTE : does not make guarentee consistency of error string on each process */  /* NOTE : does not make guarentee consistency of error string on each process */
128  bool_t Paso_MPIInfo_noError( Paso_MPIInfo *mpi_info )  bool_t Paso_MPIInfo_noError( Paso_MPIInfo *mpi_info )
129  {  {
130    int errorLocal = 0;    int errorLocal = Paso_noError() ? 0 : 1;
131    int errorGlobal= 0;    int errorGlobal = errorLocal;
132    errorLocal= Paso_noError() ? 0 : 1;  #if 0
133    #ifdef PASO_MPI
134    if (mpi_info->size>1) {    if (mpi_info->size>1) {
      #ifdef PASO_MPI  
 #if 1 /* ksteube disable error checking during benchmarking activities */  
135       MPI_Allreduce( &errorLocal, &errorGlobal, 1, MPI_INT, MPI_MAX, mpi_info->comm  );       MPI_Allreduce( &errorLocal, &errorGlobal, 1, MPI_INT, MPI_MAX, mpi_info->comm  );
 #else  
      errorGlobal=errorLocal;  
 #endif  
      #else  
      errorGlobal=errorLocal;  
      #endif  
      /* take care of the case where the error was on another processor */  
      if( (errorLocal==0) && (errorGlobal==1) ) {  
          Paso_setError( PASO_MPI_ERROR, "Paso_MPI_noError() : there was an error on another MPI process" );  
      }  
136    }    }
137      if( (errorLocal==0) && (errorGlobal==1) ) {
138         Paso_setError( PASO_MPI_ERROR, "Paso_MPI_noError() : there was an error on another MPI process" );
139      }
140    #endif
141    #endif
142    return (errorGlobal==0);    return (errorGlobal==0);
143  }  }
144    
   
145  /**************************************************  /**************************************************
146                   WRAPPERS                   WRAPPERS
147  **************************************************/  **************************************************/
148    
149  int Paso_MPIInfo_initialized( void )  int Paso_MPIInfo_initialized( void )
150  {  {
   int error=0, initialised=0;  
   
151    #ifdef PASO_MPI    #ifdef PASO_MPI
152         int error=0, initialised=0;
153       error = MPI_Initialized( &initialised );       error = MPI_Initialized( &initialised );
154       if( error!=MPI_SUCCESS )       if( error!=MPI_SUCCESS )
155           Paso_setError( PASO_MPI_ERROR, "mpi_initialised : MPI error" );           Paso_setError( PASO_MPI_ERROR, "mpi_initialised : MPI error" );
# Line 161  int Paso_MPIInfo_initialized( void ) Line 160  int Paso_MPIInfo_initialized( void )
160  }  }
161    
162  /* Append MPI rank to file name if multiple MPI processes */  /* Append MPI rank to file name if multiple MPI processes */
163  char *Paso_MPI_appendRankToFileName(char *fileName, int mpi_size, int mpi_rank) {  char *Paso_MPI_appendRankToFileName(const char *fileName, int mpi_size, int mpi_rank) {
164    char *newFileName = TMPMEMALLOC(4096,char);    /* Make plenty of room for the mpi_rank number and terminating '\0' */
165      char *newFileName = TMPMEMALLOC(strlen(fileName)+20,char);
166    strncpy(newFileName, fileName, strlen(fileName)+1);    strncpy(newFileName, fileName, strlen(fileName)+1);
167    if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);    if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);
168    return(newFileName);    return(newFileName);

Legend:
Removed from v.1347  
changed lines
  Added in v.2126

  ViewVC Help
Powered by ViewVC 1.1.26