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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1620 - (show annotations)
Fri Jun 27 02:30:18 2008 UTC (11 years, 5 months ago) by ksteube
File size: 2112 byte(s)
Included more MPI configuration options on Savanna

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include "Utils.h"
17 #include "DataVector.h"
18
19 #ifdef _OPENMP
20 #include <omp.h>
21 #endif
22
23 #ifdef PASO_MPI
24 #include <mpi.h>
25 #endif
26
27 namespace escript {
28
29 int getSvnVersion()
30 {
31 #ifdef SVN_VERSION
32 return SVN_VERSION;
33 #else
34 return 0;
35 #endif
36 }
37
38 /* This is probably not very robust, but it works on Savanna today and is useful for performance analysis */
39 int get_core_id() {
40 int processor_num=-1;
41 #ifdef CORE_ID1
42 FILE *fp;
43 int i, count_spaces=0;
44 char fname[100];
45 char buf[1000];
46
47 sprintf(fname, "/proc/%d/stat", getpid());
48 fp = fopen(fname, "r");
49 if (fp == NULL) return(-1);
50 fgets(buf, 1000, fp);
51 fclose(fp);
52
53 for (i=strlen(buf)-1; i>=0; i--) {
54 if (buf[i] == ' ') count_spaces++;
55 if (count_spaces == 4) break;
56 }
57 processor_num = atoi(&buf[i+1]);
58 #endif
59 return(processor_num);
60 }
61
62
63 void printParallelThreadCnt()
64 {
65 int mpi_iam=0, mpi_num=1;
66 char hname[64];
67
68 gethostname(hname, 64);
69
70 #ifdef PASO_MPI
71 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
72 MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
73 #endif
74
75 #ifdef _OPENMP
76 #pragma omp parallel
77 #endif
78 {
79 int omp_iam=0, omp_num=1;
80 #ifdef _OPENMP
81 omp_iam = omp_get_thread_num(); /* Call in a parallel region */
82 omp_num = omp_get_num_threads();
83 #endif
84 printf("printParallelThreadCounts: MPI=%03d/%03d OpenMP=%03d/%03d running on %s core %d\n",
85 mpi_iam, mpi_num, omp_iam, omp_num, hname, get_core_id());
86 }
87 }
88
89 void setNumberOfThreads(const int num_threads)
90 {
91
92 #ifdef _OPENMP
93 omp_set_num_threads(num_threads);
94 #endif
95
96 }
97
98 int getNumberOfThreads()
99 {
100 #ifdef _OPENMP
101 return omp_get_max_threads();
102 #else
103 return 1;
104 #endif
105
106 }
107
108 } // end of namespace

  ViewVC Help
Powered by ViewVC 1.1.26