From eaf601ec4bac45f66da4d780e99574bd842b6d53 Mon Sep 17 00:00:00 2001 From: jstark <jstark@mpi-cbg.de> Date: Mon, 10 Jan 2022 16:47:31 +0100 Subject: [PATCH] Fixing MPI Broadcasting. --- src/CSVReader/CSVReader.hpp | 14 +++++++------- src/CSVReader/tests/CSVReader_unit_test.cpp | 16 +--------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/CSVReader/CSVReader.hpp b/src/CSVReader/CSVReader.hpp index 36328e9f..b83a2eea 100644 --- a/src/CSVReader/CSVReader.hpp +++ b/src/CSVReader/CSVReader.hpp @@ -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); diff --git a/src/CSVReader/tests/CSVReader_unit_test.cpp b/src/CSVReader/tests/CSVReader_unit_test.cpp index 17bd4aee..c8d2fbee 100644 --- a/src/CSVReader/tests/CSVReader_unit_test.cpp +++ b/src/CSVReader/tests/CSVReader_unit_test.cpp @@ -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; } -- GitLab