Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openfpm_data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sbalzarini Lab
Software
Parallel Computing
OpenFPM
openfpm_data
Commits
f361582b
Commit
f361582b
authored
3 years ago
by
jstark
Browse files
Options
Downloads
Patches
Plain Diff
Added MPI communication.
parent
433c71f3
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/CSVReader/CSVReader.hpp
+13
-2
13 additions, 2 deletions
src/CSVReader/CSVReader.hpp
src/CSVReader/tests/CSVReader_unit_test.cpp
+59
-38
59 additions, 38 deletions
src/CSVReader/tests/CSVReader_unit_test.cpp
with
72 additions
and
40 deletions
src/CSVReader/CSVReader.hpp
+
13
−
2
View file @
f361582b
...
...
@@ -41,7 +41,9 @@ T string_to_type(const std::string & string_to_convert)
template
<
typename
T
>
void
read_csv_to_vector
(
const
std
::
string
&
input_file
,
openfpm
::
vector
<
T
>
&
output_vector
,
size_t
&
m
,
size_t
&
n
)
{
int
total_size
=
0
;
auto
&
v_cl
=
create_vcluster
();
// File is accessed and read only by one process
if
(
v_cl
.
rank
()
==
0
)
{
if
(
!
check_if_file_exists
(
input_file
))
...
...
@@ -62,13 +64,22 @@ void read_csv_to_vector(const std::string & input_file, openfpm::vector<T> & out
{
output_vector
.
add
(
string_to_type
<
T
>
(
element
));
// Convert element from string to type T and append to
// output_vector
elems
+=
1
;
// Increase n by one for each element read
total_size
+=
1
;
// Increase n by one for each element read
}
m
+=
1
;
// Increase m by one for each row read
}
if
(
m
>=
1
)
n
=
elems
/
m
;
// If at least one row present, divide number of elements read by number of rows to get
if
(
m
>=
1
)
n
=
total_size
/
m
;
// If at least one row present, divide number of elements read by number of rows to get
// the number of columns
}
// Distribute size of the lin. vector to all other processes s.t. their output_vector can be resized accordingly.
MPI_Bcast
(
&
total_size
,
1
,
MPI_INT
,
0
,
MPI_COMM_WORLD
);
MPI_Bcast
(
&
m
,
1
,
MPI_INT
,
0
,
MPI_COMM_WORLD
);
MPI_Bcast
(
&
n
,
1
,
MPI_INT
,
0
,
MPI_COMM_WORLD
);
if
(
v_cl
.
rank
()
!=
0
)
{
output_vector
.
resize
(
total_size
);
}
// After the output_vector has been resized to correct size, it can receive the content from process 0.
v_cl
.
Bcast
(
output_vector
,
0
);
v_cl
.
execute
();
}
...
...
This diff is collapsed.
Click to expand it.
src/CSVReader/tests/CSVReader_unit_test.cpp
+
59
−
38
View file @
f361582b
...
...
@@ -6,50 +6,71 @@
#include
"CSVReader/CSVReader.hpp"
BOOST_AUTO_TEST_SUITE
(
CSVReaderTestSuite
)
BOOST_AUTO_TEST_CASE
(
csv_reader_int
)
BOOST_AUTO_TEST_CASE
(
csv_reader_int
_test
)
{
std
::
cout
<<
"CWD = "
<<
get_cwd
()
<<
std
::
endl
;
std
::
string
csv_file
=
std
::
string
(
"../../../openfpm_io/test_data/integer.csv"
);
// Read csv file into vector while linearizing
openfpm
::
vector
<
int
>
v_lin
;
// Vector to which csv file will be read to
size_t
m
,
n
;
// Number of rows m and columns n
read_csv_to_vector
(
csv_file
,
v_lin
,
m
,
n
);
BOOST_CHECK
(
m
==
4
);
BOOST_CHECK
(
n
==
3
);
BOOST_CHECK
(
m
*
n
==
v_lin
.
size
());
for
(
int
i
=
0
;
i
<
v_lin
.
size
()
/
n
;
++
i
)
{
BOOST_CHECK
(
v_lin
.
get
(
i
*
n
)
==
i
+
1
);
BOOST_CHECK
(
v_lin
.
get
(
i
*
n
+
1
)
==
(
i
+
1
)
*
2
);
BOOST_CHECK
(
v_lin
.
get
(
i
*
n
+
2
)
==
v_lin
.
get
(
i
*
n
)
*
v_lin
.
get
(
i
*
n
+
1
));
}
#ifdef OPENFPM_PDATA
std
::
string
csv_file
=
std
::
string
(
"openfpm_io/test_data/integer.csv"
);
#else
std
::
string
csv_file
=
std
::
string
(
"test_data/integer.csv"
);
#endif
std
::
cout
<<
"CWD = "
<<
get_cwd
()
<<
std
::
endl
;
// Read csv file into vector while linearizing
openfpm
::
vector
<
int
>
v_lin
;
// Vector to which csv file will be read to
size_t
m
,
n
;
// Number of rows m and columns n
read_csv_to_vector
(
csv_file
,
v_lin
,
m
,
n
);
auto
&
v_cl
=
create_vcluster
();
std
::
cout
<<
"My rank is "
<<
v_cl
.
rank
()
<<
std
::
endl
;
auto
v_iter
=
v_lin
.
getIterator
();
while
(
v_iter
.
isNext
())
{
auto
key
=
v_iter
.
get
();
std
::
cout
<<
"Element number "
<<
key
<<
" of rank "
<<
v_cl
.
rank
()
<<
" is "
<<
v_lin
.
get
(
key
)
<<
std
::
endl
;
++
v_iter
;
}
BOOST_CHECK
(
m
==
4
);
BOOST_CHECK
(
n
==
3
);
BOOST_CHECK
(
m
*
n
==
v_lin
.
size
());
for
(
int
i
=
0
;
i
<
v_lin
.
size
()
/
n
;
++
i
)
{
BOOST_CHECK
(
v_lin
.
get
(
i
*
n
)
==
i
+
1
);
BOOST_CHECK
(
v_lin
.
get
(
i
*
n
+
1
)
==
(
i
+
1
)
*
2
);
BOOST_CHECK
(
v_lin
.
get
(
i
*
n
+
2
)
==
v_lin
.
get
(
i
*
n
)
*
v_lin
.
get
(
i
*
n
+
1
));
}
std
::
cout
<<
"Rank "
<<
v_cl
.
rank
()
<<
" reaches end of unit test."
<<
std
::
endl
;
}
BOOST_AUTO_TEST_CASE
(
csv_reader_char
)
BOOST_AUTO_TEST_CASE
(
csv_reader_char
_test
)
{
// Read csv file into vector while linearizing
const
std
::
string
csv_file
=
"../../../openfpm_io/test_data/char.csv"
;
// csv file to be read
openfpm
::
vector
<
std
::
string
>
v_lin
;
// Vector to which csv file will be read to
size_t
m
,
n
;
// Number of rows m and columns n
read_csv_to_vector
(
csv_file
,
v_lin
,
m
,
n
);
BOOST_CHECK
(
m
==
5
);
BOOST_CHECK
(
n
==
2
);
BOOST_CHECK
(
m
*
n
==
v_lin
.
size
());
openfpm
::
vector
<
std
::
string
>
col1
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
};
openfpm
::
vector
<
std
::
string
>
col2
=
{
"antilope"
,
"ballena"
,
"camel"
,
"dackel"
,
"elefant"
};
for
(
int
i
=
0
;
i
<
v_lin
.
size
()
/
n
;
++
i
)
{
BOOST_CHECK
(
col1
.
get
(
i
)
==
v_lin
.
get
(
i
*
n
));
BOOST_CHECK
(
col2
.
get
(
i
)
==
v_lin
.
get
(
i
*
n
+
1
));
}
#ifdef OPENFPM_PDATA
std
::
string
csv_file
=
std
::
string
(
"openfpm_io/test_data/char.csv"
);
#else
std
::
string
csv_file
=
std
::
string
(
"test_data/char.csv"
);
#endif
// Read csv file into vector while linearizing
openfpm
::
vector
<
std
::
string
>
v_lin
;
// Vector to which csv file will be read to
size_t
m
,
n
;
// Number of rows m and columns n
read_csv_to_vector
(
csv_file
,
v_lin
,
m
,
n
);
BOOST_CHECK
(
m
==
5
);
BOOST_CHECK
(
n
==
2
);
BOOST_CHECK
(
m
*
n
==
v_lin
.
size
());
openfpm
::
vector
<
std
::
string
>
col1
=
{
"a"
,
"b"
,
"c"
,
"d"
,
"e"
};
openfpm
::
vector
<
std
::
string
>
col2
=
{
"antilope"
,
"ballena"
,
"camel"
,
"dackel"
,
"elefant"
};
for
(
int
i
=
0
;
i
<
v_lin
.
size
()
/
n
;
++
i
)
{
BOOST_CHECK
(
col1
.
get
(
i
)
==
v_lin
.
get
(
i
*
n
));
BOOST_CHECK
(
col2
.
get
(
i
)
==
v_lin
.
get
(
i
*
n
+
1
));
}
}
BOOST_AUTO_TEST_SUITE_END
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment