1
// Copyright (C) 2007 Garth N. Wells.
2
// Licensed under the GNU LGPL Version 2.1.
4
// Modified by Magnus Vikstrøm
5
// First added: 2007-10-30
6
// Last changed: 2008-01-09
8
// This file is used for testing distribution of the mesh using MPI
12
#include "Nonlinear2D.h"
18
using namespace dolfin;
20
real timer(Mesh& mesh, int num_iterations, Form& a)
22
dolfin::cout << "Assembling with sequential assembler." << dolfin::endl;
24
Assembler assembler(mesh);
26
assembler.assemble(A, a, true);
28
for(int i=0; i<num_iterations; ++i)
29
assembler.assemble(A, a, false);
30
return toc()/static_cast<real>(num_iterations);
33
real p_timer(Mesh& mesh, MeshFunction<dolfin::uint>& partitions, int num_iterations, Form& a)
35
dolfin::cout << "Assembling with parallel assembler." << dolfin::endl;
37
pAssembler passembler(mesh, partitions);
39
passembler.assemble(B, a, true);
41
for(int i=0; i<num_iterations; ++i)
42
passembler.assemble(B, a, false);
43
return toc()/static_cast<real>(num_iterations);
46
int main(int argc, char* argv[])
48
std::string meshfile, partitionsfile, resultfile;
49
std::string assembler = "parallel";
52
int num_iterations = 1;
53
int num_part = dolfin::MPI::numProcesses();
56
bool sequential = false;
57
std::string testtype = "Poisson3D";
58
bool petsc_info = false;
62
listOpts.addOption("", "mesh", "Mesh File", true);
63
listOpts.addOption("", "partitions", "Mesh partitions file", true);
64
listOpts.addOption("", "sequential", "Run with sequential assembler", false);
65
listOpts.addOption("", "cells", "Number of cells", true);
66
listOpts.addOption("", "num_part", "Number of partitions", true);
67
listOpts.addOption("", "resultfile", "File to save results in", true);
68
listOpts.addOption("", "num_iterations", "Number of times to assemble", true);
69
listOpts.addOption("", "check", "Verify assembly result", false);
70
listOpts.addOption("", "debug", "Prints debugging info", false);
71
listOpts.addOption("", "testtype", "Type of test: Poisson2D, Poisson3D, Nonlinear2D", true);
72
listOpts.addOption("", "petsc_info", "Print info from PETSc", false);
74
if (listOpts.parse(argc, argv))
75
while ((switchInt = listOpts.cycle()) >= 0)
80
meshfile = listOpts.getArgs(switchInt);
83
partitionsfile = listOpts.getArgs(switchInt);
89
cells = atoi(listOpts.getArgs(switchInt).c_str());
90
cells_3D = atoi(listOpts.getArgs(switchInt).c_str());
93
num_part = atoi(listOpts.getArgs(switchInt).c_str());
96
resultfile = listOpts.getArgs(switchInt);
99
num_iterations = atoi(listOpts.getArgs(switchInt).c_str());
108
testtype = listOpts.getArgs(switchInt);
119
MeshFunction<dolfin::uint>* partitions;
120
dolfin_set("debug level", debug);
123
char** init_argv = new char*[2];
124
init_argv[0] = argv[0];
125
sprintf(init_argv[1], "%s", "-info");
126
dolfin::cout << "dolfin_init" << dolfin::endl;
127
dolfin_init(2, init_argv);
131
dolfin::cout << "Reading mesh from file: " << meshfile << dolfin::endl;
132
mesh = Mesh(meshfile);
136
if(testtype == "Nonlinear2D" || testtype == "Poisson2D")
138
printf("Creating UnitSquare(%d, %d)\n", cells, cells);
139
mesh = UnitSquare(cells, cells);
143
printf("Creating UnitCube(%d, %d, %d)\n", cells_3D, cells_3D, cells_3D);
144
mesh = UnitCube(cells_3D, cells_3D, cells_3D);
151
if(testtype == "Poisson3D")
152
a = new PoissonBilinearForm();
153
else if(testtype == "Nonlinear2D")
155
Function w(mesh, 1.0);
156
a = new Nonlinear2DBilinearForm(w);
159
a = new PoissonBilinearForm();
161
dolfin::cout << "Running test " << testtype << dolfin::endl;
162
dolfin::cout << "Assembling with sequential assembler." << dolfin::endl;
163
printf("Number of iteration(s): %d\n", num_iterations);
164
time = timer(mesh, num_iterations, *a);
168
if(partitionsfile != "")
170
dolfin::cout << "Reading partitions from file: " << partitionsfile << dolfin::endl;
171
partitions = new MeshFunction<dolfin::uint>(mesh, partitionsfile);
175
dolfin::cout << "Partitioning mesh into: " << num_part << " partitions" << dolfin::endl;
176
partitions = new MeshFunction<dolfin::uint>(mesh);
177
mesh.partition(*partitions, num_part);
181
if(testtype == "Poisson3D")
182
a = new PoissonBilinearForm();
183
else if(testtype == "Nonlinear2D")
185
Function w(mesh, 1.0);
186
a = new Nonlinear2DBilinearForm(w);
189
a = new PoissonBilinearForm();
191
dolfin::cout << "Running test " << testtype << dolfin::endl;
192
dolfin::cout << "Assembling with parallel assembler." << dolfin::endl;
193
printf("Number of iteration(s): %d Number of partitions: %d\n", num_iterations, num_part);
194
time = p_timer(mesh, *partitions, num_iterations, *a);
198
dolfin::cout << "Appending results to " << resultfile << dolfin::endl;
199
std::ofstream outfile(resultfile.c_str(), std::ofstream::app);
200
outfile << dolfin::MPI::numProcesses() << " " << time << std::endl;
205
printf("Average assemble time: %.3e\n", time);
209
dolfin::cout << "Not implemented" << dolfin::endl;
210
//check_assembly(mesh, *partitions);