Open nicksmithc102 opened 8 years ago
I would encourage you to do so, partly because it makes the code clearer, and partly because it lets you test/debug the pieces separately.
It's almost always better to write shorter, more specific functions than to throw many different operations into one big function. There can be some "overhead" to function calls that reduces performance, but in practice, that overhead is (a) small, and (b) easy to get rid of via function "inlining" in most cases (in fact the compiler often does this kind of optimization automatically for you with -O2
or -O3
).
Can these methods be made, used and called without creating another data structure?
Also, if an inline function is used does it need to be declared in the header file?
@philw16:
about inlining: the compiler optimization features that @quantheory talked about is different from the inline
keyword that you mean. They are somewhat related -- the inline
keyword is a hint to the compiler that you'd like this function inlined during compilation, but the compiler can ignore it if necessary.
Could you clarify why you want your functions inlined?
about creating data structures: yes it should be possible to get by without creating new data structures. This is generally the case when the function being called is free to modify the data provided to it. Sometimes calling functions don't want the functions they call to modify any of the data they pass, in which case it is necessary to create new data structures to contain the data to return. In any case it depends on how the functions are implemented. Could you clarify what you had in mind?
I understand that the function could be constructed such that it simply updates the contents of what is provided with new values. However, in computing error don't there need to be a difference of two vectors to provide something to take the norm of? I can't see how this could be possible without creating another array to store one iteration of either method to compare to the previous
However, in computing error don't there need to be a difference of two vectors to provide something to take the norm of?
Of course. You will most likely need to create temporary storage space within your jacobi
and gauss_seidel
functions to store intermediate results.
Remember that "Premature optimization is the root of all evil." Get something working, first, and then worry about inline
functions, reducing memory footprints, etc.
In homework 1, we made a module that would decompose a matrix,, another that would perform a single iteration of the algorithm, and other that would use the single iteration function to perform the whole algorithm. Will we need to do something equivalent in this homework? That is, should we write extra, separate functions (within solvers.c, perhaps?) to do these things?