Skip to content

Commit c06da08

Browse files
authored
Fix posix transport offset (#4603)
* ignore build.*/ * Fix wrong offset in POSIX transport when reading a block of >2147381248 bytes. * fix
1 parent 669cec8 commit c06da08

File tree

4 files changed

+141
-2
lines changed

4 files changed

+141
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ CMakeSettings.json
4747

4848
# CMake generated files
4949
build/
50+
build.*/
5051
.idea/
5152
.vscode/
5253

5354
# redis dump files
54-
*.rdb
55+
*.rdb

source/adios2/toolkit/transport/file/FilePOSIX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ void FilePOSIX::Read(char *buffer, size_t size, size_t start)
514514
position += DefaultMaxFileBatchSize;
515515
start += DefaultMaxFileBatchSize;
516516
}
517-
lf_PRead(&buffer[position], remainder, position);
517+
lf_PRead(&buffer[position], remainder, start);
518518
}
519519
else
520520
{

testing/adios2/engine/bp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ bp_gtest_add_tests_helper(WriteReadADIOS2 MPI_ALLOW)
104104
async_gtest_add_tests_helper(WriteReadADIOS2 MPI_ALLOW)
105105

106106
gtest_add_tests_helper(WriteReadFlatten MPI_ONLY BP Engine.BP. .BP5 WORKING_DIRECTORY ${BP5_DIR} EXTRA_ARGS "BP5" )
107+
gtest_add_tests_helper(LargeBlocks MPI_NONE BP Engine.BP. .BP5 WORKING_DIRECTORY ${BP5_DIR} EXTRA_ARGS "BP5" )
107108

108109
bp_gtest_add_tests_helper(WriteReadADIOS2fstream MPI_ALLOW)
109110
bp_gtest_add_tests_helper(WriteReadADIOS2stdio MPI_ALLOW)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* Distributed under the OSI-approved Apache License, Version 2.0. See
3+
* accompanying file Copyright.txt for details.
4+
*
5+
* TestLargeBlocks.cpp :
6+
*
7+
* Created on: Aug 5, 2025
8+
* Author: Norbert Podhorszki
9+
*/
10+
11+
#include <cstdint>
12+
#include <cstring>
13+
14+
#include <iostream>
15+
#include <stdexcept>
16+
17+
#include <adios2.h>
18+
19+
#include <gtest/gtest.h>
20+
21+
std::string engineName; // comes from command line
22+
23+
class LargeBlocks : public ::testing::Test
24+
{
25+
public:
26+
LargeBlocks() = default;
27+
};
28+
29+
constexpr size_t DefaultMaxFileBatchSize = 2147381248;
30+
31+
TEST_F(LargeBlocks, MultiBlock)
32+
{
33+
// Write a small variable
34+
// Write a large (>2147381248 bytes) so that it's offset is >0 in the file.
35+
// Read the large variable back and confirm that the data on the
36+
// chunk boundary of 2147381248 bytes is correct.
37+
// Testing if the POSIX reader transport is reading in chunks of 2147381248
38+
// bytes correctly (from the correct offsets)
39+
40+
adios2::ADIOS adios;
41+
42+
const std::string fname = "LargeBlocks.bp";
43+
size_t NX = DefaultMaxFileBatchSize / 4 +
44+
1024; // data must be > 2147381248 bytes to test chunked writing/reading
45+
46+
std::vector<uint32_t> LargeData(NX);
47+
uint32_t myvalue = 0;
48+
for (size_t n = 0; n < NX; ++n)
49+
{
50+
LargeData[n] = myvalue++;
51+
}
52+
53+
// Writer
54+
{
55+
adios2::IO outIO = adios.DeclareIO("Output");
56+
if (!engineName.empty())
57+
{
58+
outIO.SetEngine(engineName);
59+
}
60+
adios2::Engine writer = outIO.Open(fname, adios2::Mode::Write);
61+
auto varSmall = outIO.DefineVariable<uint32_t>("small", {2000}, {0}, {2000});
62+
auto varLarge = outIO.DefineVariable<uint32_t>("large", {NX}, {0}, {NX});
63+
64+
std::cout << "Writing to " << fname << std::endl;
65+
writer.BeginStep();
66+
writer.Put(varSmall, LargeData.data(), adios2::Mode::Deferred);
67+
writer.Put(varLarge, LargeData.data(), adios2::Mode::Deferred);
68+
writer.EndStep();
69+
writer.Close();
70+
}
71+
72+
// Reader with streaming
73+
{
74+
adios2::IO inIO = adios.DeclareIO("Input");
75+
if (!engineName.empty())
76+
{
77+
inIO.SetEngine(engineName);
78+
}
79+
adios2::Engine reader = inIO.Open(fname, adios2::Mode::ReadRandomAccess);
80+
std::cout << "Reading as stream with BeginStep/EndStep:" << std::endl;
81+
82+
auto varLarge = inIO.InquireVariable<uint32_t>("large");
83+
EXPECT_TRUE(varLarge);
84+
std::cout << " large data shape " << varLarge.Shape()[0] << std::endl;
85+
86+
varLarge.SetSelection({{0}, {NX}});
87+
std::vector<uint32_t> data(NX);
88+
reader.Get(varLarge, data.data());
89+
reader.PerformGets();
90+
91+
size_t TestOffset = DefaultMaxFileBatchSize / 4;
92+
std::cout << "large data from " << TestOffset - 10 << ":" << std::endl;
93+
std::cout << " written: " << std::endl;
94+
for (size_t i = TestOffset - 10; i < TestOffset + 10; ++i)
95+
{
96+
std::cout << static_cast<int>(LargeData[i]) << " ";
97+
}
98+
std::cout << std::endl;
99+
std::cout << " read: " << std::endl;
100+
for (size_t i = TestOffset - 10; i < TestOffset + 10; ++i)
101+
{
102+
std::cout << static_cast<int>(data[i]) << " ";
103+
}
104+
std::cout << std::endl;
105+
for (size_t i = TestOffset - 10; i < TestOffset + 10; ++i)
106+
{
107+
EXPECT_EQ(data[i], LargeData[i]);
108+
}
109+
reader.Close();
110+
}
111+
}
112+
113+
int main(int argc, char **argv)
114+
{
115+
#if ADIOS2_USE_MPI
116+
int provided;
117+
118+
// MPI_THREAD_MULTIPLE is only required if you enable the SST MPI_DP
119+
MPI_Init_thread(nullptr, nullptr, MPI_THREAD_MULTIPLE, &provided);
120+
#endif
121+
122+
int result;
123+
::testing::InitGoogleTest(&argc, argv);
124+
125+
if (argc > 1)
126+
{
127+
engineName = std::string(argv[1]);
128+
}
129+
130+
result = RUN_ALL_TESTS();
131+
132+
#if ADIOS2_USE_MPI
133+
MPI_Finalize();
134+
#endif
135+
136+
return result;
137+
}

0 commit comments

Comments
 (0)