using lapack on a mac in C++ (beginner questions)

Open discussion regarding features, bugs, issues, vendors, etc.

using lapack on a mac in C++ (beginner questions)

Postby vgoklani » Fri Apr 21, 2006 1:46 pm

Hi,
I need the eigenvalues of a large matrix, and I would like to use lapack to find them. I will be doing this in C++ on a mac (intel based macbook pro, running under 10.4.6) using g++, and I am unsure of how to actually link the vec.lib. Where is the library located? Can someone also point me to some good tutorials for using lapack on a mac. I am a beginner, so any advice (no matter how trivial) would be helpful. What would the syntax be for compiling a file.
vgoklani
 
Posts: 1
Joined: Fri Apr 21, 2006 1:38 pm

Postby Julie » Tue May 02, 2006 10:59 am

Please refer to http://developer.apple.com/hardwaredriv ... index.html to get help about the Veclib library.

Especially http://developer.apple.com/hardwaredriv ... aries.html that explains you how to call lapack from C.

Here is what they say about programming in C++ with AltiVEc: (see http://developer.apple.com/hardwaredriv ... tails.html)
You can program in C++ and Objective C using the AltiVec C programming interface, in the same way that you can use ordinary C functions and data types in C++ and Objective C.

With C++, some attention must be paid to performance when building abstraction. Wrapping a vector data type in a C++ object can have substantial negative performance implications if your compiler does not support passing class data by value in register. Passing small amounts of data by address causes a large amount of unnecessary load/store overhead. Typical slowdowns may be a factor of two. Be sure to check your compiler's output. Newer versions of popular C++ compilers for MacOS X support this feature.


Here is a sample C code to get eigenvalues from a symetric matrix:
Code: Select all
#include <stdio.h>
#include <stdlib.h>

#define f77_dsyev dsyev_

extern int f77_dsyev( char *jobz, char *uplo, int *n, double *a, int *lda,
   double *w, double *work, int *lwork, int *info );

int main(){
   int n=3;
   int info;
   double  A[9] = {1,2,3,2,4,5,3,5,6};
   double  w[3];
   int lwork;
   double *work;
   int i,j;
   printf("A= \n");
   for (i=0;i<n;i++)
   {for (j=0;j<n;j++)
   printf("%f \t ",A[i*n+j]);
   printf("\n");
   }

   /* workspace query, workspace needed for dsyev in lwork */
   lwork=-1;
   work = (double *)calloc(1,sizeof(double)) ;
   f77_dsyev("V","U",&n,A,&n,w,work,&lwork,&info);
   lwork=work[0];
   free(work);

   /*set workspace according to workspace query, dsyev call, free workspace*/
   work = (double *)calloc(lwork,sizeof(double)) ;
   f77_dsyev("V","U",&n,A,&n,w,work,&lwork,&info);
   free(work);

   if (info != 0)
      printf("error!\n");
   else {
      printf("eigen values:\n");
      for (i=0;i<n;i++)
         printf("%f \t",w[i]);
      printf("\n");
   }

   return info;
}

To compile it with vecLib , use:
cc -O3 code.c -framework vecLib


Here are the results:
Code: Select all
A=
1.000000         2.000000        3.000000       
2.000000         4.000000        5.000000       
3.000000         5.000000        6.000000       
eigen values:
-0.515729       0.170915        11.344814


Hope it helps...
Julie
Last edited by Julie on Tue May 30, 2006 3:59 pm, edited 1 time in total.
Julie
 
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

Postby rafael » Thu Jun 01, 2006 1:48 pm

Hello

I tried to use your sample code and it compiled under Visual C++ 6 but by some reason, instead of giving me as result

A=
1.000000 2.000000 3.000000
2.000000 4.000000 5.000000
3.000000 5.000000 6.000000
eigen values:
-0.515729 0.170915 11.344814

i get
A=
1.000000 2.000000 3.000000
2.000000 4.000000 5.000000
3.000000 5.000000 6.000000
** On entry to DSYEV , parameter number 8 had an illegal value
** On entry to DSYEV , parameter number 8 had an illegal value
error!

do you have any idea how to solve this?
Btw, im using the compiled library in CLAw32.zip of http://www.netlib.org/clapack/index.html

your help will be highly appreciated

Rafael
rafael
 
Posts: 2
Joined: Thu Jun 01, 2006 1:11 pm


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 6 guests

cron