1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <iostream>
#include <boost/mpi/communicator.hpp>
#include <boost/mpi/environment.hpp>
#include <complex>
#include <vector>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char* argv[])
{
typedef vector<vector<vector<complex<double> > > > chmatrix; //define ~common types (for fun, honestly)
typedef vector<vector<complex<double> > > cmatrix;
vector<complex<double> > input_vector;
int matrix_size, matrix_amount, depth, row, col;
complex<double> temp_cmpl_db;
string temp_str_gtl_mat_dt, temp_str_gtl_int_dt; //temporary strings for retrieving matrices
/*if(!argv)
{
cout << "error: no input file specified" << endl;
return 1;
}*/
fstream input_file("example.txt");
chmatrix input_matrices_transfer;
if(input_file.is_open())
{
getline(input_file, temp_str_gtl_int_dt, ' ');
matrix_amount = stoi(temp_str_gtl_int_dt, nullptr);
getline(input_file, temp_str_gtl_int_dt, ' ');
matrix_size = stoi(temp_str_gtl_int_dt, nullptr);
chmatrix input_matrices(matrix_size, vector<vector<complex<double> > >(matrix_size, vector<complex<double> >(matrix_amount)));
chmatrix input_matrices_temp(matrix_size, vector<vector<complex<double> > >(matrix_size, vector<complex<double> >(matrix_amount)));
for(unsigned int matrix_index = 0; matrix_index < matrix_amount*matrix_size*matrix_size; matrix_index++)
{
getline(input_file, temp_str_gtl_mat_dt, ' ');
cout << temp_str_gtl_mat_dt << endl;
if(temp_str_gtl_mat_dt != "\n")
{
depth = matrix_index/(matrix_size*matrix_size);
row = (matrix_index - (matrix_size*matrix_size*depth))%matrix_size;
col = (matrix_index - (matrix_size*matrix_size*depth))/matrix_size;
istringstream temp_conv_comp(temp_str_gtl_mat_dt);
temp_conv_comp >> input_matrices[row][col][depth];
cout << input_matrices[row][col][depth] << endl; //this works
};
cout << input_matrices[2][2][2] << endl; //this also works
input_matrices_transfer = input_matrices;
};
input_file.close();
cout << input_matrices_transfer[2][2][2] << endl; //this doesn't work
}
else
{
cout << "error: cannot find/open input file" << endl;
return 1;
};
return 0;
};
|