-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change eddy cuda assumptions #192
Change eddy cuda assumptions #192
Conversation
Before we merge this, I thought of a potential problem. Namely, when I |
As written, it would be a problem if we made the trap work in functions, yes - you should do |
Why not just wrap that section with |
Because doing it correctly (making the conditional actually use the command that does the test) is cleaner than the current code, let alone adding disable/enable around the current code? |
diff -q ${g_stdEddy} ${g_gpuEnabledEddy} > /dev/null | ||
return_code=$? | ||
if [ "${return_code}" -eq "0" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff -q ${g_stdEddy} ${g_gpuEnabledEddy} > /dev/null | |
return_code=$? | |
if [ "${return_code}" -eq "0" ]; then | |
# diff returns true when files are the same, which we want to treat as an error | |
if diff -q "${g_stdEddy}" "${g_gpuEnabledEddy}" > /dev/null; then |
I had it backwards, we don't want a negation, because we want to take the conditional when the files are the same. I have suggested the edit. |
So, simply by putting the command within an |
Correct, conditional tests do not trigger bash manpage:
This is slightly misleading, as |
Ok, should be robust against error trapping now. |
# Check if files differ (which is what we want) within an 'if' statement | ||
# so that we don't trigger any active error trapping if they do differ. | ||
# 'diff' returns "true" if files are the same, in which case we want to abort. | ||
# Don't wrap the 'diff' command in () or [], as that will likely change the behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, ()
specifies a subshell (which does not behave like $()
, which additionally captures stdout and returns it as a string), which in this case should do the same thing (same exit status as the last command it executed). (())
specifies a mathematical expression, with special syntax, []
uses a builtin [
command that treats its arguments as a conditional expression (similar to the test
builtin), and [[]]
is bash syntax that behaves mostly like [
, but with some enhancements (playing nicely with &&
and ||
inside the expression).
if
doesn't have any special syntax rules (it treats its arguments like any other bash command), those []
, etc constructs can be used anywhere, it's just that if
and while
are usually the only things that need to use []
or similar (because everywhere else in a script, you generally don't want things returning nonzero exit codes, which is how [
and similar signal "false").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I not have merged this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commits are fine, I was commenting on a comment, for explanatory purposes, not suggesting a change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove the last line of the comment if you want (and just push the change directly to master), but are you saying that using ()
, $()
, or []
would all survive the error trapping as well, in the case when the files differ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Using []
would change the expected syntax (because [
is particular about what its arguments are), and would throw an error. Using $()
would be wrong, as if
would then try to execute whatever string came from stdout of the diff (but it is redirected currently, so if
would always try to execute the empty string).
I am not suggesting a change, just trying to explain why []
would fail. if
itself doesn't have special syntax, but whatever you put after if
sets the syntax for anything that comes after it ([
accepts arguments like -e somefile ]
, (())
takes integer arithmetic, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is a less roundabout explanation: every if [
statement was already using a nonzero exit status, whenever the condition was false, because a nonzero exit status was always the only way to tell if
to skip the then
section and do the else
section if it exists - [
was just the command that was giving the exit status:
tim@blackbox:~$ [ -e foo ]
tim@blackbox:~$ echo $?
1
Thus, nonzero exit status in an if
or while
, etc. is expected, and therefore these are specially exempted from the trap ERR
and set -e
rules.
This PR should make the automatic detection of the GPU-enabled version of
eddy
a bit more robust.