/[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 1343 by ksteube, Wed Nov 14 02:48:02 2007 UTC revision 1811 by ksteube, Thu Sep 25 23:11:13 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 */
# Line 161  int Paso_MPIInfo_initialized( void ) Line 168  int Paso_MPIInfo_initialized( void )
168  }  }
169    
170  /* Append MPI rank to file name if multiple MPI processes */  /* Append MPI rank to file name if multiple MPI processes */
171  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) {
172    char newFileName[4096];    /* Make plenty of room for the mpi_rank number and terminating '\0' */
173      char *newFileName = TMPMEMALLOC(strlen(fileName)+20,char);
174    strncpy(newFileName, fileName, strlen(fileName)+1);    strncpy(newFileName, fileName, strlen(fileName)+1);
175    if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);    if (mpi_size>1) sprintf(newFileName+strlen(newFileName), ".%04d", mpi_rank);
176    return(newFileName);    return(newFileName);

Legend:
Removed from v.1343  
changed lines
  Added in v.1811

  ViewVC Help
Powered by ViewVC 1.1.26