-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
322 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#ifndef PRIMEPRODUCTPOSTPROCESSOR_H | ||
#define PRIMEPRODUCTPOSTPROCESSOR_H | ||
|
||
#include "GeneralPostprocessor.h" | ||
|
||
class PrimeProductPostprocessor; | ||
class PrimeProductUserObject; | ||
|
||
template <> | ||
InputParameters validParams<PrimeProductPostprocessor>(); | ||
|
||
/** | ||
* Get the value of proproduct from PrimeProductUserObject | ||
*/ | ||
class PrimeProductPostprocessor : public GeneralPostprocessor | ||
{ | ||
public: | ||
PrimeProductPostprocessor(const InputParameters & parameters); | ||
|
||
virtual void initialize() override {} | ||
virtual void execute() override {} | ||
|
||
virtual Real getValue() override; | ||
|
||
protected: | ||
const PrimeProductUserObject & _prime_product; | ||
}; | ||
|
||
#endif // PRIMEPRODUCTPOSTPROCESSOR_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#ifndef PRIMECOUNTERUSEROBJECT_H | ||
#define PRIMECOUNTERUSEROBJECT_H | ||
|
||
#include "GeneralUserObject.h" | ||
|
||
class PrimeProductUserObject; | ||
|
||
template <> | ||
InputParameters validParams<PrimeProductUserObject>(); | ||
|
||
/** | ||
* Computes a product of prime numbers. Each threads picks an n-th prime number where n is equal to | ||
* its thread ID. Then when threads join the product of all prime numbers is computed, which is the | ||
* final value provided by this user object. | ||
*/ | ||
class PrimeProductUserObject : public GeneralUserObject | ||
{ | ||
public: | ||
PrimeProductUserObject(const InputParameters & params); | ||
|
||
virtual void initialize() override; | ||
virtual void execute() override; | ||
virtual void finalize() override; | ||
|
||
virtual void threadJoin(const UserObject &) override; | ||
|
||
unsigned int getProduct() const { return _product; } | ||
|
||
protected: | ||
unsigned int factorial(unsigned int n) const; | ||
unsigned int prime(unsigned int n) const; | ||
|
||
/// Prime number of this instance | ||
unsigned int _prime; | ||
/// Product for all prime numbers | ||
unsigned int _product; | ||
}; | ||
|
||
#endif /* PRIMECOUNTERUSEROBJECT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "PrimeProductPostprocessor.h" | ||
#include "PrimeProductUserObject.h" | ||
|
||
registerMooseObject("MooseTestApp", PrimeProductPostprocessor); | ||
|
||
template <> | ||
InputParameters | ||
validParams<PrimeProductPostprocessor>() | ||
{ | ||
InputParameters params = validParams<GeneralPostprocessor>(); | ||
params.addRequiredParam<UserObjectName>( | ||
"prime_product", "The name of the user object that holds the prime product"); | ||
return params; | ||
} | ||
|
||
PrimeProductPostprocessor::PrimeProductPostprocessor(const InputParameters & parameters) | ||
: GeneralPostprocessor(parameters), | ||
_prime_product(getUserObject<PrimeProductUserObject>("prime_product")) | ||
{ | ||
} | ||
|
||
Real | ||
PrimeProductPostprocessor::getValue() | ||
{ | ||
return _prime_product.getProduct(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "PrimeProductUserObject.h" | ||
#include <unistd.h> | ||
|
||
registerMooseObject("MooseTestApp", PrimeProductUserObject); | ||
|
||
template <> | ||
InputParameters | ||
validParams<PrimeProductUserObject>() | ||
{ | ||
InputParameters params = validParams<GeneralUserObject>(); | ||
return params; | ||
} | ||
|
||
PrimeProductUserObject::PrimeProductUserObject(const InputParameters & params) | ||
: GeneralUserObject(params) | ||
{ | ||
if (libMesh::n_threads() > 20) | ||
mooseError("This object works only with up to 20 threads. If you need more, add more prime " | ||
"numbers into `prime` variable in the execute method."); | ||
} | ||
|
||
void | ||
PrimeProductUserObject::initialize() | ||
{ | ||
} | ||
|
||
void | ||
PrimeProductUserObject::execute() | ||
{ | ||
// first 20 prime numbers | ||
static unsigned int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, | ||
31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; | ||
_product = primes[_tid]; | ||
} | ||
|
||
void | ||
PrimeProductUserObject::finalize() | ||
{ | ||
} | ||
|
||
void | ||
PrimeProductUserObject::threadJoin(const UserObject & uo) | ||
{ | ||
const PrimeProductUserObject & pcuo = dynamic_cast<const PrimeProductUserObject &>(uo); | ||
_product *= pcuo._product; | ||
} |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th1.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,2 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th2.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,6 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th3.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,30 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th4.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,210 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th5.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,2310 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th6.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,30030 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th7.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,510510 |
3 changes: 3 additions & 0 deletions
3
test/tests/userobjects/threaded_general_user_object/gold/th8.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
time,product | ||
0,0 | ||
1,9699690 |
49 changes: 49 additions & 0 deletions
49
test/tests/userobjects/threaded_general_user_object/test.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[Mesh] | ||
type = GeneratedMesh | ||
dim = 1 | ||
nx = 2 | ||
[] | ||
|
||
[Variables] | ||
[./u] | ||
[../] | ||
[] | ||
|
||
[Kernels] | ||
[./diff] | ||
type = Diffusion | ||
variable = u | ||
[../] | ||
[] | ||
|
||
[BCs] | ||
[./l] | ||
type = DirichletBC | ||
variable = u | ||
boundary = left | ||
value = 1 | ||
[../] | ||
[] | ||
|
||
[Executioner] | ||
type = Steady | ||
[] | ||
|
||
[UserObjects] | ||
[./prime_product] | ||
type = PrimeProductUserObject | ||
threaded = true | ||
execute_on = timestep_end | ||
[../] | ||
[] | ||
|
||
[Postprocessors] | ||
[./product] | ||
type = PrimeProductPostprocessor | ||
prime_product = prime_product | ||
[../] | ||
[] | ||
|
||
[Outputs] | ||
csv = true | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
[Tests] | ||
[./th1] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th1' | ||
min_threads = 1 | ||
max_threads = 1 | ||
csvdiff = 'th1.csv' | ||
[../] | ||
|
||
[./th2] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th2' | ||
min_threads = 2 | ||
max_threads = 2 | ||
csvdiff = 'th2.csv' | ||
[../] | ||
|
||
[./th3] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th3' | ||
min_threads = 3 | ||
max_threads = 3 | ||
csvdiff = 'th3.csv' | ||
[../] | ||
|
||
[./th4] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th4' | ||
min_threads = 4 | ||
max_threads = 4 | ||
csvdiff = 'th4.csv' | ||
[../] | ||
|
||
[./th5] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th5' | ||
min_threads = 5 | ||
max_threads = 5 | ||
csvdiff = 'th5.csv' | ||
[../] | ||
|
||
[./th6] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th6' | ||
min_threads = 6 | ||
max_threads = 6 | ||
csvdiff = 'th6.csv' | ||
[../] | ||
|
||
[./th7] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th7' | ||
min_threads = 7 | ||
max_threads = 7 | ||
csvdiff = 'th7.csv' | ||
[../] | ||
|
||
[./th8] | ||
type = 'CSVDiff' | ||
input = 'test.i' | ||
cli_args = 'Outputs/file_base=th8' | ||
min_threads = 8 | ||
max_threads = 8 | ||
csvdiff = 'th8.csv' | ||
[../] | ||
[] |