/[escript]/branches/arrayview_from_1695_trunk/escript/src/Utils.cpp
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/Utils.cpp

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

trunk/escript/src/Utils.cpp revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC branches/arrayview_from_1695_trunk/escript/src/Utils.cpp revision 1781 by jfenwick, Thu Sep 11 05:03:14 2008 UTC
# Line 20  Line 20 
20  #include <omp.h>  #include <omp.h>
21  #endif  #endif
22    
23    #ifdef PASO_MPI
24    #include <mpi.h>
25    #endif
26    
27    #ifdef  _WIN32
28    #include <WinSock2.h>
29    #endif
30    
31  namespace escript {  namespace escript {
32    
33  int getSvnVersion()  int getSvnVersion()
# Line 31  int getSvnVersion() Line 39  int getSvnVersion()
39  #endif  #endif
40  }  }
41    
42    /* This is probably not very robust, but it works on Savanna today and is useful for performance analysis */
43    int get_core_id() {
44      int processor_num=-1;
45    #ifdef CORE_ID1
46      FILE *fp;
47      int i, count_spaces=0;
48      char fname[100];
49      char buf[1000];
50    
51      sprintf(fname, "/proc/%d/stat", getpid());
52      fp = fopen(fname, "r");
53      if (fp == NULL) return(-1);
54      fgets(buf, 1000, fp);
55      fclose(fp);
56    
57      for (i=strlen(buf)-1; i>=0; i--) {
58        if (buf[i] == ' ') count_spaces++;
59        if (count_spaces == 4) break;
60      }
61      processor_num = atoi(&buf[i+1]);
62    #endif
63      return(processor_num);
64    }
65    
66    
67    void printParallelThreadCnt()
68    {
69      int mpi_iam=0, mpi_num=1;
70      char hname[64];
71    
72    #ifdef HAVE_GETHOSTNAME
73      gethostname(hname, 64);
74    #else
75      strcpy(hname, "unknown host");
76    #endif
77    
78      #ifdef PASO_MPI
79      MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
80      MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
81      #endif
82    
83      #pragma omp parallel
84      {
85        int omp_iam=0, omp_num=1;
86        #ifdef _OPENMP
87        omp_iam = omp_get_thread_num(); /* Call in a parallel region */
88        omp_num = omp_get_num_threads();
89        #endif
90        printf("printParallelThreadCounts: MPI=%03d/%03d OpenMP=%03d/%03d running on %s core %d\n",
91          mpi_iam, mpi_num, omp_iam, omp_num, hname, get_core_id());
92      }
93    }
94    
95  void setNumberOfThreads(const int num_threads)  void setNumberOfThreads(const int num_threads)
96  {  {
97    

Legend:
Removed from v.1388  
changed lines
  Added in v.1781

  ViewVC Help
Powered by ViewVC 1.1.26