Skip to content
Snippets Groups Projects
Commit eaf601ec authored by jstark's avatar jstark
Browse files

Fixing MPI Broadcasting.

parent f361582b
No related branches found
No related tags found
No related merge requests found
Pipeline #4155 failed
......@@ -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;
size_t total_size = 0;
m = 0;
n = 0;
auto & v_cl = create_vcluster();
// File is accessed and read only by one process
if (v_cl.rank() == 0)
......@@ -54,9 +56,6 @@ void read_csv_to_vector(const std::string & input_file, openfpm::vector<T> & out
}
std::ifstream file(input_file); // Create file pointer and open file
std::string line, element;
m = 0;
n = 0;
size_t elems = 0;
while (getline(file, line)) // Read entire row and store as one string in line
{
std::stringstream stream_line(line); // Needed to break line into elements later one
......@@ -72,9 +71,10 @@ void read_csv_to_vector(const std::string & input_file, openfpm::vector<T> & out
// 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);
MPI_Bcast(&total_size,1,MPI_UNSIGNED,0,MPI_COMM_WORLD);
MPI_Bcast(&m,1,MPI_UNSIGNED,0,MPI_COMM_WORLD);
MPI_Bcast(&n,1,MPI_UNSIGNED,0,MPI_COMM_WORLD);
if (v_cl.rank() != 0)
{
output_vector.resize(total_size);
......
......@@ -13,23 +13,11 @@ BOOST_AUTO_TEST_CASE(csv_reader_int_test)
#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;
}
read_csv_to_vector(csv_file, v_lin, m, n);
BOOST_CHECK(m == 4);
BOOST_CHECK(n == 3);
......@@ -41,8 +29,6 @@ BOOST_AUTO_TEST_CASE(csv_reader_int_test)
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment