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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1561 - (show annotations)
Wed May 21 06:58:52 2008 UTC (11 years, 4 months ago) by ksteube
File size: 1440 byte(s)
Added python method printParallelThreadCounts() to tell how many MPI CPUs and OpenMP threads we are using (for testing hybrid runs)

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 void printParallelThreadCnt()
39 {
40 int mpi_iam=0, mpi_num=1;
41
42 #ifdef PASO_MPI
43 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_iam);
44 MPI_Comm_size(MPI_COMM_WORLD, &mpi_num);
45 #endif
46
47 #ifdef _OPENMP
48 #pragma omp parallel
49 #endif
50 {
51 int omp_iam=0, omp_num=1;
52 #ifdef _OPENMP
53 omp_iam = omp_get_thread_num(); /* Call in a parallel region */
54 omp_num = omp_get_num_threads();
55 #endif
56 printf("printParallelThreadCounts: OpenMP=%d/%d MPI=%d/%d\n", omp_iam, omp_num, mpi_iam, mpi_num);
57 }
58 }
59
60 void setNumberOfThreads(const int num_threads)
61 {
62
63 #ifdef _OPENMP
64 omp_set_num_threads(num_threads);
65 #endif
66
67 }
68
69 int getNumberOfThreads()
70 {
71 #ifdef _OPENMP
72 return omp_get_max_threads();
73 #else
74 return 1;
75 #endif
76
77 }
78
79 } // end of namespace

  ViewVC Help
Powered by ViewVC 1.1.26