w04-g03-read-input
Read input file into arrays of correct length
Objective
Adapt the previously developed code in read_input_fixed.cpp
, such that arrays are allocated the exact appropriate size. The input file to read is the same as previously provided.
Implementation
-
Use the file named
read_input.cpp
as a starting point, which is provided in thetehpc/basics/
directory. The input fileread_input_fixed.inp
is already provided in there too. -
Fill in code to read the input file such that each array is allocated the minimum needed size. Focus on the
nodes
section only; you can neglect the other sections for now. Assume that the order in which the keywords appear could be different in an other input file. Remember that you can copy from last week's code. Hint: we first want to read the file, find the relevant section, and store it before we do anything with it. -
Print the arrays to the terminal to verify the correctness of your code.
-
Make sure that your code is well structured and commented.
Notes
Compile and run your code by:
- going into the
tehpc/build/
folder - (if you haven't done so before) copy the input file
read_input_fixed.inp
into this folder - compile with the following command:
g++ -Werror -Wpedantic -g -o read_input ../basics/read_input.cpp
- run code with
./read_input