|
kusano |
2b45e8 |
/*********************************************************************/
|
|
kusano |
2b45e8 |
/* Copyright 2009, 2010 The University of Texas at Austin. */
|
|
kusano |
2b45e8 |
/* All rights reserved. */
|
|
kusano |
2b45e8 |
/* */
|
|
kusano |
2b45e8 |
/* Redistribution and use in source and binary forms, with or */
|
|
kusano |
2b45e8 |
/* without modification, are permitted provided that the following */
|
|
kusano |
2b45e8 |
/* conditions are met: */
|
|
kusano |
2b45e8 |
/* */
|
|
kusano |
2b45e8 |
/* 1. Redistributions of source code must retain the above */
|
|
kusano |
2b45e8 |
/* copyright notice, this list of conditions and the following */
|
|
kusano |
2b45e8 |
/* disclaimer. */
|
|
kusano |
2b45e8 |
/* */
|
|
kusano |
2b45e8 |
/* 2. Redistributions in binary form must reproduce the above */
|
|
kusano |
2b45e8 |
/* copyright notice, this list of conditions and the following */
|
|
kusano |
2b45e8 |
/* disclaimer in the documentation and/or other materials */
|
|
kusano |
2b45e8 |
/* provided with the distribution. */
|
|
kusano |
2b45e8 |
/* */
|
|
kusano |
2b45e8 |
/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
|
|
kusano |
2b45e8 |
/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
|
|
kusano |
2b45e8 |
/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
|
|
kusano |
2b45e8 |
/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
|
|
kusano |
2b45e8 |
/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
|
|
kusano |
2b45e8 |
/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
|
|
kusano |
2b45e8 |
/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
|
|
kusano |
2b45e8 |
/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
|
|
kusano |
2b45e8 |
/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
|
|
kusano |
2b45e8 |
/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
|
|
kusano |
2b45e8 |
/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
|
|
kusano |
2b45e8 |
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
|
|
kusano |
2b45e8 |
/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
|
|
kusano |
2b45e8 |
/* POSSIBILITY OF SUCH DAMAGE. */
|
|
kusano |
2b45e8 |
/* */
|
|
kusano |
2b45e8 |
/* The views and conclusions contained in the software and */
|
|
kusano |
2b45e8 |
/* documentation are those of the authors and should not be */
|
|
kusano |
2b45e8 |
/* interpreted as representing official policies, either expressed */
|
|
kusano |
2b45e8 |
/* or implied, of The University of Texas at Austin. */
|
|
kusano |
2b45e8 |
/*********************************************************************/
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#include <stdio.h></stdio.h>
|
|
kusano |
2b45e8 |
#include <stdlib.h></stdlib.h>
|
|
kusano |
2b45e8 |
#ifdef __CYGWIN32__
|
|
kusano |
2b45e8 |
#include <sys time.h=""></sys>
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#include "common.h"
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
double fabs(double);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#undef POTRF
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef COMPLEX
|
|
kusano |
2b45e8 |
#ifdef XDOUBLE
|
|
kusano |
2b45e8 |
#define POTRF BLASFUNC(qpotrf)
|
|
kusano |
2b45e8 |
#define SYRK BLASFUNC(qsyrk)
|
|
kusano |
2b45e8 |
#elif defined(DOUBLE)
|
|
kusano |
2b45e8 |
#define POTRF BLASFUNC(dpotrf)
|
|
kusano |
2b45e8 |
#define SYRK BLASFUNC(dsyrk)
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define POTRF BLASFUNC(spotrf)
|
|
kusano |
2b45e8 |
#define SYRK BLASFUNC(ssyrk)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#ifdef XDOUBLE
|
|
kusano |
2b45e8 |
#define POTRF BLASFUNC(xpotrf)
|
|
kusano |
2b45e8 |
#define SYRK BLASFUNC(xherk)
|
|
kusano |
2b45e8 |
#elif defined(DOUBLE)
|
|
kusano |
2b45e8 |
#define POTRF BLASFUNC(zpotrf)
|
|
kusano |
2b45e8 |
#define SYRK BLASFUNC(zherk)
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define POTRF BLASFUNC(cpotrf)
|
|
kusano |
2b45e8 |
#define SYRK BLASFUNC(cherk)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(__WIN32__) || defined(__WIN64__)
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int gettimeofday(struct timeval *tv, void *tz){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FILETIME ft;
|
|
kusano |
2b45e8 |
unsigned __int64 tmpres = 0;
|
|
kusano |
2b45e8 |
static int tzflag;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (NULL != tv)
|
|
kusano |
2b45e8 |
{
|
|
kusano |
2b45e8 |
GetSystemTimeAsFileTime(&ft);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
tmpres |= ft.dwHighDateTime;
|
|
kusano |
2b45e8 |
tmpres <<= 32;
|
|
kusano |
2b45e8 |
tmpres |= ft.dwLowDateTime;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
/*converting file time to unix epoch*/
|
|
kusano |
2b45e8 |
tmpres /= 10; /*convert into microseconds*/
|
|
kusano |
2b45e8 |
tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
|
kusano |
2b45e8 |
tv->tv_sec = (long)(tmpres / 1000000UL);
|
|
kusano |
2b45e8 |
tv->tv_usec = (long)(tmpres % 1000000UL);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
return 0;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static __inline double getmflops(int ratio, int m, double secs){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
double mm = (double)m;
|
|
kusano |
2b45e8 |
double mulflops, addflops;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (secs==0.) return 0.;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
mulflops = mm * (1./3. + mm * (1./2. + mm * 1./6.));
|
|
kusano |
2b45e8 |
addflops = 1./6. * mm * (mm * mm - 1);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (ratio == 1) {
|
|
kusano |
2b45e8 |
return (mulflops + addflops) / secs * 1.e-6;
|
|
kusano |
2b45e8 |
} else {
|
|
kusano |
2b45e8 |
return (2. * mulflops + 6. * addflops) / secs * 1.e-6;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int MAIN__(int argc, char *argv[]){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
char *trans[] = {"T", "N"};
|
|
kusano |
2b45e8 |
char *uplo[] = {"U", "L"};
|
|
kusano |
2b45e8 |
FLOAT alpha[] = {1.0, 0.0};
|
|
kusano |
2b45e8 |
FLOAT beta [] = {0.0, 0.0};
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT *a, *b;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
blasint m, i, j, info, uplos;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int from = 1;
|
|
kusano |
2b45e8 |
int to = 200;
|
|
kusano |
2b45e8 |
int step = 1;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT maxerr;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
struct timeval start, stop;
|
|
kusano |
2b45e8 |
double time1;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
argc--;argv++;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (argc > 0) { from = atol(*argv); argc--; argv++;}
|
|
kusano |
2b45e8 |
if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
|
|
kusano |
2b45e8 |
if (argc > 0) { step = atol(*argv); argc--; argv++;}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
|
|
kusano |
2b45e8 |
fprintf(stderr,"Out of Memory!!\n");exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
|
|
kusano |
2b45e8 |
fprintf(stderr,"Out of Memory!!\n");exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for(m = from; m <= to; m += step){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
fprintf(stderr, "M = %6d : ", (int)m);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (uplos = 0; uplos < 2; uplos ++) {
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef COMPLEX
|
|
kusano |
2b45e8 |
if (uplos & 1) {
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j++) {
|
|
kusano |
2b45e8 |
for(i = 0; i < j; i++) a[i + j * m] = 0.;
|
|
kusano |
2b45e8 |
a[j + j * m] = ((double) rand() / (double) RAND_MAX) + 8.;
|
|
kusano |
2b45e8 |
for(i = j + 1; i < m; i++) a[i + j * m] = ((double) rand() / (double) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
} else {
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j++) {
|
|
kusano |
2b45e8 |
for(i = 0; i < j; i++) a[i + j * m] = ((double) rand() / (double) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
a[j + j * m] = ((double) rand() / (double) RAND_MAX) + 8.;
|
|
kusano |
2b45e8 |
for(i = j + 1; i < m; i++) a[i + j * m] = 0.;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
if (uplos & 1) {
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j++) {
|
|
kusano |
2b45e8 |
for(i = 0; i < j; i++) {
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 0] = 0.;
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 1] = 0.;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
a[(j + j * m) * 2 + 0] = ((double) rand() / (double) RAND_MAX) + 8.;
|
|
kusano |
2b45e8 |
a[(j + j * m) * 2 + 1] = 0.;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for(i = j + 1; i < m; i++) {
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 0] = ((double) rand() / (double) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 1] = ((double) rand() / (double) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
} else {
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j++) {
|
|
kusano |
2b45e8 |
for(i = 0; i < j; i++) {
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 0] = ((double) rand() / (double) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 1] = ((double) rand() / (double) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
a[(j + j * m) * 2 + 0] = ((double) rand() / (double) RAND_MAX) + 8.;
|
|
kusano |
2b45e8 |
a[(j + j * m) * 2 + 1] = 0.;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for(i = j + 1; i < m; i++) {
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 0] = 0.;
|
|
kusano |
2b45e8 |
a[(i + j * m) * 2 + 1] = 0.;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
SYRK(uplo[uplos], trans[uplos], &m, &m, alpha, a, &m, beta, b, &m);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
gettimeofday( &start, (struct timezone *)0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
POTRF(uplo[uplos], &m, b, &m, &info);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
gettimeofday( &stop, (struct timezone *)0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (info != 0) {
|
|
kusano |
2b45e8 |
fprintf(stderr, "Info = %d\n", info);
|
|
kusano |
2b45e8 |
exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
maxerr = 0.;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (!(uplos & 1)) {
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j++) {
|
|
kusano |
2b45e8 |
for(i = 0; i <= j; i++) {
|
|
kusano |
2b45e8 |
#ifndef COMPLEX
|
|
kusano |
2b45e8 |
if (maxerr < fabs(a[i + j * m] - b[i + j * m])) maxerr = fabs(a[i + j * m] - b[i + j * m]);
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
if (maxerr < fabs(a[(i + j * m) * 2 + 0] - b[(i + j * m) * 2 + 0])) maxerr = fabs(a[(i + j * m) * 2 + 0] - b[(i + j * m) * 2 + 0]);
|
|
kusano |
2b45e8 |
if (maxerr < fabs(a[(i + j * m) * 2 + 1] - b[(i + j * m) * 2 + 1])) maxerr = fabs(a[(i + j * m) * 2 + 1] - b[(i + j * m) * 2 + 1]);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
} else {
|
|
kusano |
2b45e8 |
for (j = 0; j < m; j++) {
|
|
kusano |
2b45e8 |
for(i = j; i < m; i++) {
|
|
kusano |
2b45e8 |
#ifndef COMPLEX
|
|
kusano |
2b45e8 |
if (maxerr < fabs(a[i + j * m] - b[i + j * m])) maxerr = fabs(a[i + j * m] - b[i + j * m]);
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
if (maxerr < fabs(a[(i + j * m) * 2 + 0] - b[(i + j * m) * 2 + 0])) maxerr = fabs(a[(i + j * m) * 2 + 0] - b[(i + j * m) * 2 + 0]);
|
|
kusano |
2b45e8 |
if (maxerr < fabs(a[(i + j * m) * 2 + 1] - b[(i + j * m) * 2 + 1])) maxerr = fabs(a[(i + j * m) * 2 + 1] - b[(i + j * m) * 2 + 1]);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
fprintf(stderr,
|
|
kusano |
2b45e8 |
#ifdef XDOUBLE
|
|
kusano |
2b45e8 |
" %Le %10.3f MFlops", maxerr,
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
" %e %10.3f MFlops", maxerr,
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
getmflops(COMPSIZE * COMPSIZE, m, time1));
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (maxerr > 1.e-3) {
|
|
kusano |
2b45e8 |
fprintf(stderr, "Hmm, probably it has bug.\n");
|
|
kusano |
2b45e8 |
exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
fprintf(stderr, "\n");
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
return 0;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));
|