Skip to content

Commit

Permalink
MultiArray3d.cpp (+3) [22+/26-] - code style
Browse files Browse the repository at this point in the history
  • Loading branch information
skynowa committed Jan 2, 2025
1 parent 8a17bee commit b9c371f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
4 changes: 2 additions & 2 deletions IpcMt/Thread/Threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void fnoarg(int t)
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
int nthreads = std::thread::hardware_concurrency();
const int nthreads = std::thread::hardware_concurrency();
std::cout << "nthreads = " << nthreads << std::endl;

std::vector<std::thread> pool;
Expand All @@ -25,7 +25,7 @@ int main(int, char **)
pool.push_back( std::thread(fnoarg,i) );
}

for(auto& t : pool){
for (auto& t : pool){
t.join();
}

Expand Down
18 changes: 8 additions & 10 deletions Libs/Boost/MultiArray2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
void
print(const boost::multi_array<double, 2> &array)
{
for (std::size_t i=0; i<array.shape()[0]; i++) {
for (std::size_t j=0; j<array.shape()[1]; j++) {
for (std::size_t i = 0; i < array.shape()[0]; i++) {
for (std::size_t j = 0; j < array.shape()[1]; j++) {
std::cout << array[i][j] << " ";
}
std::cout << "\n";
Expand All @@ -27,20 +27,18 @@ print(const boost::multi_array<double, 2> &array)
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
const std::size_t m = (argc>1) ? atoi(argv[1]) : 4;
const std::size_t n = (argc>2) ? atoi(argv[2]) : 5;
const std::size_t m = (argc > 1) ? atoi(argv[1]) : 4;
const std::size_t n = (argc > 2) ? atoi(argv[2]) : 5;

boost::multi_array<double, 2> A(boost::extents[n][m]);

for(std::size_t i=0; i<n; i++)
for(std::size_t j=0; j<m; j++)
A[i][j] = i * m + j;
for (std::size_t i = 0; i < n; i++)
for (std::size_t j = 0; j < m; j++) A[i][j] = i * m + j;

boost::multi_array<double, 2> B(boost::extents[n][m]);

for(std::size_t i=0; i<n; i++)
for(std::size_t j=0; j<m; j++)
B[i][j] = i * m + j + 0.5;
for (std::size_t i = 0; i < n; i++)
for (std::size_t j = 0; j < m; j++) B[i][j] = i * m + j + 0.5;

print(A);
print(B);
Expand Down
26 changes: 12 additions & 14 deletions Libs/Boost/MultiArray3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
void
print(const boost::multi_array<double, 3> &array)
{
for (std::size_t i=0; i<array.shape()[0]; i++) {
for (std::size_t j=0; j<array.shape()[1]; j++) {
for (std::size_t k=0; k<array.shape()[2]; k++) {
for (std::size_t i = 0; i < array.shape()[0]; i++) {
for (std::size_t j = 0; j < array.shape()[1]; j++) {
for (std::size_t k = 0; k < array.shape()[2]; k++) {
std::cout << array[i][j][k] << " ";
}
std::cout << "\n";
Expand All @@ -28,23 +28,21 @@ print(const boost::multi_array<double, 3> &array)
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{
const std::size_t m = (argc>1) ? atoi(argv[1]) : 4;
const std::size_t n = (argc>2) ? atoi(argv[2]) : 5;
const std::size_t o = (argc>3) ? atoi(argv[3]) : 2;
const std::size_t m = (argc > 1) ? atoi(argv[1]) : 4;
const std::size_t n = (argc > 2) ? atoi(argv[2]) : 5;
const std::size_t o = (argc > 3) ? atoi(argv[3]) : 2;

boost::multi_array<double, 3> A(boost::extents[o][n][m]);

for (std::size_t i=0; i<o; i++)
for (std::size_t j=0; j<n; j++)
for (std::size_t k=0; k<m; k++)
A[i][j][k] = i * m * n + j * m + k;
for (std::size_t i = 0; i < o; i++)
for (std::size_t j = 0; j < n; j++)
for (std::size_t k = 0; k < m; k++) A[i][j][k] = i * m * n + j * m + k;

boost::multi_array<double, 3> B(boost::extents[o][n][m]);

for (std::size_t i=0; i<o; i++)
for (std::size_t j=0; j<n; j++)
for (std::size_t k=0; k<m; k++)
B[i][j][k] = i * m * n + j * m + k + 0.5;
for (std::size_t i = 0; i < o; i++)
for (std::size_t j = 0; j < n; j++)
for (std::size_t k = 0; k < m; k++) B[i][j][k] = i * m * n + j * m + k + 0.5;

print(A);
print(B);
Expand Down

0 comments on commit b9c371f

Please sign in to comment.