/[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 1312 by ksteube, Mon Sep 24 06:18:44 2007 UTC revision 1981 by jfenwick, Thu Nov 6 05:27:33 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>
17    #include <string.h>
18    
19    
20  #include "Paso_MPI.h"  #include "Paso_MPI.h"
# Line 23  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 97  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 */
# Line 147  bool_t Paso_MPIInfo_noError( Paso_MPIInf Line 155  bool_t Paso_MPIInfo_noError( Paso_MPIInf
155    
156  int Paso_MPIInfo_initialized( void )  int Paso_MPIInfo_initialized( void )
157  {  {
   int error=0, initialised=0;  
   
158    #ifdef PASO_MPI    #ifdef PASO_MPI
159         int error=0, initialised=0;
160       error = MPI_Initialized( &initialised );       error = MPI_Initialized( &initialised );
161       if( error!=MPI_SUCCESS )       if( error!=MPI_SUCCESS )
162           Paso_setError( PASO_MPI_ERROR, "mpi_initialised : MPI error" );           Paso_setError( PASO_MPI_ERROR, "mpi_initialised : MPI error" );
# Line 158  int Paso_MPIInfo_initialized( void ) Line 165  int Paso_MPIInfo_initialized( void )
165       return TRUE;       return TRUE;
166    #endif    #endif
167  }  }
168    
169    /* Append MPI rank to file name if multiple MPI processes */
170    char *Paso_MPI_appendRankToFileName(const char *fileName, int mpi_size, int mpi_rank) {
171      /* Make plenty of room for the mpi_rank number and terminating '\0' */
172      char *newFileName = TMPMEMALLOC(strlen(fileName)+20,char);
173      strncpy(newFileName, fileName, strlen(fileName)+1);
174      if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);
175      return(newFileName);
176    }
177    

Legend:
Removed from v.1312  
changed lines
  Added in v.1981

  ViewVC Help
Powered by ViewVC 1.1.26