/[escript]/trunk/escript/src/Utils.cpp
ViewVC logotype

Diff of /trunk/escript/src/Utils.cpp

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

temp_trunk_copy/escript/src/Utils.cpp revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC trunk/escript/src/Utils.cpp revision 2313 by gross, Tue Mar 17 03:41:17 2009 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 <string.h>
16    
17  #include "Utils.h"  #include "Utils.h"
18  #include "DataVector.h"  #include "DataVector.h"
# Line 20  Line 21 
21  #include <omp.h>  #include <omp.h>
22  #endif  #endif
23    
24    #ifdef PASO_MPI
25    #include <mpi.h>
26    #endif
27    
28    #ifdef  _WIN32
29    #include <WinSock2.h>
30    #else
31    #include <unistd.h>
32    #endif
33    
34  namespace escript {  namespace escript {
35    
36  int getSvnVersion()  int getSvnVersion()
# Line 31  int getSvnVersion() Line 42  int getSvnVersion()
42  #endif  #endif
43  }  }
44    
45    /* This is probably not very robust, but it works on Savanna today and is useful for performance analysis */
46    int get_core_id() {
47      int processor_num=-1;
48    #ifdef CORE_ID1
49      FILE *fp;
50      int i, count_spaces=0;
51      char fname[100];
52      char buf[1000];
53    
54      sprintf(fname, "/proc/%d/stat", getpid());
55      fp = fopen(fname, "r");
56      if (fp == NULL) return(-1);
57      fgets(buf, 1000, fp);
58      fclose(fp);
59    
60      for (i=strlen(buf)-1; i>=0; i--) {
61        if (buf[i] == ' ') count_spaces++;
62        if (count_spaces == 4) break;
63      }
64      processor_num = atoi(&buf[i+1]);
65    #endif
66      return(processor_num);
67    }
68    
69    
70    void printParallelThreadCnt()
71    {
72      int mpi_iam=0, mpi_num=1;
73      char hname[64];
74    
75    #ifdef HAVE_GETHOSTNAME
76      gethostname(hname, 64);
77      hname[63] = '\0';
78    #else
79      strcpy(hname, "unknown host");
80    #endif
81    
82      #ifdef PASO_MPI
83      MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
84      MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
85      #endif
86    
87      #pragma omp parallel
88      {
89        int omp_iam=0, omp_num=1;
90        #ifdef _OPENMP
91        omp_iam = omp_get_thread_num(); /* Call in a parallel region */
92        omp_num = omp_get_num_threads();
93        #endif
94        printf("printParallelThreadCounts: MPI=%03d/%03d OpenMP=%03d/%03d running on %s core %d\n",
95          mpi_iam, mpi_num, omp_iam, omp_num, hname, get_core_id());
96      }
97    }
98    
99  void setNumberOfThreads(const int num_threads)  void setNumberOfThreads(const int num_threads)
100  {  {
101    
# Line 50  int getNumberOfThreads() Line 115  int getNumberOfThreads()
115    
116  }  }
117    
118    ESCRIPT_DLL_API int getMPISizeWorld() {
119      int mpi_num = 1;
120      #ifdef PASO_MPI
121      MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
122      #endif
123      return mpi_num;
124    }
125    
126    ESCRIPT_DLL_API int getMPIRankWorld() {
127      int mpi_iam = 0;
128      #ifdef PASO_MPI
129      MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
130      #endif
131      return mpi_iam;
132    }
133    
134    ESCRIPT_DLL_API int getMPIWorldMax(const int val) {
135      #ifdef PASO_MPI
136      int val2 = val;
137      int out = val;
138      MPI_Allreduce( &val2, &out, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD );
139      #else
140      int out = val;
141      #endif
142      return out;
143    }
144    
145      
146    
147    ESCRIPT_DLL_API double getMachinePrecision() {
148       return DBL_EPSILON;
149    }
150    ESCRIPT_DLL_API double getMaxFloat() {
151       return DBL_MAX;
152    }
153    ESCRIPT_DLL_API void MPIBarrierWorld() {
154      #ifdef PASO_MPI
155      MPI_Barrier(MPI_COMM_WORLD );
156      #endif
157    }
158    
159    
160  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1384  
changed lines
  Added in v.2313

  ViewVC Help
Powered by ViewVC 1.1.26