|
| 1 | +/*********************************************************************/ |
| 2 | +/* Copyright 2009, 2010 The University of Texas at Austin. */ |
| 3 | +/* All rights reserved. */ |
| 4 | +/* */ |
| 5 | +/* Redistribution and use in source and binary forms, with or */ |
| 6 | +/* without modification, are permitted provided that the following */ |
| 7 | +/* conditions are met: */ |
| 8 | +/* */ |
| 9 | +/* 1. Redistributions of source code must retain the above */ |
| 10 | +/* copyright notice, this list of conditions and the following */ |
| 11 | +/* disclaimer. */ |
| 12 | +/* */ |
| 13 | +/* 2. Redistributions in binary form must reproduce the above */ |
| 14 | +/* copyright notice, this list of conditions and the following */ |
| 15 | +/* disclaimer in the documentation and/or other materials */ |
| 16 | +/* provided with the distribution. */ |
| 17 | +/* */ |
| 18 | +/* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */ |
| 19 | +/* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */ |
| 20 | +/* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ |
| 21 | +/* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ |
| 22 | +/* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */ |
| 23 | +/* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */ |
| 24 | +/* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ |
| 25 | +/* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */ |
| 26 | +/* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */ |
| 27 | +/* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ |
| 28 | +/* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ |
| 29 | +/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */ |
| 30 | +/* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */ |
| 31 | +/* POSSIBILITY OF SUCH DAMAGE. */ |
| 32 | +/* */ |
| 33 | +/* The views and conclusions contained in the software and */ |
| 34 | +/* documentation are those of the authors and should not be */ |
| 35 | +/* interpreted as representing official policies, either expressed */ |
| 36 | +/* or implied, of The University of Texas at Austin. */ |
| 37 | +/*********************************************************************/ |
| 38 | + |
| 39 | +#include <stdio.h> |
| 40 | +#include <stdlib.h> |
| 41 | +#ifdef __CYGWIN32__ |
| 42 | +#include <sys/time.h> |
| 43 | +#endif |
| 44 | +#include "common.h" |
| 45 | + |
| 46 | + |
| 47 | +#undef GEEV |
| 48 | + |
| 49 | +#ifndef COMPLEX |
| 50 | +#ifdef XDOUBLE |
| 51 | +#define GEEV BLASFUNC(qgeev) |
| 52 | +#elif defined(DOUBLE) |
| 53 | +#define GEEV BLASFUNC(dgeev) |
| 54 | +#else |
| 55 | +#define GEEV BLASFUNC(sgeev) |
| 56 | +#endif |
| 57 | +#else |
| 58 | +#ifdef XDOUBLE |
| 59 | +#define GEEV BLASFUNC(xgeev) |
| 60 | +#elif defined(DOUBLE) |
| 61 | +#define GEEV BLASFUNC(zgeev) |
| 62 | +#else |
| 63 | +#define GEEV BLASFUNC(cgeev) |
| 64 | +#endif |
| 65 | +#endif |
| 66 | + |
| 67 | +#ifndef COMPLEX |
| 68 | +extern void GEEV( char* jobvl, char* jobvr, blasint* n, FLOAT* a, |
| 69 | + blasint* lda, FLOAT* wr, FLOAT* wi, FLOAT* vl, blasint* ldvl, |
| 70 | + FLOAT* vr, blasint* ldvr, FLOAT* work, blasint* lwork, blasint* info ); |
| 71 | +#else |
| 72 | +extern void GEEV( char* jobvl, char* jobvr, blasint* n, FLOAT* a, |
| 73 | + blasint* lda, FLOAT* wr, FLOAT* vl, blasint* ldvl, |
| 74 | + FLOAT* vr, blasint* ldvr, FLOAT* work, blasint* lwork, FLOAT *rwork, blasint* info ); |
| 75 | +#endif |
| 76 | + |
| 77 | +#if defined(__WIN32__) || defined(__WIN64__) |
| 78 | + |
| 79 | +#ifndef DELTA_EPOCH_IN_MICROSECS |
| 80 | +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL |
| 81 | +#endif |
| 82 | + |
| 83 | +int gettimeofday(struct timeval *tv, void *tz){ |
| 84 | + |
| 85 | + FILETIME ft; |
| 86 | + unsigned __int64 tmpres = 0; |
| 87 | + static int tzflag; |
| 88 | + |
| 89 | + if (NULL != tv) |
| 90 | + { |
| 91 | + GetSystemTimeAsFileTime(&ft); |
| 92 | + |
| 93 | + tmpres |= ft.dwHighDateTime; |
| 94 | + tmpres <<= 32; |
| 95 | + tmpres |= ft.dwLowDateTime; |
| 96 | + |
| 97 | + /*converting file time to unix epoch*/ |
| 98 | + tmpres /= 10; /*convert into microseconds*/ |
| 99 | + tmpres -= DELTA_EPOCH_IN_MICROSECS; |
| 100 | + tv->tv_sec = (long)(tmpres / 1000000UL); |
| 101 | + tv->tv_usec = (long)(tmpres % 1000000UL); |
| 102 | + } |
| 103 | + |
| 104 | + return 0; |
| 105 | +} |
| 106 | + |
| 107 | +#endif |
| 108 | + |
| 109 | +#if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0 |
| 110 | + |
| 111 | +static void *huge_malloc(BLASLONG size){ |
| 112 | + int shmid; |
| 113 | + void *address; |
| 114 | + |
| 115 | +#ifndef SHM_HUGETLB |
| 116 | +#define SHM_HUGETLB 04000 |
| 117 | +#endif |
| 118 | + |
| 119 | + if ((shmid =shmget(IPC_PRIVATE, |
| 120 | + (size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1), |
| 121 | + SHM_HUGETLB | IPC_CREAT |0600)) < 0) { |
| 122 | + printf( "Memory allocation failed(shmget).\n"); |
| 123 | + exit(1); |
| 124 | + } |
| 125 | + |
| 126 | + address = shmat(shmid, NULL, SHM_RND); |
| 127 | + |
| 128 | + if ((BLASLONG)address == -1){ |
| 129 | + printf( "Memory allocation failed(shmat).\n"); |
| 130 | + exit(1); |
| 131 | + } |
| 132 | + |
| 133 | + shmctl(shmid, IPC_RMID, 0); |
| 134 | + |
| 135 | + return address; |
| 136 | +} |
| 137 | + |
| 138 | +#define malloc huge_malloc |
| 139 | + |
| 140 | +#endif |
| 141 | + |
| 142 | +int MAIN__(int argc, char *argv[]){ |
| 143 | + |
| 144 | + FLOAT *a,*vl,*vr,*wi,*wr,*work,*rwork; |
| 145 | + FLOAT wkopt[4]; |
| 146 | + char job='V'; |
| 147 | + char *p; |
| 148 | + |
| 149 | + blasint m, i, j, info,lwork; |
| 150 | + double factor = 26.33; |
| 151 | + |
| 152 | + int from = 1; |
| 153 | + int to = 200; |
| 154 | + int step = 1; |
| 155 | + |
| 156 | + struct timeval start, stop; |
| 157 | + double time1; |
| 158 | + |
| 159 | + argc--;argv++; |
| 160 | + |
| 161 | + if (argc > 0) { from = atol(*argv); argc--; argv++;} |
| 162 | + if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;} |
| 163 | + if (argc > 0) { step = atol(*argv); argc--; argv++;} |
| 164 | + |
| 165 | + if ((p = getenv("OPENBLAS_JOB"))) job=*p; |
| 166 | + |
| 167 | + if ( job == 'N' ) factor = 10.0; |
| 168 | + |
| 169 | + fprintf(stderr, "From : %3d To : %3d Step = %3d Job=%c\n", from, to, step,job); |
| 170 | + |
| 171 | + if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){ |
| 172 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 173 | + } |
| 174 | + |
| 175 | + if (( vl = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){ |
| 176 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 177 | + } |
| 178 | + |
| 179 | + if (( vr = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){ |
| 180 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 181 | + } |
| 182 | + |
| 183 | + if (( wr = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){ |
| 184 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 185 | + } |
| 186 | + |
| 187 | + if (( wi = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){ |
| 188 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 189 | + } |
| 190 | + |
| 191 | + if (( rwork = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){ |
| 192 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 193 | + } |
| 194 | + |
| 195 | + for(j = 0; j < to; j++){ |
| 196 | + for(i = 0; i < to * COMPSIZE; i++){ |
| 197 | + a[i + j * to * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5; |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + |
| 202 | + lwork = -1; |
| 203 | + m=to; |
| 204 | +#ifndef COMPLEX |
| 205 | + GEEV (&job, &job, &m, a, &m, wr, wi, vl, &m, vr, &m, wkopt, &lwork, &info); |
| 206 | +#else |
| 207 | + GEEV (&job, &job, &m, a, &m, wr, vl, &m, vr, &m, wkopt, &lwork,rwork, &info); |
| 208 | +#endif |
| 209 | + |
| 210 | + lwork = (blasint)wkopt[0]; |
| 211 | + if (( work = (FLOAT *)malloc(sizeof(FLOAT) * lwork * COMPSIZE)) == NULL){ |
| 212 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 213 | + } |
| 214 | + |
| 215 | + |
| 216 | +#ifdef linux |
| 217 | + srandom(getpid()); |
| 218 | +#endif |
| 219 | + |
| 220 | + fprintf(stderr, " SIZE FLops Time Lwork\n"); |
| 221 | + |
| 222 | + for(m = from; m <= to; m += step){ |
| 223 | + |
| 224 | + fprintf(stderr, " %6d : ", (int)m); |
| 225 | + gettimeofday( &start, (struct timezone *)0); |
| 226 | + |
| 227 | + lwork = -1; |
| 228 | +#ifndef COMPLEX |
| 229 | + GEEV (&job, &job, &m, a, &m, wr, wi, vl, &m, vr, &m, wkopt, &lwork, &info); |
| 230 | +#else |
| 231 | + GEEV (&job, &job, &m, a, &m, wr, vl, &m, vr, &m, wkopt, &lwork,rwork, &info); |
| 232 | +#endif |
| 233 | + |
| 234 | + lwork = (blasint)wkopt[0]; |
| 235 | +#ifndef COMPLEX |
| 236 | + GEEV (&job, &job, &m, a, &m, wr, wi, vl, &m, vr, &m, work, &lwork, &info); |
| 237 | +#else |
| 238 | + GEEV (&job, &job, &m, a, &m, wr, vl, &m, vr, &m, work, &lwork,rwork, &info); |
| 239 | +#endif |
| 240 | + |
| 241 | + gettimeofday( &stop, (struct timezone *)0); |
| 242 | + |
| 243 | + if (info) { |
| 244 | + fprintf(stderr, "failed to compute eigenvalues .. %d\n", info); |
| 245 | + exit(1); |
| 246 | + } |
| 247 | + |
| 248 | + time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6; |
| 249 | + |
| 250 | + fprintf(stderr, |
| 251 | + " %10.2f MFlops : %10.2f Sec : %d\n", |
| 252 | + COMPSIZE * COMPSIZE * factor * (double)m * (double)m * (double)m / time1 * 1.e-6,time1,lwork); |
| 253 | + |
| 254 | + |
| 255 | + } |
| 256 | + |
| 257 | + return 0; |
| 258 | +} |
| 259 | + |
| 260 | +void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__"))); |
0 commit comments