/mobile Handheld Friendly website

 performance measurements

Each table row shows performance measurements for this C++ g++ program with a particular command-line input value N.

 N  CPU secs Elapsed secs Memory KB Code B ≈ CPU Load
10Make Error  1059   

Read the ↓ make, command line, and program output logs to see how this program was run.

Read fannkuch-redux benchmark to see what this program should do.

 notes

gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu8)

 fannkuch-redux C++ g++ program source code

/* The Computer Language Benchmarks Game
   http://benchmarksgame.alioth.debian.org/

   contributed by Branimir Maksimovic
   first permutation algo taken from Miroslav Rubanets program
*/
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <future>
#include <unistd.h>

typedef unsigned char int_t;

void rotate(int_t* p, int n)
{
   int_t tmp = p[0];
   for(int i = 0; i < n; ++i)p[i]=p[i+1];
   p[n] = tmp;
}

void next_permutation(int_t* beg, int n, int_t* c)
{
   int i = 1;
   while(i<n)
   {
      rotate(beg,i);
      if(c[i]>=i)c[i++]=0;
      else break;
   }
   ++c[i];
}

class Perm{
public:
struct P{
   int_t p[16];
};
Perm(unsigned n)
: cnt {0},n(n),permcount(0)
{
   fact[0]=1;
   for(unsigned i=1;i<n+1;++i)
   {
      fact[i]=fact[i-1]*i;
   }
}
P get(int idx)
{ 
    char pp[16]={};
    permcount = idx;
    int_t i = 0;
    std::generate(perm.p,perm.p+n,[&i](){return ++i;});
    for ( unsigned i=n-1; i>0; --i ) {
        unsigned d = idx / fact[i];
        cnt[i] = d;
        idx = idx % fact[i];
        std::copy( &perm.p[0], &perm.p[i+1], &pp[0] );
        for (unsigned j=0; j<=i; ++j ){
         perm.p[j] = j+d <= i ? pp[j+d] : pp[j+d-i-1];
      }
    }
   return perm;
}
P next()
{
   next_permutation(perm.p,n,cnt);
   ++permcount;
   return perm;
}
unsigned count()const { return permcount; }
unsigned max()const { return fact[n]; }
private:
   int_t cnt[16];
   unsigned fact[16],n,permcount;
   P perm;
};

struct Result{
   int checksum;
   int maxflips;
};

Result work(Perm perm,unsigned n,unsigned max)
{
   Result r={0};
   Perm::P p = perm.get(n);
   for(; perm.count()<max;p=perm.next())
   {
      int flips = 0;
      while(p.p[0] != 1)
      {
         std::reverse(p.p,p.p+p.p[0]);
         ++flips;
      }
      r.checksum += (perm.count()%2 == 0)?flips:-flips;
      r.maxflips = std::max(r.maxflips,flips);
   }
   return r;
}

Result fannkuch(int n)
{
   Result tmp = {0};
   Perm perm(n);
   
   unsigned N = sysconf(_SC_NPROCESSORS_ONLN);
   std::future<Result> ft[N];
   
   unsigned k = perm.max()/N;
   unsigned j = 0;
   for(unsigned i = 0 ; i < N;++i,j+=k)
   {
      unsigned max = i<N-1?j+k:perm.max();
      ft[i] = std::async(std::launch::async,work,perm,j,max);
   }
   for(unsigned i = 0; i < N; ++i)
   {
      auto r = ft[i].get();
      tmp.checksum += r.checksum;
      tmp.maxflips = std::max(tmp.maxflips,r.maxflips);
   }
   return tmp;
}

int main(int argc, char** argv)
{
   int n = 7;
   if(argc > 1)n = atoi(argv[1]);
   if(n < 3 || n > 12)
   {
      printf("n should be between [3 and 12]\n");
      return 0;
   }
   Result r = fannkuch(n);
   printf("%d\nPfannkuchen(%d) = %d\n",r.checksum,n,r.maxflips);
}

 make, command-line, and program output logs

Sun, 27 Oct 2013 22:13:00 GMT

MAKE:
/usr/bin/g++ -c -pipe -O3 -fomit-frame-pointer -march=native  -pthread -flax-vector-conversions fannkuchredux.c++ -o fannkuchredux.c++.o &&  \
        /usr/bin/g++ fannkuchredux.c++.o -o fannkuchredux.gpp_run -lpthread -lboost_thread 
In file included from /usr/include/c++/4.8/future:35:0,
                 from fannkuchredux.c++:10:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
fannkuchredux.c++: In constructor ‘Perm::Perm(unsigned int)’:
fannkuchredux.c++:40:3: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
 : cnt {0},n(n),permcount(0)
   ^
fannkuchredux.c++: In member function ‘Perm::P Perm::get(int)’:
fannkuchredux.c++:53:53: warning: lambda expressions only available with -std=c++11 or -std=gnu++11 [enabled by default]
     std::generate(perm.p,perm.p+n,[&i](){return ++i;});
                                                     ^
fannkuchredux.c++:53:54: error: no matching function for call to ‘generate(int_t [16], int_t*, Perm::get(int)::__lambda0)’
     std::generate(perm.p,perm.p+n,[&i](){return ++i;});
                                                      ^
fannkuchredux.c++:53:54: note: candidate is:
In file included from /usr/include/c++/4.8/algorithm:62:0,
                 from fannkuchredux.c++:9:
/usr/include/c++/4.8/bits/stl_algo.h:5048:5: note: template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)
     generate(_ForwardIterator __first, _ForwardIterator __last,
     ^
/usr/include/c++/4.8/bits/stl_algo.h:5048:5: note:   template argument deduction/substitution failed:
fannkuchredux.c++: In substitution of ‘template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator) [with _FIter = unsigned char*; _Generator = Perm::get(int)::__lambda0]’:
fannkuchredux.c++:53:54:   required from here
fannkuchredux.c++:53:54: error: template argument for ‘template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)’ uses local type ‘Perm::get(int)::__lambda0’
     std::generate(perm.p,perm.p+n,[&i](){return ++i;});
                                                      ^
fannkuchredux.c++:53:54: error:   trying to instantiate ‘template<class _FIter, class _Generator> void std::generate(_FIter, _FIter, _Generator)’
fannkuchredux.c++: In function ‘Result fannkuch(int)’:
fannkuchredux.c++:108:4: error: ‘future’ is not a member of ‘std’
    std::future<Result> ft[N];
    ^
fannkuchredux.c++:108:22: error: expected primary-expression before ‘>’ token
    std::future<Result> ft[N];
                      ^
fannkuchredux.c++:108:24: error: ‘ft’ was not declared in this scope
    std::future<Result> ft[N];
                        ^
fannkuchredux.c++:115:15: error: ‘async’ is not a member of ‘std’
       ft[i] = std::async(std::launch::async,work,perm,j,max);
               ^
fannkuchredux.c++:115:31: error: ‘std::launch’ has not been declared
       ft[i] = std::async(std::launch::async,work,perm,j,max);
                               ^
fannkuchredux.c++:119:12: error: ‘r’ does not name a type
       auto r = ft[i].get();
            ^
fannkuchredux.c++:120:23: error: ‘r’ was not declared in this scope
       tmp.checksum += r.checksum;
                       ^
make: [fannkuchredux.gpp_run] Error 1 (ignored)
rm fannkuchredux.c++
0.15s to complete and log all make actions

COMMAND LINE:
./fannkuchredux.gpp_run 10

MAKE ERROR 

Revised BSD license

  Home   Conclusions   License   Play