Skip to content
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

Bugfix: sort variant #111

Open
HPCguy opened this issue Aug 14, 2024 · 1 comment
Open

Bugfix: sort variant #111

HPCguy opened this issue Aug 14, 2024 · 1 comment

Comments

@HPCguy
Copy link
Owner

HPCguy commented Aug 14, 2024

Optimizer bug needs to be fixed for this test case (optimizer effectively creates a NOP!):

#include <stdio.h>
#include <stdlib.h>

void bubblesort(float *c, int n)
{
   float v1, v2;
   int i, done;

   do {
      done = 1; // --n;
      v1 = c[0];
      for (i=1; i<n; ++i) {
         v2 = c[i];
         if (v1 > v2) {
            c[i-1] = v2;
            c[i] = v1;
            done = 0;
         }
         else
            v1 = v2;
      }
   } while (!done);
}

int main()
{
   int i;
   float val[20];

   for (i=0; i<20; ++i)
      val[i] = (float) rand();

   bubblesort(val, 20);

   for (i=0; i<20; ++i)
      printf("%f\n", val[i]);
   printf("\n");

   return 0;
}


@HPCguy
Copy link
Owner Author

HPCguy commented Aug 14, 2024

Interestingly, the integer version of the function works fine when optimized:

void bubblesort(int *c, int n)
{
   int v1, v2;
   int i, done;

   do {
      done = 1; // --n;
      v1 = c[0];
      for (i=1; i<n; ++i) {
         v2 = c[i];
         if (v1 > v2) {
            c[i-1] = v2;
            c[i] = v1;
            done = 0;
         }
         else
            v1 = v2;
      }
   } while (!done);
}

I think I just forgot to carry over some of the integer optimiation to the floating point code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant