Repository navigation
Expand file tree
/
Copy pathutils.cpp
More file actions
146 lines (127 loc) · 4.95 KB
/
Copy pathutils.cpp
File metadata and controls
146 lines (127 loc) · 4.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//@HEADER
// ************************************************************************
//
// MiniFE: Simple Finite Element Assembly and Solve
// Copyright (2006-2013) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
// ************************************************************************
//@HEADER
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#ifdef HAVE_MPI
#include <mpi.h>
#endif
#ifdef MINIFE_HAVE_TPI
#include <TPI.h>
#endif
#ifdef MINIFE_HAVE_TBB
#include <tbb/task_scheduler_init.h>
#endif
#include <param_utils.hpp>
#include <Parameters.hpp>
#include <utils.hpp>
namespace miniFE {
//-------------------------------------------------------------
void get_parameters(int argc, char** argv, Parameters& params)
{
std::string argstring;
Mantevo::read_args_into_string(argc, argv, argstring);
std::string garbage("garbage");
std::string filename =
Mantevo::parse_parameter<std::string>(argstring, "input_file", garbage);
if (filename != garbage) {
Mantevo::read_file_into_string(filename, argstring);
}
params.nx = Mantevo::parse_parameter<int>(argstring, "nx", 10);
params.ny = Mantevo::parse_parameter<int>(argstring, "ny", params.nx);
params.nz = Mantevo::parse_parameter<int>(argstring, "nz", params.ny);
params.load_imbalance =
Mantevo::parse_parameter<float>(argstring, "load_imbalance", 0);
params.numthreads = Mantevo::parse_parameter<int>(argstring, "numthreads", 1);
params.mv_overlap_comm_comp = Mantevo::parse_parameter<int>(argstring, "mv_overlap_comm_comp", 0);
params.use_locking = Mantevo::parse_parameter<int>(argstring, "use_locking", 0);
params.name = Mantevo::parse_parameter<std::string>(argstring, "name","");
params.elem_group_size = Mantevo::parse_parameter<int>(argstring, "elem_group_size", 1);
params.use_elem_mat_fields = Mantevo::parse_parameter<int>(argstring, "use_elem_mat_fields", 1);
params.verify_solution = Mantevo::parse_parameter<int>(argstring, "verify_solution", 0);
params.device = Mantevo::parse_parameter<int>(argstring, "device", 0);
params.num_devices = Mantevo::parse_parameter<int>(argstring, "num_devices", 2);
params.skip_device = Mantevo::parse_parameter<int>(argstring, "skip_device", 9999);
params.numa = Mantevo::parse_parameter<int>(argstring, "numa", 1);
}
//-------------------------------------------------------------
void broadcast_parameters(Parameters& params)
{
#ifdef HAVE_MPI
const int num_int_params = 13;
int iparams[num_int_params] = {params.nx, params.ny, params.nz, params.numthreads, params.mv_overlap_comm_comp, params.use_locking,
params.elem_group_size, params.use_elem_mat_fields, params.verify_solution,
params.device, params.num_devices,params.skip_device,params.numa};
MPI_Bcast(&iparams[0], num_int_params, MPI_INT, 0, MPI_COMM_WORLD);
params.nx = iparams[0];
params.ny = iparams[1];
params.nz = iparams[2];
params.numthreads = iparams[3];
params.mv_overlap_comm_comp = iparams[4];
params.use_locking = iparams[5];
params.elem_group_size = iparams[6];
params.use_elem_mat_fields = iparams[7];
params.verify_solution = iparams[8];
params.device = iparams[9];
params.num_devices = iparams[10];
params.skip_device = iparams[11];
params.numa = iparams[12];
float fparams[1] = {params.load_imbalance};
MPI_Bcast(&fparams[0], 1, MPI_FLOAT, 0, MPI_COMM_WORLD);
params.load_imbalance = fparams[0];
#endif
}
//-------------------------------------------------------------
void initialize_mpi(int argc, char** argv, int& numprocs, int& myproc)
{
#ifdef HAVE_MPI
#ifdef MINIFE_MPI_THREAD_MULTIPLE
int mpi_thr_config = MPI_THREAD_SINGLE;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &mpi_thr_config);
if( MPI_THREAD_MULTIPLE != mpi_thr_config ) {
fprintf(stderr, "Error: unable to configure MPI for MPI_THREAD_MULTIPLE!\n");
exit(-1);
}
#else
MPI_Init(&argc, &argv);
#endif
MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &myproc);
#else
numprocs = 1;
myproc = 0;
#endif
}
//-------------------------------------------------------------
void finalize_mpi()
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
}
}//namespace miniFE