unverständliche Fehlermeldungen:

hallo,
ich kapier's nicht- ich bekomme Fehlermeldungen mit Verweis auf Zeilennummern, die überhaupt keinen entspechenden Code enthalten -
z.B. kommen M, K und N überhaupt nicht in Zeilen 11-12 vor!

Arduino: 1.5.6-r2 (Windows XP), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

ArduBench0002:11: error: 'M' was not declared in this scope
ArduBench0002:11: error: 'K' was not declared in this scope
ArduBench0002:11: error: 'K' was not declared in this scope
ArduBench0002:12: error: 'N' was not declared in this scope
ArduBench0002:12: error: 'N' was not declared in this scope
ArduBench0002.ino: In function 'long unsigned int randM()':
ArduBench0002:20: error: 'conast' was not declared in this scope
ArduBench0002:20: error: expected `;' before 'unsigned'
ArduBench0002:36: error: 'A' was not declared in this scope
ArduBench0002:38: error: 'A' was not declared in this scope
ArduBench0002.ino: At global scope:
ArduBench0002:55: error: 'M' was not declared in this scope
ArduBench0002:55: error: 'K' was not declared in this scope
ArduBench0002:55: error: 'K' was not declared in this scope
ArduBench0002.ino: In function 'void MatrixMatrixMult(int, int, int)':

//... SNIP

was ist denn da los?
(ein anderes Programm mit serieller Ausgabe funktioniert übrigens einwandfrei.)

// version 1.08.0002



#define TimerMS() millis()

unsigned long runtime[8];

int a[500], b[500], c[500], t[500];

//--------------------------------------------
// Mersenne Twister
//--------------------------------------------

unsigned long randM(void) {
   
   const int M = 7;
   conast unsigned long A[2] = { 0, 0x8ebfd028 };

   static unsigned long y[25];
   static int index = 25+1;

   if (index >= 25) {
     int k;
     if (index > 25) {
        unsigned long r = 9, s = 3402;
        for (k=0 ; k<25 ; ++k) {
          r = 509845221 * r + 3;
          s *= s + 1;
          y[k] = s + (r >> 10);
        }
     }
     for (k=0 ; k<25-M ; ++k)
        y[k] = y[k+M] ^ (y[k] >> 1) ^ A[y[k] & 1];
     for (; k<25 ; ++k)
        y[k] = y[k+(M-25)] ^ (y[k] >> 1) ^ A[y[k] & 1];
     index = 0;
   }

   unsigned long e = y[index++];
   e ^= (e << 7) & 0x2b5b2500;
   e ^= (e << 15) & 0xdb8b0000;
   e ^= (e >> 16);
   return e;
}

//--------------------------------------------
// Matrix Algebra
//--------------------------------------------

// matrix * matrix multiplication (matrix product)

void MatrixMatrixMult(int N, int M, int K, double A[][M], double B[][K], double C[][K]){
  int i, j, s;                                       // matrix A: N x M // B: M x K // C: N x K
  for (i=0; i<N; ++i) {
    for (j=0; j<K; ++j) {
       C[i][j]=0;
       for (s=0; s<M; ++s) {
         C[i][j]=C[i][j] + A[i][s]*B[s][j];
      }
    }
  }
}


// matrix determinant

double MatrixDet(int N, double A[N][N])
{
    int i,j,i_count,j_count, count=0;
    double Asub[N-1][N-1], det=0;

    if(N==1) return A[0][0];
    if(N==2) return (A[0][0]*A[1][1] - A[0][1]*A[1][0]);

    for(count=0; count<N; count++)
    {
        i_count=0;
        for(i=1; i<N; i++)
        {
            j_count=0;
            for(j=0; j<N; j++)
            {
                if(j == count) continue;
                Asub[i_count][j_count] = A[i][j];
                j_count++;
            }
            i_count++;
        }
        det += pow(-1, count) * A[0][count] * MatrixDet(N-1,Asub);
    }
    return det;
}


//--------------------------------------------
// shell sort
//--------------------------------------------

void shellsort(int size, int* A)
{
  int i, j, increment;
  int temp;
  increment = size / 2;

  while (increment > 0) {
    for (i = increment; i < size; i++) {
      j = i;
      temp = A[i];
      while ((j >= increment) && (A[j-increment] > temp)) {
        A[j] = A[j - increment];
        j = j - increment;
      }
      A[j] = temp;
    }

    if (increment == 2)
       increment = 1;
    else
       increment = (unsigned int) (increment / 2.2);
  }
}

//--------------------------------------------
// gnu quick sort
// (0ptional)
//--------------------------------------------

int compare_int (const int *a, const int *b)
{
  int  temp = *a - *b;

  if (temp > 0)          return  1;
  else if (temp < 0)     return -1;
  else                   return  0;
}

// gnu qsort:
// void qsort (void *a , size_a count, size_a size, compare_function)
// gnu qsort call for a[500] array of int:
// qsort (a , 500, sizeof(a), compare_int)



//--------------------------------------------
// benchmark test procedures
//--------------------------------------------


int test_Int_Add() {
   int i=1, j=11, k=112, l=1111, m=11111, n=-1, o=-11, p=-111, q=-1112, r=-11111;
   int x;
   volatile long s=0;
   for(x=0;x<10000;++x) {
     s+=i; s+=j; s+=k; s+=l; s+=m; s+=n; s+=o; s+=p; s+=q; s+=r;
   }
   return s;
}



long test_Int_Mult() {
  int x,y;
  volatile long s;

  for(y=0;y<2000;++y) {
    s=1;
    for(x=1;x<=13;++x) { s*=x;}
    for(x=13;x>0;--x) { s/=x;}

  }
  return s;
}


#define PI  M_PI


float test_float_math() {

  volatile float s=PI;
  int y;

  for(y=0;y<5000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s*=cos(10.5*s);
     s=sqrt(s);
     s=exp(s);
  }
  return s;
}


long test_rand_MT(){
  volatile unsigned long s;
  int y;

  for(y=0;y<5000;++y) {
     s=randM()%10001;
  }
  return s;
}


float test_matrix_math() {
  int x;

  double A[2][2], B[2][2], C[2][2];
  double O[3][3], T[3][3];
  unsigned long s;

  for(x=0;x<250;++x) {

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    B[0][0]=10;  B[0][1]=30;
    B[1][0]=20;  B[1][1]=40;

    MatrixMatrixMult(2,2,2, A,B,C);

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    MatrixDet(2, A);

    O[0][0]=1;   O[0][1]=4;  O[0][2]=7;
    O[1][0]=2;   O[1][1]=5;  O[1][2]=8;
    O[2][0]=3;   O[2][1]=6;  O[2][2]=9;

    MatrixDet(3, O);

  }

  s=(O[0][0]*O[1][1]*O[2][2]);
  return s;
}



// for array copy using void *memcpy(void *dest, const void *src, size_t n);

long test_Sort(){
  unsigned long s;
  int y, i;
  int t[500];

  for(y=0;y<30;++y) {
    memcpy(t, a, sizeof(a));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(b));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(c));
    shellsort(500, t);
  }

  return y;
}

inline void displayValues() {

  char buf[120];

    sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); serial.println( buf);
    sprintf (buf, "%3d %4d  int_Mult",   1, runtime[1]); serial.println( buf);
    sprintf (buf, "%3d %4d  float_op",   2, runtime[2]); serial.println( buf);
    sprintf (buf, "%3d %4d  randomize",  3, runtime[3]); serial.println( buf);
    sprintf (buf, "%3d %4d  matrx_algb", 4, runtime[4]); serial.println( buf);
    sprintf (buf, "%3d %4d  arr_sort",   5, runtime[5]); serial.println( buf);
    sprintf (buf, "%3d %4d  displ_txt",  6, runtime[6]); serial.println( buf);
    sprintf (buf, "%3d %4d  graphics",   7, 99999); serial.println( buf);
    sprintf (buf, "%3d %4d  graphics",   8, 99999); serial.println( buf);
}


void Handler(int sig)               /// ???
{
  //printf("handler %d\n", sig);    /// ???
}

int test(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int   i;

  
  for(y=0;y<500;++y) {
    a[y]=randM()%30000; b[y]=randM()%30000; c[y]=randM()%30000;
  }


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); serial.println( buf);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Mult",   0, runtime[1]); serial.println( buf);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  float_op",   0, runtime[2]); serial.println( buf);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  randomize",  0, runtime[3]); serial.println( buf);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  matrx_algb", 0, runtime[4]); serial.println( buf);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  arr_sort",   0, runtime[5]); serial.println( buf);

  serial.println();
 
  sprintf (buf, "gesamt ms: %d ", y);           serial.println( buf);
  sprintf (buf, "benchmark: %d ", 50000000/y ); serial.println( buf);

  return 1;

}



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  //test();
  sprintf (buf, "Ende HaWe brickbench");           serial.println( buf);
  while(1);
}

Blödmann

void MatrixMatrixMult(int N, int M, int K, double A[][M], double B[][K], double C[][K])

Das geht nur in C99, da es da einen speziellen Array Typ bei dem die Dimension erst zur Laufzeit ausgewertet wird. Ansonsten muss die Dimension zur Compile-Zeit feststehen

Die Lösung steht hier:

Am einfachsten sind ganz normale Zeiger (Visual C++ Test Code):

void printArray(int* data, int dim1, int dim2)
{
	for(int i = 0; i < dim1; i++)
		for(int j = 0; j < dim2; j++)
			cout << *((data + i * dim2) + j) << endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
	double A[2][2] = { { 1, 2}, { 3, 4 } };
	double O[3][3] = { { 1, 2, 3}, { 4, 5, 6 }, { 7, 8, 9 }};


	printArray((double*)A, 2, 2);
	cout << endl;
	printArray((double*)O, 3, 3);

	getchar();
	return 0;
}

Beachte den Cast auf double* beim Funktionsaufruf! Sonst gibt es Mecker.

Du musst aber beim Zugriff auf das Element sowie es aussieht mit Zeiger-Arithmetik arbeiten, da der Doppel Subscript Operator da leider nicht funktioniert.

Welchen Arduino verwendest Du denn?
Grüße Uwe

Steht doch dort. Atmega2560

Hat aber damit nichts zu tun. Es ist einfach ein Compiler Problem. Ohne "variable length arrays" geht das so schlichtweg nicht:

Die wurden aber in C++ nicht übernommen, da es da in der STL Container Klassen wie std::vector gibt, aber die gibt es auf dem Arduino standardmäßig nicht

danke für die Antworten!
Sketch-Compiler-Problem verstehe ich, C++ aber nicht, denn der Originalcode ist reines ANSI C99, es läuft alles ohne Probleme unter gpp C ohne C++ Klassen mit dem 2009er Compiler, und spätere ANSI C Standards sind doch auch rückwärtskompatibel...!?
Andererseits: der neue C11-Standard wird doch von Sketch auch nicht unterstützt, denn sonst müsste es ja auch preemptives Multitasking unterstützen (in C11 enhalten!).

Die Größe der Matrizen steht andererseits zum Compilierzeitpunkt nicht fest, es sollen ja zur Laufzeit verschieden große Matrizen bzw. Arrays ausgewertet werden können.
VLAs gehen auch nicht:

"Dabei ist zu beachten, dass VLAs nicht initialisiert werden können...und die Größe nur einmalig bei der Definition festgelegt werden kann."

Mehrdimensionale Arrays (Matrizen) mit variabler Größe kommen aber auch in anderen Programmen bei mir sehr häufig vor - die quasi linearisieren zu müssen mit Pointer aufs 1. Element wird ein ziemliches konfuses Gewurschtel mit Sketch. Das ist wirklich dumm, dass das nicht vom Sketch Compiler unterstützt wird.

ps, ohne double ist es für Matrizenrechnung aber auch nicht sinnvoll:
wenn man in der numerischen Analysis linerare Gleichungssysteme (Matrizen) mit float "löst" , kommt es sehr oft zu falschen Ergebnissen, erst double hat hier die ausreichende Rechengenauigkeit.
Ich hatte mal einen Fall, da hatte eine Matrize die Determinante Null (denn sie war nicht linear unabhängig), da ergab die Berechnung mit float 24 (!), mit double aber korrekt 0.

HaWe:
Mehrdimensionale Arrays (Matrizen) mit variabler Größe kommen aber auch in anderen Programmen bei mir sehr häufig vor - die quasi linearisieren zu müssen mit Pointer aufs 1. Element wird ein ziemliches konfuses Gewurschtel mit Sketch. Das ist wirklich dumm, dass das nicht vom Sketch Compiler unterstützt wird.

Dumm ist der, der Dummes tut.

void MatrixMatrixMult(int N, int M, int K, float *A, float *B, float *C) {
   int i, j, s;
   for (i = 0; i < N; ++i) {
      for (j = 0; j < K; ++j) {
         C[i*K+j] = 0;
         for (s = 0; s < M; ++s) {
            C[i*K+j] = C[i*K+j] + A[i*N+s] * B[s*M+j];
         }
      }
   }
}

ja, das ist klar, so dumm bin ich auch nicht :slight_smile:

jetzt stell dir das aber mal nicht mit 2-dim sondern mit 9-dim arrays vor....

außerdem bekomme ich dann immer noch haufenweise ähnliche Fehlermeldungen:
(Zeile 11 etc...)

Arduino: 1.5.6-r2 (Windows XP), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

ArduBench0002:11: error: 'N' was not declared in this scope
ArduBench0002:11: error: 'N' was not declared in this scope
ArduBench0002.ino: In function 'long unsigned int randM()':
ArduBench0002:19: error: 'conast' was not declared in this scope
ArduBench0002:19: error: expected `;' before 'unsigned'
ArduBench0002:35: error: 'A' was not declared in this scope
ArduBench0002:37: error: 'A' was not declared in this scope
ArduBench0002.ino: At global scope:
ArduBench0002:69: error: 'N' was not declared in this scope
ArduBench0002:69: error: 'N' was not declared in this scope
ArduBench0002.ino: In function 'double MatrixDet(int)':
ArduBench0002:74: error: 'A' was not declared in this scope
ArduBench0002:75: error: 'A' was not declared in this scope
ArduBench0002:86: error: 'A' was not declared in this scope
ArduBench0002:91: error: 'A' was not declared in this scope
ArduBench0002:69: error: too many arguments to function 'double MatrixDet(int)'
ArduBench0002:91: error: at this point in file
ArduBench0002.ino: In function 'float test_matrix_math()':
ArduBench0002:222: error: cannot convert 'double ()[2]' to 'float' for argument '4' to 'void MatrixMatrixMult(int, int, int, float*, float*, float*)'
ArduBench0002:69: error: too many arguments to function 'double MatrixDet(int)'
ArduBench0002:227: error: at this point in file
ArduBench0002:69: error: too many arguments to function 'double MatrixDet(int)'
ArduBench0002:233: error: at this point in file
// SNIP

// version 1.08.0003



#define TimerMS() millis()

unsigned long runtime[8];

int a[500], b[500], c[500], t[500];

//--------------------------------------------
// Mersenne Twister
//--------------------------------------------

unsigned long randM(void) {
   
   const int M = 7;
   conast unsigned long A[2] = { 0, 0x8ebfd028 };

   static unsigned long y[25];
   static int index = 25+1;

   if (index >= 25) {
     int k;
     if (index > 25) {
        unsigned long r = 9, s = 3402;
        for (k=0 ; k<25 ; ++k) {
          r = 509845221 * r + 3;
          s *= s + 1;
          y[k] = s + (r >> 10);
        }
     }
     for (k=0 ; k<25-M ; ++k)
        y[k] = y[k+M] ^ (y[k] >> 1) ^ A[y[k] & 1];
     for (; k<25 ; ++k)
        y[k] = y[k+(M-25)] ^ (y[k] >> 1) ^ A[y[k] & 1];
     index = 0;
   }

   unsigned long e = y[index++];
   e ^= (e << 7) & 0x2b5b2500;
   e ^= (e << 15) & 0xdb8b0000;
   e ^= (e >> 16);
   return e;
}

//--------------------------------------------
// Matrix Algebra
//--------------------------------------------

// matrix * matrix multiplication (matrix product)
 
 void MatrixMatrixMult(int N, int M, int K, float *A, float *B, float *C) {
   int i, j, s;
   for (i = 0; i < N; ++i) {
      for (j = 0; j < K; ++j) {
         C[i*K+j] = 0;
         for (s = 0; s < M; ++s) {
            C[i*K+j] = C[i*K+j] + A[i*N+s] * B[s*M+j];
         }
      }
   }
}


// matrix determinant

double MatrixDet(int N, double A[N][N])
{
    int i,j,i_count,j_count, count=0;
    double Asub[N-1][N-1], det=0;

    if(N==1) return A[0][0];
    if(N==2) return (A[0][0]*A[1][1] - A[0][1]*A[1][0]);

    for(count=0; count<N; count++)
    {
        i_count=0;
        for(i=1; i<N; i++)
        {
            j_count=0;
            for(j=0; j<N; j++)
            {
                if(j == count) continue;
                Asub[i_count][j_count] = A[i][j];
                j_count++;
            }
            i_count++;
        }
        det += pow(-1, count) * A[0][count] * MatrixDet(N-1,Asub);
    }
    return det;
}


//--------------------------------------------
// shell sort
//--------------------------------------------

void shellsort(int size, int* A)
{
  int i, j, increment;
  int temp;
  increment = size / 2;

  while (increment > 0) {
    for (i = increment; i < size; i++) {
      j = i;
      temp = A[i];
      while ((j >= increment) && (A[j-increment] > temp)) {
        A[j] = A[j - increment];
        j = j - increment;
      }
      A[j] = temp;
    }

    if (increment == 2)
       increment = 1;
    else
       increment = (unsigned int) (increment / 2.2);
  }
}

//--------------------------------------------
// gnu quick sort
// (0ptional)
//--------------------------------------------

int compare_int (const int *a, const int *b)
{
  int  temp = *a - *b;

  if (temp > 0)          return  1;
  else if (temp < 0)     return -1;
  else                   return  0;
}

// gnu qsort:
// void qsort (void *a , size_a count, size_a size, compare_function)
// gnu qsort call for a[500] array of int:
// qsort (a , 500, sizeof(a), compare_int)



//--------------------------------------------
// benchmark test procedures
//--------------------------------------------


int test_Int_Add() {
   int i=1, j=11, k=112, l=1111, m=11111, n=-1, o=-11, p=-111, q=-1112, r=-11111;
   int x;
   volatile long s=0;
   for(x=0;x<10000;++x) {
     s+=i; s+=j; s+=k; s+=l; s+=m; s+=n; s+=o; s+=p; s+=q; s+=r;
   }
   return s;
}



long test_Int_Mult() {
  int x,y;
  volatile long s;

  for(y=0;y<2000;++y) {
    s=1;
    for(x=1;x<=13;++x) { s*=x;}
    for(x=13;x>0;--x) { s/=x;}

  }
  return s;
}


#define PI  M_PI


float test_float_math() {

  volatile float s=PI;
  int y;

  for(y=0;y<5000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s*=cos(10.5*s);
     s=sqrt(s);
     s=exp(s);
  }
  return s;
}


long test_rand_MT(){
  volatile unsigned long s;
  int y;

  for(y=0;y<5000;++y) {
     s=randM()%10001;
  }
  return s;
}


float test_matrix_math() {
  int x;

  double A[2][2], B[2][2], C[2][2];
  double O[3][3], T[3][3];
  unsigned long s;

  for(x=0;x<250;++x) {

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    B[0][0]=10;  B[0][1]=30;
    B[1][0]=20;  B[1][1]=40;

    MatrixMatrixMult(2,2,2, A,B,C);

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    MatrixDet(2, A);

    O[0][0]=1;   O[0][1]=4;  O[0][2]=7;
    O[1][0]=2;   O[1][1]=5;  O[1][2]=8;
    O[2][0]=3;   O[2][1]=6;  O[2][2]=9;

    MatrixDet(3, O);

  }

  s=(O[0][0]*O[1][1]*O[2][2]);
  return s;
}



// for array copy using void *memcpy(void *dest, const void *src, size_t n);

long test_Sort(){
  unsigned long s;
  int y, i;
  int t[500];

  for(y=0;y<30;++y) {
    memcpy(t, a, sizeof(a));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(b));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(c));
    shellsort(500, t);
  }

  return y;
}

inline void displayValues() {

  char buf[120];

    sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); serial.println( buf);
    sprintf (buf, "%3d %4d  int_Mult",   1, runtime[1]); serial.println( buf);
    sprintf (buf, "%3d %4d  float_op",   2, runtime[2]); serial.println( buf);
    sprintf (buf, "%3d %4d  randomize",  3, runtime[3]); serial.println( buf);
    sprintf (buf, "%3d %4d  matrx_algb", 4, runtime[4]); serial.println( buf);
    sprintf (buf, "%3d %4d  arr_sort",   5, runtime[5]); serial.println( buf);
    sprintf (buf, "%3d %4d  displ_txt",  6, runtime[6]); serial.println( buf);
    sprintf (buf, "%3d %4d  graphics",   7, 99999); serial.println( buf);
    sprintf (buf, "%3d %4d  graphics",   8, 99999); serial.println( buf);
}


void Handler(int sig)               /// ???
{
  //printf("handler %d\n", sig);    /// ???
}

int test(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int   i;

  
  for(y=0;y<500;++y) {
    a[y]=randM()%30000; b[y]=randM()%30000; c[y]=randM()%30000;
  }


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); serial.println( buf);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Mult",   0, runtime[1]); serial.println( buf);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  float_op",   0, runtime[2]); serial.println( buf);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  randomize",  0, runtime[3]); serial.println( buf);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  matrx_algb", 0, runtime[4]); serial.println( buf);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  arr_sort",   0, runtime[5]); serial.println( buf);

  serial.println();
 
  sprintf (buf, "gesamt ms: %d ", y);           serial.println( buf);
  sprintf (buf, "benchmark: %d ", 50000000/y ); serial.println( buf);

  return 1;

}



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  //test();
  sprintf (buf, "Ende HaWe brickbench");           serial.println( buf);
  while(1);
}

HaWe:
außerdem bekomme ich dann immer noch haufenweise ähnliche Fehlermeldungen:

Deine gehäuften Fehlermeldungen liegen daran, dass Du haufenweise ungültige Funktionsdeklarationen im Programm hast.

Einer der "Magic Tricks" der Arduino-Software ist, dass der von Arduino tatsächlich kompilierte Code am Anfang Vorwärtsdeklarationen aller Deiner Funktionen eingesetzt bekommt, und wenn Du haufenweise ungültige Funktionsdeklarationen im Programm hast, werden zusätzlich am Anfang des compilierten Codes die ganzen ungültigen Funktionsdeklarationen nochmal als Vorwärtsdeklarationen eingefügt. Das führt zu den merkwürdigsten Compilerfehlern und Compiler-Folgefehlern mit Verweisen auf Zeilen im Sketch, die überhaupt keinen Fehler enthalten.

Du mußt erst alle syntaktisch und grammatikalisch falschen Funktionsdeklarationen in Deinem Sketch durch fehlerfreie Funktionsdeklarationen ersetzen, bevor die merkwürdigen Fehlermeldungen verschwinden.

Also auch Funktionen wie

double MatrixDet(int N, double A[N][N])

müssen durch Funktionen ersetzt werden, denen nur die Dimension und ein Pointer auf eine Matrix übergeben werden.

danke, jetzt habe ich das mit Zeile 11 usw verstanden!

edit, nach copy-and-paste Fehler:
ich blicks nicht - ich bin offenbar zu sehr ans ANSI C99 gewöhnt (und verstehe jetzt die umdefinierten Funktionen nicht mehr):

Arduino: 1.5.6-r2 (Windows XP), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

ArduBench0004.ino: In function 'float test_matrix_math()':
ArduBench0004:222: error: cannot convert 'float ()[2]' to 'float' for argument '4' to 'void MatrixMatrixMult(int, int, int, float*, float*, float*)'
ArduBench0004:227: error: cannot convert 'float ()[2]' to 'float' for argument '2' to 'float MatrixDet(int, float*)'
ArduBench0004:233: error: cannot convert 'float ()[3]' to 'float' for argument '2' to 'float MatrixDet(int, float*)'
ArduBench0004.ino: In function 'void loop()':

// version 1.08.0004



#define TimerMS() millis()

unsigned long runtime[8];

int a[500], b[500], c[500], t[500];

//--------------------------------------------
// Mersenne Twister
//--------------------------------------------

unsigned long randM(void) {
   
   const int M = 7;
   const unsigned long A[2] = { 0, 0x8ebfd028 };

   static unsigned long y[25];
   static int index = 25+1;

   if (index >= 25) {
     int k;
     if (index > 25) {
        unsigned long r = 9, s = 3402;
        for (k=0 ; k<25 ; ++k) {
          r = 509845221 * r + 3;
          s *= s + 1;
          y[k] = s + (r >> 10);
        }
     }
     for (k=0 ; k<25-M ; ++k)
        y[k] = y[k+M] ^ (y[k] >> 1) ^ A[y[k] & 1];
     for (; k<25 ; ++k)
        y[k] = y[k+(M-25)] ^ (y[k] >> 1) ^ A[y[k] & 1];
     index = 0;
   }

   unsigned long e = y[index++];
   e ^= (e << 7) & 0x2b5b2500;
   e ^= (e << 15) & 0xdb8b0000;
   e ^= (e >> 16);
   return e;
}

//--------------------------------------------
// Matrix Algebra
//--------------------------------------------

// matrix * matrix multiplication (matrix product)
 
 void MatrixMatrixMult(int N, int M, int K, float *A, float *B, float *C) {
   int i, j, s;
   for (i = 0; i < N; ++i) {
      for (j = 0; j < K; ++j) {
         C[i*K+j] = 0;
         for (s = 0; s < M; ++s) {
            C[i*K+j] = C[i*K+j] + A[i*N+s] * B[s*M+j];
         }
      }
   }
}


// matrix determinant

float MatrixDet(int N, float A[]) {
   int i, j, i_count, j_count, count = 0;
   float Asub[N - 1][N - 1], det = 0;

   if (N == 1)
      return *A;
   if (N == 2)
      return ((*A) * (*(A+1+1*N)) - (*(A+1*N)) * (*(A+1)));

   for (count = 0; count < N; count++) {
      i_count = 0;
      for (i = 1; i < N; i++) {
         j_count = 0;
         for (j = 0; j < N; j++) {
            if (j == count)
               continue;
            Asub[i_count][j_count] = *(A+i+j*N);
            j_count++;
         }
         i_count++;
      }
      det += pow(-1, count) * A[0+count*N] * MatrixDet(N - 1, &Asub[0][0]);
   }
   return det;
}



//--------------------------------------------
// shell sort
//--------------------------------------------

void shellsort(int size, int* A)
{
  int i, j, increment;
  int temp;
  increment = size / 2;

  while (increment > 0) {
    for (i = increment; i < size; i++) {
      j = i;
      temp = A[i];
      while ((j >= increment) && (A[j-increment] > temp)) {
        A[j] = A[j - increment];
        j = j - increment;
      }
      A[j] = temp;
    }

    if (increment == 2)
       increment = 1;
    else
       increment = (unsigned int) (increment / 2.2);
  }
}

//--------------------------------------------
// gnu quick sort
// (0ptional)
//--------------------------------------------

int compare_int (const int *a, const int *b)
{
  int  temp = *a - *b;

  if (temp > 0)          return  1;
  else if (temp < 0)     return -1;
  else                   return  0;
}

// gnu qsort:
// void qsort (void *a , size_a count, size_a size, compare_function)
// gnu qsort call for a[500] array of int:
// qsort (a , 500, sizeof(a), compare_int)



//--------------------------------------------
// benchmark test procedures
//--------------------------------------------


int test_Int_Add() {
   int i=1, j=11, k=112, l=1111, m=11111, n=-1, o=-11, p=-111, q=-1112, r=-11111;
   int x;
   volatile long s=0;
   for(x=0;x<10000;++x) {
     s+=i; s+=j; s+=k; s+=l; s+=m; s+=n; s+=o; s+=p; s+=q; s+=r;
   }
   return s;
}



long test_Int_Mult() {
  int x,y;
  volatile long s;

  for(y=0;y<2000;++y) {
    s=1;
    for(x=1;x<=13;++x) { s*=x;}
    for(x=13;x>0;--x) { s/=x;}

  }
  return s;
}


#define PI  M_PI


float test_float_math() {

  volatile float s=PI;
  int y;

  for(y=0;y<5000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s*=cos(10.5*s);
     s=sqrt(s);
     s=exp(s);
  }
  return s;
}


long test_rand_MT(){
  volatile unsigned long s;
  int y;

  for(y=0;y<5000;++y) {
     s=randM()%10001;
  }
  return s;
}


float test_matrix_math() {
  int x;

  float A[2][2], B[2][2], C[2][2];
  float O[3][3], T[3][3];
  unsigned long s;

  for(x=0;x<250;++x) {

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    B[0][0]=10;  B[0][1]=30;
    B[1][0]=20;  B[1][1]=40;

    MatrixMatrixMult(2,2,2, A,B,C);

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    MatrixDet(2, A);

    O[0][0]=1;   O[0][1]=4;  O[0][2]=7;
    O[1][0]=2;   O[1][1]=5;  O[1][2]=8;
    O[2][0]=3;   O[2][1]=6;  O[2][2]=9;

    MatrixDet(3, O);

  }

  s=(O[0][0]*O[1][1]*O[2][2]);
  return s;
}



// for array copy using void *memcpy(void *dest, const void *src, size_t n);

long test_Sort(){
  unsigned long s;
  int y, i;
  int t[500];

  for(y=0;y<30;++y) {
    memcpy(t, a, sizeof(a));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(b));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(c));
    shellsort(500, t);
  }

  return y;
}

inline void displayValues() {

  char buf[120];

    sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); Serial.println( buf);
    sprintf (buf, "%3d %4d  int_Mult",   1, runtime[1]); Serial.println( buf);
    sprintf (buf, "%3d %4d  float_op",   2, runtime[2]); Serial.println( buf);
    sprintf (buf, "%3d %4d  randomize",  3, runtime[3]); Serial.println( buf);
    sprintf (buf, "%3d %4d  matrx_algb", 4, runtime[4]); Serial.println( buf);
    sprintf (buf, "%3d %4d  arr_sort",   5, runtime[5]); Serial.println( buf);
    sprintf (buf, "%3d %4d  displ_txt",  6, runtime[6]); Serial.println( buf);
    sprintf (buf, "%3d %4d  graphics",   7, 99999); Serial.println( buf);
    sprintf (buf, "%3d %4d  graphics",   8, 99999); Serial.println( buf);
}


int test(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int   i;

  
  for(y=0;y<500;++y) {
    a[y]=randM()%30000; b[y]=randM()%30000; c[y]=randM()%30000;
  }


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); Serial.println( buf);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Mult",   0, runtime[1]); Serial.println( buf);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  float_op",   0, runtime[2]); Serial.println( buf);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  randomize",  0, runtime[3]); Serial.println( buf);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  matrx_algb", 0, runtime[4]); Serial.println( buf);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  arr_sort",   0, runtime[5]); Serial.println( buf);

  Serial.println();
 
  sprintf (buf, "gesamt ms: %d ", y);           Serial.println( buf);
  sprintf (buf, "benchmark: %d ", 50000000/y ); Serial.println( buf);

  return 1;

}



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
   char  buf[120];
  // put your main code here, to run repeatedly:
  //test();
  sprintf (buf, "Ende HaWe brickbench");           Serial.println( buf);
  while(1);
}

HaWe:
ArduBench0004:222: error: cannot convert 'float ()[2]' to 'float' for argument '4' to 'void MatrixMatrixMult(int, int, int, float*, float*, float*)'

MatrixMatrixMult(2, 2, 2, A[0], B[0], C[0]);

1000 Dank, jetzt hat's geschnackelt :slight_smile:

hier ist der berichtigte Code mit Ergebnis (Rechen- und Sort-Ergebnisse noch nicht kontrolliert: :sunglasses:

// hw brickbench
// benchmark test for NXT/EV3 and similar Micro Controllers
// PL: Sketch 1.5.6-r2 
// platform: Arduino Mega 2560
// Autor: (C) Helmut Wunder 2013, 2014
//
// freie Verwendung für private Zwecke
// für kommerzielle Zwecke nur nach Genehmigung durch den Autor.
// protected under the friendly Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// http: //creativecommons.org/licenses/by-nc-sa/3.0/ //

// version 1.08.0004


#define TimerMS() millis()

unsigned long runtime[8];

int a[500], b[500], c[500], t[500];

//--------------------------------------------
// Mersenne Twister
//--------------------------------------------

unsigned long randM(void) {
   
   const int M = 7;
   const unsigned long A[2] = { 0, 0x8ebfd028 };

   static unsigned long y[25];
   static int index = 25+1;

   if (index >= 25) {
     int k;
     if (index > 25) {
        unsigned long r = 9, s = 3402;
        for (k=0 ; k<25 ; ++k) {
          r = 509845221 * r + 3;
          s *= s + 1;
          y[k] = s + (r >> 10);
        }
     }
     for (k=0 ; k<25-M ; ++k)
        y[k] = y[k+M] ^ (y[k] >> 1) ^ A[y[k] & 1];
     for (; k<25 ; ++k)
        y[k] = y[k+(M-25)] ^ (y[k] >> 1) ^ A[y[k] & 1];
     index = 0;
   }

   unsigned long e = y[index++];
   e ^= (e << 7) & 0x2b5b2500;
   e ^= (e << 15) & 0xdb8b0000;
   e ^= (e >> 16);
   return e;
}

//--------------------------------------------
// Matrix Algebra
//--------------------------------------------

// matrix * matrix multiplication (matrix product)
 
 void MatrixMatrixMult(int N, int M, int K, float *A, float *B, float *C) {
   int i, j, s;
   for (i = 0; i < N; ++i) {
      for (j = 0; j < K; ++j) {
         C[i*K+j] = 0;
         for (s = 0; s < M; ++s) {
            C[i*K+j] = C[i*K+j] + A[i*N+s] * B[s*M+j];
         }
      }
   }
}


// matrix determinant

float MatrixDet(int N, float A[]) {
   int i, j, i_count, j_count, count = 0;
   float Asub[N - 1][N - 1], det = 0;

   if (N == 1)
      return *A;
   if (N == 2)
      return ((*A) * (*(A+1+1*N)) - (*(A+1*N)) * (*(A+1)));

   for (count = 0; count < N; count++) {
      i_count = 0;
      for (i = 1; i < N; i++) {
         j_count = 0;
         for (j = 0; j < N; j++) {
            if (j == count)
               continue;
            Asub[i_count][j_count] = *(A+i+j*N);
            j_count++;
         }
         i_count++;
      }
      det += pow(-1, count) * A[0+count*N] * MatrixDet(N - 1, &Asub[0][0]);
   }
   return det;
}



//--------------------------------------------
// shell sort
//--------------------------------------------

void shellsort(int size, int* A)
{
  int i, j, increment;
  int temp;
  increment = size / 2;

  while (increment > 0) {
    for (i = increment; i < size; i++) {
      j = i;
      temp = A[i];
      while ((j >= increment) && (A[j-increment] > temp)) {
        A[j] = A[j - increment];
        j = j - increment;
      }
      A[j] = temp;
    }

    if (increment == 2)
       increment = 1;
    else
       increment = (unsigned int) (increment / 2.2);
  }
}

//--------------------------------------------
// gnu quick sort
// (0ptional)
//--------------------------------------------

int compare_int (const int *a, const int *b)
{
  int  temp = *a - *b;

  if (temp > 0)          return  1;
  else if (temp < 0)     return -1;
  else                   return  0;
}

// gnu qsort:
// void qsort (void *a , size_a count, size_a size, compare_function)
// gnu qsort call for a[500] array of int:
// qsort (a , 500, sizeof(a), compare_int)



//--------------------------------------------
// benchmark test procedures
//--------------------------------------------


int test_Int_Add() {
   int i=1, j=11, k=112, l=1111, m=11111, n=-1, o=-11, p=-111, q=-1112, r=-11111;
   int x;
   volatile long s=0;
   for(x=0;x<10000;++x) {
     s+=i; s+=j; s+=k; s+=l; s+=m; s+=n; s+=o; s+=p; s+=q; s+=r;
   }
   return s;
}



long test_Int_Mult() {
  int x,y;
  volatile long s;

  for(y=0;y<2000;++y) {
    s=1;
    for(x=1;x<=13;++x) { s*=x;}
    for(x=13;x>0;--x) { s/=x;}

  }
  return s;
}


#define PI  M_PI


float test_float_math() {

  volatile float s=PI;
  int y;

  for(y=0;y<5000;++y) {
     s*=sqrt(s);
     s=sin(s);
     s*=cos(10.5*s);
     s=sqrt(s);
     s=exp(s);
  }
  return s;
}


long test_rand_MT(){
  volatile unsigned long s;
  int y;

  for(y=0;y<5000;++y) {
     s=randM()%10001;
  }
  return s;
}


float test_matrix_math() {
  int x;

  float A[2][2], B[2][2], C[2][2];
  float S[3][3], T[3][3];
  unsigned long s;

  for(x=0;x<250;++x) {

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;

    B[0][0]=10;  B[0][1]=30;
    B[1][0]=20;  B[1][1]=40;

    MatrixMatrixMult(2, 2, 2, A[0], B[0], C[0]); // <<<<<<<<<<<<<<<<<<<

    A[0][0]=1;   A[0][1]=3;
    A[1][0]=2;   A[1][1]=4;
    MatrixDet(2, A[0]);                          // <<<<<<<<<<<<<<<<<<<

    S[0][0]=1;   S[0][1]=4;  S[0][2]=7;
    S[1][0]=2;   S[1][1]=5;  S[1][2]=8;
    S[2][0]=3;   S[2][1]=6;  S[2][2]=9;

    MatrixDet(3, S[0]);                          // <<<<<<<<<<<<<<<<<<<

  }

  s=(S[0][0]*S[1][1]*S[2][2]);
  return s;
}



// for array copy using void *memcpy(void *dest, const void *src, size_t n);

long test_Sort(){
  unsigned long s;
  int y, i;
  int t[500];

  for(y=0;y<30;++y) {
    memcpy(t, a, sizeof(a));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(b));
    shellsort(500, t);
   
    memcpy(t, a, sizeof(c));
    shellsort(500, t);
  }

  return y;
}

inline void displayValues() {

  char buf[120];

    sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); Serial.println( buf);
    sprintf (buf, "%3d %4d  int_Mult",   1, runtime[1]); Serial.println( buf);
    sprintf (buf, "%3d %4d  float_op",   2, runtime[2]); Serial.println( buf);
    sprintf (buf, "%3d %4d  randomize",  3, runtime[3]); Serial.println( buf);
    sprintf (buf, "%3d %4d  matrx_algb", 4, runtime[4]); Serial.println( buf);
    sprintf (buf, "%3d %4d  arr_sort",   5, runtime[5]); Serial.println( buf);
    
   
}


int test(){

  unsigned long time0, x, y;
  float s;
  char  buf[120];
  int   i;

  
  for(y=0;y<500;++y) {
    a[y]=randM()%30000; b[y]=randM()%30000; c[y]=randM()%30000;
  }


  // LcdClearDisplay();

  time0= TimerMS();;
  s=test_Int_Add();
  runtime[0]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Add",    0, runtime[0]); Serial.println( buf);

  time0=TimerMS();
  s=test_Int_Mult();
  runtime[1]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  int_Mult",   1, runtime[1]); Serial.println( buf);

  time0=TimerMS();
  s=test_float_math();
  runtime[2]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  float_op",   2, runtime[2]); Serial.println( buf);

  time0=TimerMS();
  s=test_rand_MT();
  runtime[3]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  randomize",  3, runtime[3]); Serial.println( buf);

  time0=TimerMS();
  s=test_matrix_math();
  runtime[4]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  matrx_algb", 4, runtime[4]); Serial.println( buf);


  time0=TimerMS();
  s=test_Sort();
  runtime[5]=TimerMS()-time0;
  sprintf (buf, "%3d %4d  arr_sort",   5, runtime[5]); Serial.println( buf);
  
  // lcd display text / graphs  not performed!
  runtime[6]=0;
  runtime[7]=0;

  Serial.println();
  
  y = 0;
  for (x = 0; x < 8; ++x) {
      y += runtime[x];
  }
 
  sprintf (buf, "gesamt ms: %u ", y);           Serial.println( buf);
  sprintf (buf, "benchmark: %u ", 50000000/y ); Serial.println( buf);

  return 1;

}



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
   char  buf[120];
  // put your main code here, to run repeatedly:
  test();
  sprintf (buf, "Ende HaWe brickbench");           Serial.println( buf);
  while(1);
}
  0  130  int_Add
  1 1215  int_Mult
  2  889  float_op
  3  326  randomize
  4  240  matrx_algb
  5 1682  arr_sort

gesamt ms: 4482 
benchmark: 11155

herzlichen Dank nochmal für deine Hilfe !
:slight_smile:

jetzt nur noch eine OT Anschlussfrage für den Benchmark -

frei verfügbarer Flash ist 248k, RAM ist 8k....
wie groß aber ist der Speicher, den man für ausführbaren Programmcode beim 2560 zur Laufzeit zur Verfügung hat?
für Variablen = 8k
aber für Code...?

HaWe:
edit, nach copy-and-paste Fehler:
ich blicks nicht - ich bin offenbar zu sehr ans ANSI C99 gewöhnt (und verstehe jetzt die umdefinierten Funktionen nicht mehr):

Ich habe doch gesagt, dass es Mecker gibt wenn du den Cast beim Funktionsaufruf nicht machst!

Die Fehlermeldung ist eindeutig. Die Funktion erwartet ein Teil-Array, oder einen Zeiger. Da kannst du kein zwei-dimensionales Array übergeben

ist doch alles schon geklärt, ich bin mit den Sketch Konventionen nicht vertraut (benutze es ja erst seit wenigen Monaten!) und musste bisher Arrays nicht linearisieren.

Ich nutzte bisher u.a. ANSI C99 mit gpp C, da klappte alles (ohne plusplus).

Aber nochmal meine Anschlussfrage:
frei verfügbarer Flash ist 248k, RAM ist 8k....
wie groß ist jetzt der Speicher, den man für ausführbaren Programmcode beim 2560 zur Laufzeit zur Verfügung hat?
für Variablen = 8k
aber für Code...?

sind das die 248k?