chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Strange observation: Chicken, C, C++: Joe Average does b


From: Siegfried Gonzi
Subject: [Chicken-users] Strange observation: Chicken, C, C++: Joe Average does benchmarking
Date: Tue, 18 Dec 2007 21:50:35 +0100

hello: He wait before you now start out flaming me please note: I am not in 
numerical analysis in any way but I wrote my phd in physics more or less with 
the help of Bigloo and some radiative tranfer codes (my simulations took many 
days on our work stations). And now I am post doc and we run big models for 
many days on clusters. So I am well aware what 'calculation in the big means'.

But I cannot believe the following matrix-marix multiplication: Hey, I found 
the following C++ code on the net (see enclosed) and compared it to chicken 64 
on mac osx leopard: Intel dual core, 2MHz, Mac Book and 1GB of RAM:

FOR: 2048 matrix (codes see end of posting):

Chicken: csc matrix.scm -benchmark-mode
==
5864062714880 23447698673664 32239498824704 41031347213312

1st run:
real    2m44.894s
user    2m38.841s
sys     0m0.658s

2nd run:
5864062714880 23447698673664 32239498824704 41031347213312

real    2m39.186s
user    2m38.359s
sys     0m0.737s
==

 C++:  g++ -O6 -ffast-math -funroll-loops  tes.cpp
==
5.86406e+12 2.34477e+13 3.22395e+13 4.10313e+13

real    3m47.428s
user    3m45.644s
sys     0m1.234s
==

C:  gcc -O6 -ffast-math -funroll-loops  tes.c
==
5.86406e+12 2.34477e+13 3.22395e+13 4.10313e+13

real    3m14.884s
user    3m14.005s
sys     0m0.688s
==

I cannot believe this. Any clues and flame baits. Could it be that chicken is 
specifically compiled for osx? What are the 'better' compiler options for gcc?


regards, Siegfried
==
#include <iostream>
#include <vector>

using namespace std;

vector<vector<double> > mkmatrix(int rows, int cols)
{
    double counter=double(0.0);
    vector<vector<double> > m;


    for(int i=0; i<rows; i++)
    {
        vector<double> row_vec;
        for(int j=0; j<cols; j++)
        {
            counter = counter + 1.0;
            row_vec.push_back(counter);
        }
        m.push_back(row_vec);
    }
        return(m);
}




vector<vector<double> > mmult(int rows, int cols,
                                vector<vector<double> > m1,
                                vector<vector<double> > m2,
                                vector<vector<double> > m3)
{
    double val;
    for(int i=0; i<rows; i++)
    {
        for(int j=0; j<rows; j++)
        {
            val = double(0.0);
            for(int k=0; k<cols; k++)
            {
                val += m1[i][k] * m2[k][j];
            }
            m3[i][j] = val;
        }
    }
    return(m3);
}


int main()
{
    int SIZE=2048;

    vector<vector<double> > m1 = mkmatrix(SIZE,SIZE);
    vector<vector<double> > m2 = mkmatrix(SIZE,SIZE);
    vector<vector<double> > mm = mkmatrix(SIZE,SIZE);

    mm = mmult(SIZE,SIZE,m1,m2,mm);

    cout << mm[0][0] << " " << mm[2][3] << " " << mm[3][2] << " " <<
mm[4][4] << endl;

    return(0);
}
==

==
#include <iostream>
#include <stdlib.h>

using namespace std;

double **mkmatrix(int rows, int cols) {
    int i, j, count = 1;
    double **m = (double **) malloc(rows * sizeof(double *));
    for (i=0; i<rows; i++) {
        m[i] = (double *) malloc(cols * sizeof(double));
        for (j=0; j<cols; j++) {
            m[i][j] = count++;
        }
    }
    return(m);
}

void zeromatrix(int rows, int cols, double **m) {
    int i, j;
    for (i=0; i<rows; i++)
        for (j=0; j<cols; j++)
            m[i][j] = 0;
}

void freematrix(int rows, double **m) {
    while (--rows > -1) { free(m[rows]); }
    free(m);
}

double **mmult(int rows, int cols, double **m1, double **m2, double **m3) {
    int i, j, k;
    double val;
    for (i=0; i<rows; i++) {
        for (j=0; j<cols; j++) {
            val = double(0.0);
            for (k=0; k<cols; k++) {
                val += m1[i][k] * m2[k][j];
            }
            m3[i][j] = val;
        }
    }
    return(m3);
}

int main()
{
    int i, SIZE=2048;

    double **m1 = mkmatrix(SIZE, SIZE);
    double **m2 = mkmatrix(SIZE, SIZE);
    double **mm = mkmatrix(SIZE, SIZE);

    mm = mmult(SIZE, SIZE, m1, m2, mm);

    cout << mm[0][0] << " " << mm[2][3] << " " << mm[3][2] << " " <<
mm[4][4] << endl;

    freematrix(SIZE, m1);
    freematrix(SIZE, m2);
    freematrix(SIZE, mm);
    return(0);
}
==

Chicken:

==
(define (mkmatrix rows cols)
  (let ((mx (make-vector rows 0.0))
        (count 1.0))
    (do ((i 0 (+ i 1)))
        ((= i rows))
      (let ((row (make-vector cols 0.0)))
        (do ((j 0 (+ j 1)))
            ((= j cols))
          (vector-set! row j count)
          (set! count (+ count 1.0)))
        (vector-set! mx i row)))
    mx))


(define (num-cols mx)
  (let ((row (vector-ref mx 0)))
    (vector-length row)))


(define (num-rows mx)
  (vector-length mx))


(define (mmult rows cols m1 m2)
  (let ((m3 (make-vector rows 0.0)))
    (do ((i 0 (+ 1 i)))
        ((= i rows))
      (let ((m1i (vector-ref m1 i))
            (row (make-vector cols 0.0)))
        (do ((j 0 (+ 1 j)))
            ((= j cols))
          (let ((val 0.0))
            (do ((k 0 (+ 1 k)))
                ((= k cols))
              (set! val (+ val (* (vector-ref m1i k)
                                  (vector-ref (vector-ref m2 k) j)))))
            (vector-set! row j val)))
        (vector-set! m3 i row)))
    m3))


(define (do-main size)
  (let ((mm 0.0)
        (m1 (mkmatrix size size))
        (m2 (mkmatrix size size)))
    (set! mm (mmult size size m1 m2))
    (let ((r0 (vector-ref mm 0))
          (r2 (vector-ref mm 2))
          (r3 (vector-ref mm 3))
          (r4 (vector-ref mm 4)))
      (print (vector-ref r0 0) " " (vector-ref r2 3) " "
             (vector-ref r3 2) " " (vector-ref r4 4)))))

(do-main 2048)
==


-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger?did=10




reply via email to

[Prev in Thread] Current Thread [Next in Thread]