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

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.
Posts: 1
Joined: Fri Apr 21, 2006 1:38 pm

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

Please refer to ... index.html to get help about the Veclib library.

Especially ... aries.html that explains you how to call lapack from C.

Here is what they say about programming in C++ with AltiVEc: (see ... 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]);

   /* workspace query, workspace needed for dsyev in lwork */
   work = (double *)calloc(1,sizeof(double)) ;

   /*set workspace according to workspace query, dsyev call, free workspace*/
   work = (double *)calloc(lwork,sizeof(double)) ;

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

   return info;

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

Here are the results:
Code: Select all
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...
Last edited by Julie on Tue May 30, 2006 3:59 pm, edited 1 time in total.
Posts: 299
Joined: Wed Feb 23, 2005 12:32 am
Location: ICL, Denver. Colorado

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


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

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
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

do you have any idea how to solve this?
Btw, im using the compiled library in of

your help will be highly appreciated

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 19 guests