## Developer Reference

• 2022.1
• 12/20/2021
• Public Content
Contents

# SSYEVD Example Program in C

``````/*******************************************************************************
*  The information and material ("Material") provided below is owned by Intel
*  Corporation or its suppliers or licensors, and title to such Material remains
*  with Intel Corporation or its suppliers or licensors. The Material contains
*  proprietary information of Intel or its suppliers and licensors. The Material
*  is protected by worldwide copyright laws and treaty provisions. No part of
*  the Material may be copied, reproduced, published, uploaded, posted,
*  transmitted, or distributed in any way without Intel's prior express written
*  property rights in the Material is granted to or conferred upon you, either
*  expressly, by implication, inducement, estoppel or otherwise. Any license
*  under such intellectual property rights must be express and approved by Intel
*  in writing.
*
********************************************************************************
*/
/*
SSYEVD Example.
==============

Program computes all eigenvalues and eigenvectors of a real symmetric
matrix A using divide and conquer algorithm, where A is:

6.39   0.13  -8.23   5.71  -3.18
0.13   8.37  -4.46  -6.10   7.21
-8.23  -4.46  -9.58  -9.25  -7.42
5.71  -6.10  -9.25   3.72   8.54
-3.18   7.21  -7.42   8.54   2.51

Description.
============

The routine computes all eigenvalues and, optionally, eigenvectors of an
n-by-n real symmetric matrix A. The eigenvector v(j) of A satisfies

A*v(j) = lambda(j)*v(j)

where lambda(j) is its eigenvalue. The computed eigenvectors are
orthonormal.
If the eigenvectors are requested, then this routine uses a divide and
conquer algorithm to compute eigenvalues and eigenvectors.

Example Program Results.
========================

SSYEVD Example Program Results

Eigenvalues
-17.44 -11.96   6.72  14.25  19.84

Eigenvectors (stored columnwise)
-0.26   0.31  -0.74   0.33   0.42
-0.17  -0.39  -0.38  -0.80   0.16
-0.89   0.04   0.09   0.03  -0.45
-0.29  -0.59   0.34   0.31   0.60
-0.19   0.63   0.44  -0.38   0.48
*/
#include <stdlib.h>
#include <stdio.h>

/* SSYEVD prototype */
extern void ssyevd( char* jobz, char* uplo, int* n, float* a, int* lda,
float* w, float* work, int* lwork, int* iwork, int* liwork, int* info );
/* Auxiliary routines prototypes */
extern void print_matrix( char* desc, int m, int n, float* a, int lda );

/* Parameters */
#define N 5
#define LDA N

/* Main program */
int main() {
/* Locals */
int n = N, lda = LDA, info, lwork, liwork;
int iwkopt;
int* iwork;
float wkopt;
float* work;
/* Local arrays */
float w[N];
float a[LDA*N] = {
6.39f,  0.00f,  0.00f,  0.00f,  0.00f,
0.13f,  8.37f,  0.00f,  0.00f,  0.00f,
-8.23f, -4.46f, -9.58f,  0.00f,  0.00f,
5.71f, -6.10f, -9.25f,  3.72f,  0.00f,
-3.18f,  7.21f, -7.42f,  8.54f,  2.51f
};
/* Executable statements */
printf( " SSYEVD Example Program Results\n" );
/* Query and allocate the optimal workspace */
lwork = -1;
liwork = -1;
ssyevd( "Vectors", "Upper", &n, a, &lda, w, &wkopt, &lwork, &iwkopt,
&liwork, &info );
lwork = (int)wkopt;
work = (float*)malloc( lwork*sizeof(float) );
liwork = iwkopt;
iwork = (int*)malloc( liwork*sizeof(int) );
/* Solve eigenproblem */
ssyevd( "Vectors", "Upper", &n, a, &lda, w, work, &lwork, iwork,
&liwork, &info );
/* Check for convergence */
if( info > 0 ) {
printf( "The algorithm failed to compute eigenvalues.\n" );
exit( 1 );
}
/* Print eigenvalues */
print_matrix( "Eigenvalues", 1, n, w, 1 );
/* Print eigenvectors */
print_matrix( "Eigenvectors (stored columnwise)", n, n, a, lda );
/* Free workspace */
free( (void*)iwork );
free( (void*)work );
exit( 0 );
} /* End of SSYEVD Example */

/* Auxiliary routine: printing a matrix */
void print_matrix( char* desc, int m, int n, float* a, int lda ) {
int i, j;
printf( "\n %s\n", desc );
for( i = 0; i < m; i++ ) {
for( j = 0; j < n; j++ ) printf( " %6.2f", a[i+j*lda] );
printf( "\n" );
}
}``````

#### Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.