Skip to content

Commit a9f8a78

Browse files
improve examples
1 parent 887f791 commit a9f8a78

File tree

8 files changed

+29
-30
lines changed

8 files changed

+29
-30
lines changed

examples/compression_comparison.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ make Compression_comparison
1111
mkdir -p ../output/examples/compression_comparison
1212

1313
# Arguments
14-
outputpath=../output/examples/compression_comparison/
14+
outputfolder=../output/examples/compression_comparison/
1515
distances=(1 2 3)
1616

1717
# Run
1818
for distance in "${distances[@]}"
1919
do
20-
./examples/compression_comparison ${distance} compression_comparison_${distance}.csv ${outputpath}
20+
./examples/compression_comparison ${distance} compression_comparison_${distance}.csv ${outputfolder}
2121
done
2222

2323

examples/use_clustering.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ using namespace htool;
99
int main(int argc, char *argv[]) {
1010

1111
// Check the number of parameters
12-
if (argc != 2) {
12+
if (argc > 2) {
1313
// Tell the user how to run the program
14-
cerr << "Usage: " << argv[0] << " outputname" << endl;
14+
cerr << "Usage: " << argv[0] << " output_folder" << endl;
1515
/* "Usage messages" are a conventional way of telling the user
1616
* how to run a program if they enter the command incorrectly.
1717
*/
1818
return 1;
1919
}
20-
std::string outputname = argv[1];
20+
std::string output_folder = argc == 2 ? argv[1] : "./";
2121

2222
// Geometry
2323
const int number_points = 10000;
@@ -30,13 +30,13 @@ int main(int argc, char *argv[]) {
3030
// Cluster tree builder with customization
3131
ClusterTreeBuilder<double> recursive_build_strategy;
3232
recursive_build_strategy.set_maximal_leaf_size(10);
33-
recursive_build_strategy.set_partitioning_strategy(std::make_shared<Partitioning<double, ComputeLargestExtent<double>, RegularSplitting<double>>>()); // this is actually the default choice
33+
recursive_build_strategy.set_partitioning_strategy(std::make_shared<Partitioning_N<double, ComputeLargestExtent<double>, RegularSplitting<double>>>());
3434

3535
// Clustering
3636
Cluster<double> cluster = recursive_build_strategy.create_cluster_tree(number_points, spatial_dimension, coordinates.data(), number_of_children, number_of_partitions);
3737

3838
// Output
39-
save_clustered_geometry(cluster, spatial_dimension, coordinates.data(), outputname + "/clustering_output", {1, 2, 3});
39+
save_clustered_geometry(cluster, spatial_dimension, coordinates.data(), output_folder + "/clustering_output", {1, 2, 3});
4040

4141
return 0;
4242
}

examples/use_clustering.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ make Use_clustering
1111
mkdir -p ../output/examples/use_clustering
1212

1313
# Arguments
14-
outputpath=../output/examples/use_clustering/
14+
outputfolder=../output/examples/use_clustering/
1515

1616
# Run
17-
./examples/Use_clustering ${outputpath}
17+
./examples/Use_clustering ${outputfolder}
1818

1919
# Display output
2020
python3 ../tools/plot_cluster.py --inputfile ../output/examples/use_clustering/clustering_output.csv --depth 2

examples/use_ddm_solver.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,5 @@ cmake ../
1010
make Use_ddm_solver
1111
mkdir -p ../output/examples/use_ddm_solver
1212

13-
# Arguments
14-
outputpath=../output/examples/use_ddm_solver/
15-
1613
# Run
17-
mpirun -np 4 ./examples/Use_ddm_solver ${outputpath}
14+
mpirun -np 4 ./examples/Use_ddm_solver

examples/use_distributed_operator.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,29 @@ int main(int argc, char *argv[]) {
6464
MPI_Comm_size(MPI_COMM_WORLD, &sizeWorld);
6565

6666
// Check the number of parameters
67-
if (argc != 2) {
67+
if (argc > 2) {
6868
// Tell the user how to run the program
69-
cerr << "Usage: " << argv[0] << " outputpath" << endl;
69+
cerr << "Usage: " << argv[0] << " output_folder" << endl;
7070
/* "Usage messages" are a conventional way of telling the user
7171
* how to run a program if they enter the command incorrectly.
7272
*/
7373
return 1;
7474
}
7575

76-
std::string outputpath = argv[1];
76+
std::string output_folder = argc == 2 ? argv[1] : "./";
7777

7878
// Geometry
7979
const int number_points = 10000;
8080
const int spatial_dimension = 3;
8181
const int number_of_partitions = sizeWorld;
8282
const int number_of_children = 8;
8383
vector<double> coordinates(spatial_dimension * number_points);
84-
create_sphere(number_points, coordinates.data());
84+
create_rotated_ellipse(3, 4., 1., 0., 0., number_points, coordinates.data()); // 2d ellipse in 3d
8585

8686
// Clustering
8787
ClusterTreeBuilder<double> recursive_build_strategy;
8888
recursive_build_strategy.set_maximal_leaf_size(100);
89+
recursive_build_strategy.set_partitioning_strategy(std::make_shared<Partitioning_N<double, ComputeLargestExtent<double>, RegularSplitting<double>>>()); // this is actually the default choice
8990
Cluster<double> cluster = recursive_build_strategy.create_cluster_tree(number_points, spatial_dimension, coordinates.data(), number_of_children, number_of_partitions);
9091

9192
// HMatrix parameters
@@ -122,7 +123,7 @@ int main(int argc, char *argv[]) {
122123
std::cout << "Information about hmatrices accross all processors\n";
123124
}
124125
print_distributed_hmatrix_information(local_hmatrix, std::cout, MPI_COMM_WORLD);
125-
save_leaves_with_rank(local_hmatrix, outputpath + "/local_hmatrix_" + std::to_string(rankWorld));
126+
save_leaves_with_rank(local_hmatrix, output_folder + "/local_hmatrix_" + std::to_string(rankWorld));
126127

127128
// Finalize the MPI environment.
128129
MPI_Finalize();

examples/use_distributed_operator.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ make Use_distributed_operator
1111
mkdir -p ../output/examples/use_distributed_operator
1212

1313
# Arguments
14-
outputpath=../output/examples/use_distributed_operator/
14+
outputfolder=../output/examples/use_distributed_operator/
1515

1616
# Run
17-
mpirun -np 4 ./examples/Use_distributed_operator ${outputpath}
17+
mpirun -np 4 ./examples/Use_distributed_operator ${outputfolder}
1818

1919
# Display output
2020
python3 ../tools/plot_hmatrix.py --inputfile ../output/examples/use_distributed_operator/local_hmatrix_0.csv

examples/use_hmatrix.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ class UserOperator : public VirtualGenerator<double> {
5959
int main(int argc, char *argv[]) {
6060

6161
// Check the number of parameters
62-
if (argc != 2) {
62+
if (argc > 2) {
6363
// Tell the user how to run the program
64-
cerr << "Usage: " << argv[0] << " outputpath" << endl;
64+
cerr << "Usage: " << argv[0] << " output_folder" << endl;
6565
/* "Usage messages" are a conventional way of telling the user
6666
* how to run a program if they enter the command incorrectly.
6767
*/
6868
return 1;
6969
}
7070

71-
std::string outputpath = argv[1];
71+
std::string output_folder = argc == 2 ? argv[1] : "./";
7272

7373
// Execution policy
7474
auto &policy = exec_compat::par;
@@ -77,15 +77,16 @@ int main(int argc, char *argv[]) {
7777
const int number_points = 10000;
7878
const int spatial_dimension = 3;
7979
vector<double> coordinates(spatial_dimension * number_points);
80-
create_sphere(number_points, coordinates.data());
80+
create_rotated_ellipse(3, 4., 1., 0., 0., number_points, coordinates.data()); // 2d ellipse in 3d
8181

8282
// Cluster tree builder
8383
ClusterTreeBuilder<double> recursive_build_strategy;
8484
recursive_build_strategy.set_maximal_leaf_size(500);
85+
recursive_build_strategy.set_partitioning_strategy(std::make_shared<Partitioning_N<double, ComputeLargestExtent<double>, RegularSplitting<double>>>());
8586

8687
// HMatrix parameters
8788
const double epsilon = 0.01;
88-
const double eta = 10;
89+
const double eta = 200;
8990
char symmetry = 'S';
9091
char UPLO = 'L';
9192

@@ -97,18 +98,18 @@ int main(int argc, char *argv[]) {
9798
HMatrix<double> hmatrix = hmatrix_builder.build(policy, A, htool::HMatrixTreeBuilder<double>(epsilon, eta, symmetry, UPLO));
9899

99100
// Output
100-
// save_leaves_with_rank(hmatrix, outputpath + "hmatrix");
101+
save_leaves_with_rank(hmatrix, output_folder + "/hmatrix");
101102
print_tree_parameters(hmatrix, std::cout);
102103
print_hmatrix_information(hmatrix, std::cout);
103104

104-
// sequential y= A*x
105+
// y= A*x
105106
std::vector<double> x(number_points, 1), y(number_points, 0), ref(number_points, 0);
106107
add_hmatrix_vector_product(policy, 'N', double(1), hmatrix, x.data(), double(0), y.data());
107108
ref = A * x;
108109
std::cout << "relative error on matrix vector product : ";
109110
std::cout << norm2(ref - y) / norm2(ref) << "\n";
110111

111-
// sequential z = A^-1 y
112+
// z = A^-1 y
112113
std::vector<double> z(number_points, 0);
113114
z = y;
114115
MatrixView<double> z_view(number_points, 1, z.data());

examples/use_hmatrix.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ make Use_hmatrix
1111
mkdir -p ../output/examples/use_hmatrix
1212

1313
# Arguments
14-
outputpath=../output/examples/use_hmatrix/
14+
outputfolder=../output/examples/use_hmatrix/
1515

1616
# Run
17-
./examples/Use_hmatrix ${outputpath}
17+
./examples/Use_hmatrix ${outputfolder}
1818

1919
# Display output
2020
python3 ../tools/plot_hmatrix.py --inputfile ../output/examples/use_hmatrix/hmatrix.csv

0 commit comments

Comments
 (0)