|
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 GETRF
|
|
kusano |
2b45e8 |
#undef GETRS
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef COMPLEX
|
|
kusano |
2b45e8 |
#ifdef XDOUBLE
|
|
kusano |
2b45e8 |
#define GETRF BLASFUNC(qgetrf)
|
|
kusano |
2b45e8 |
#define GETRS BLASFUNC(qgetrs)
|
|
kusano |
2b45e8 |
#elif defined(DOUBLE)
|
|
kusano |
2b45e8 |
#define GETRF BLASFUNC(dgetrf)
|
|
kusano |
2b45e8 |
#define GETRS BLASFUNC(dgetrs)
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define GETRF BLASFUNC(sgetrf)
|
|
kusano |
2b45e8 |
#define GETRS BLASFUNC(sgetrs)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#ifdef XDOUBLE
|
|
kusano |
2b45e8 |
#define GETRF BLASFUNC(xgetrf)
|
|
kusano |
2b45e8 |
#define GETRS BLASFUNC(xgetrs)
|
|
kusano |
2b45e8 |
#elif defined(DOUBLE)
|
|
kusano |
2b45e8 |
#define GETRF BLASFUNC(zgetrf)
|
|
kusano |
2b45e8 |
#define GETRS BLASFUNC(zgetrs)
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
#define GETRF BLASFUNC(cgetrf)
|
|
kusano |
2b45e8 |
#define GETRS BLASFUNC(cgetrs)
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(__WIN32__) || defined(__WIN64__)
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef DELTA_EPOCH_IN_MICROSECS
|
|
kusano |
2b45e8 |
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
|
kusano |
2b45e8 |
#endif
|
|
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 |
#if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
static void *huge_malloc(BLASLONG size){
|
|
kusano |
2b45e8 |
int shmid;
|
|
kusano |
2b45e8 |
void *address;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifndef SHM_HUGETLB
|
|
kusano |
2b45e8 |
#define SHM_HUGETLB 04000
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if ((shmid =shmget(IPC_PRIVATE,
|
|
kusano |
2b45e8 |
(size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
|
|
kusano |
2b45e8 |
SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
|
|
kusano |
2b45e8 |
printf( "Memory allocation failed(shmget).\n");
|
|
kusano |
2b45e8 |
exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
address = shmat(shmid, NULL, SHM_RND);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if ((BLASLONG)address == -1){
|
|
kusano |
2b45e8 |
printf( "Memory allocation failed(shmat).\n");
|
|
kusano |
2b45e8 |
exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
shmctl(shmid, IPC_RMID, 0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
return address;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#define malloc huge_malloc
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
int MAIN__(int argc, char *argv[]){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT *a, *b;
|
|
kusano |
2b45e8 |
blasint *ipiv;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
blasint m, i, j, info;
|
|
kusano |
2b45e8 |
blasint unit = 1;
|
|
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, time2;
|
|
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 * COMPSIZE)) == NULL){
|
|
kusano |
2b45e8 |
fprintf(stderr,"Out of Memory!!\n");exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (( ipiv = (blasint *)malloc(sizeof(blasint) * to * COMPSIZE)) == NULL){
|
|
kusano |
2b45e8 |
fprintf(stderr,"Out of Memory!!\n");exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifdef linux
|
|
kusano |
2b45e8 |
srandom(getpid());
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
fprintf(stderr, " SIZE Residual Decompose Solve Total\n");
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for(m = from; m <= to; m += step){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
fprintf(stderr, " %6d : ", (int)m);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for(j = 0; j < m; j++){
|
|
kusano |
2b45e8 |
for(i = 0; i < m * COMPSIZE; i++){
|
|
kusano |
2b45e8 |
a[i + j * m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (i = 0; i < m * COMPSIZE; ++i) b[i] = 0.;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
for (j = 0; j < m; ++j) {
|
|
kusano |
2b45e8 |
for (i = 0; i < m * COMPSIZE; ++i) {
|
|
kusano |
2b45e8 |
b[i] += a[i + j * m * COMPSIZE];
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
gettimeofday( &start, (struct timezone *)0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
GETRF (&m, &m, a, &m, ipiv, &info);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
gettimeofday( &stop, (struct timezone *)0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (info) {
|
|
kusano |
2b45e8 |
fprintf(stderr, "Matrix is not singular .. %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 |
gettimeofday( &start, (struct timezone *)0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
GETRS("N", &m, &unit, a, &m, ipiv, b, &m, &info);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
gettimeofday( &stop, (struct timezone *)0);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (info) {
|
|
kusano |
2b45e8 |
fprintf(stderr, "Matrix is not singular .. %d\n", info);
|
|
kusano |
2b45e8 |
exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
time2 = (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 |
for(i = 0; i < m; i++){
|
|
kusano |
2b45e8 |
#ifndef XDOUBLE
|
|
kusano |
2b45e8 |
if (maxerr < fabs(b[i * COMPSIZE] - 1.0)) maxerr = fabs(b[i * COMPSIZE] - 1.0);
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
if (maxerr < fabs(b[i * COMPSIZE] + 1)) maxerr = fabs(b[i * COMPSIZE + 1]);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
if (maxerr < fabsl(b[i * COMPSIZE] - 1.0L)) maxerr = fabsl(b[i * COMPSIZE] - 1.0L);
|
|
kusano |
2b45e8 |
#ifdef COMPLEX
|
|
kusano |
2b45e8 |
if (maxerr < fabsl(b[i * COMPSIZE] + 1)) maxerr = fabsl(b[i * COMPSIZE + 1]);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#ifdef XDOUBLE
|
|
kusano |
2b45e8 |
fprintf(stderr," %Le ", maxerr);
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
fprintf(stderr," %e ", maxerr);
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
fprintf(stderr,
|
|
kusano |
2b45e8 |
" %10.2f MFlops %10.2f MFlops %10.2f MFlops\n",
|
|
kusano |
2b45e8 |
COMPSIZE * COMPSIZE * 2. / 3. * (double)m * (double)m * (double)m / time1 * 1.e-6,
|
|
kusano |
2b45e8 |
COMPSIZE * COMPSIZE * 2. * (double)m * (double)m / time2 * 1.e-6,
|
|
kusano |
2b45e8 |
COMPSIZE * COMPSIZE * (2. / 3. * (double)m * (double)m * (double)m + 2. * (double)m * (double)m) / (time1 + time2) * 1.e-6);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if 0
|
|
kusano |
2b45e8 |
if (
|
|
kusano |
2b45e8 |
#ifdef DOUBLE
|
|
kusano |
2b45e8 |
maxerr > 1.e-8
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
maxerr > 1.e-1
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
) {
|
|
kusano |
2b45e8 |
fprintf(stderr, "Error is too large.\n");
|
|
kusano |
2b45e8 |
exit(1);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
#endif
|
|
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__")));
|