#604: LocalReduce: Initialize variables to avoid compiler warnings -------------------------+-------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: new Priority: minor | Milestone: Component: Cactus | Version: development version Keywords: | -------------------------+-------------------------------------------------- The following one-line change would initialize the inval variable, avoiding compiler warnings for almost all variable types.
{{{ Index: local_reductions.h =================================================================== --- local_reductions.h (revision 86) +++ local_reductions.h (working copy) @@ -32,6 +32,7 @@ iter = 0; \ sum_indices = 0; \ num_points = 1; \ + REDUCTION_INITIAL(inval) \ REDUCTION_INITIAL( * outval) \ \ if ( N_dims == 0 ) \ }}}
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: review Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: --------------------------+------------------------------------------------- Changes (by knarf):
* status: new => review
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: review Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: --------------------------+-------------------------------------------------
Comment (by eschnett):
This seems to be a harmless change.
Why does the compiler warn?
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: review Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: --------------------------+-------------------------------------------------
Comment (by knarf):
Potential use of uninitialized memory
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: review Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: --------------------------+-------------------------------------------------
Comment (by eschnett):
I mean, is this a real possibility in the source code, or is the compiler just not clever enough to understand the source code? I notice e.g. some funny games with .Re and .Im and complex numbers.
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: review Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: --------------------------+-------------------------------------------------
Comment (by knarf):
It complains about .Im, also for non-complex variable types, so I assume it's the compiler not understanding the logic. However, I didn't look too closely and it might actually access .Im even for non-complex types. It doesn't look bad to me to initialize that memory in any case, and it also does not look like it would affect performance in any measurable way (by looking at the code, not by trying to measure it).
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: review Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: | Keywords: --------------------------+-------------------------------------------------
Comment (by eschnett):
There is a bit of complexity since e.g. the L2 norm of complex numbers results in a real number. I don't know how/whether the code handles this.
I also remember that some of the reduction operations give wrong values for complex numbers.
The patch seems harmless, please apply.
#604: LocalReduce: Initialize variables to avoid compiler warnings --------------------------+------------------------------------------------- Reporter: knarf | Owner: Type: enhancement | Status: closed Priority: minor | Milestone: Component: Cactus | Version: development version Resolution: fixed | Keywords: --------------------------+------------------------------------------------- Changes (by eschnett):
* status: review => closed * resolution: => fixed
Comment:
Applied.
trac@lists.einsteintoolkit.org