|
| 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 | +#undef GETRF |
| 47 | +#undef GETRI |
| 48 | + |
| 49 | +#ifndef COMPLEX |
| 50 | +#ifdef XDOUBLE |
| 51 | +#define GETRF BLASFUNC(qgetrf) |
| 52 | +#define GETRI BLASFUNC(qgetri) |
| 53 | +#elif defined(DOUBLE) |
| 54 | +#define GETRF BLASFUNC(dgetrf) |
| 55 | +#define GETRI BLASFUNC(dgetri) |
| 56 | +#else |
| 57 | +#define GETRF BLASFUNC(sgetrf) |
| 58 | +#define GETRI BLASFUNC(sgetri) |
| 59 | +#endif |
| 60 | +#else |
| 61 | +#ifdef XDOUBLE |
| 62 | +#define GETRF BLASFUNC(xgetrf) |
| 63 | +#define GETRI BLASFUNC(xgetri) |
| 64 | +#elif defined(DOUBLE) |
| 65 | +#define GETRF BLASFUNC(zgetrf) |
| 66 | +#define GETRI BLASFUNC(zgetri) |
| 67 | +#else |
| 68 | +#define GETRF BLASFUNC(cgetrf) |
| 69 | +#define GETRI BLASFUNC(cgetri) |
| 70 | +#endif |
| 71 | +#endif |
| 72 | + |
| 73 | +extern void GETRI(blasint *m, FLOAT *a, blasint *lda, blasint *ipiv, FLOAT *work, blasint *lwork, blasint *info); |
| 74 | + |
| 75 | +#if defined(__WIN32__) || defined(__WIN64__) |
| 76 | + |
| 77 | +#ifndef DELTA_EPOCH_IN_MICROSECS |
| 78 | +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL |
| 79 | +#endif |
| 80 | + |
| 81 | +int gettimeofday(struct timeval *tv, void *tz){ |
| 82 | + |
| 83 | + FILETIME ft; |
| 84 | + unsigned __int64 tmpres = 0; |
| 85 | + static int tzflag; |
| 86 | + |
| 87 | + if (NULL != tv) |
| 88 | + { |
| 89 | + GetSystemTimeAsFileTime(&ft); |
| 90 | + |
| 91 | + tmpres |= ft.dwHighDateTime; |
| 92 | + tmpres <<= 32; |
| 93 | + tmpres |= ft.dwLowDateTime; |
| 94 | + |
| 95 | + /*converting file time to unix epoch*/ |
| 96 | + tmpres /= 10; /*convert into microseconds*/ |
| 97 | + tmpres -= DELTA_EPOCH_IN_MICROSECS; |
| 98 | + tv->tv_sec = (long)(tmpres / 1000000UL); |
| 99 | + tv->tv_usec = (long)(tmpres % 1000000UL); |
| 100 | + } |
| 101 | + |
| 102 | + return 0; |
| 103 | +} |
| 104 | + |
| 105 | +#endif |
| 106 | + |
| 107 | +#if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0 |
| 108 | + |
| 109 | +static void *huge_malloc(BLASLONG size){ |
| 110 | + int shmid; |
| 111 | + void *address; |
| 112 | + |
| 113 | +#ifndef SHM_HUGETLB |
| 114 | +#define SHM_HUGETLB 04000 |
| 115 | +#endif |
| 116 | + |
| 117 | + if ((shmid =shmget(IPC_PRIVATE, |
| 118 | + (size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1), |
| 119 | + SHM_HUGETLB | IPC_CREAT |0600)) < 0) { |
| 120 | + printf( "Memory allocation failed(shmget).\n"); |
| 121 | + exit(1); |
| 122 | + } |
| 123 | + |
| 124 | + address = shmat(shmid, NULL, SHM_RND); |
| 125 | + |
| 126 | + if ((BLASLONG)address == -1){ |
| 127 | + printf( "Memory allocation failed(shmat).\n"); |
| 128 | + exit(1); |
| 129 | + } |
| 130 | + |
| 131 | + shmctl(shmid, IPC_RMID, 0); |
| 132 | + |
| 133 | + return address; |
| 134 | +} |
| 135 | + |
| 136 | +#define malloc huge_malloc |
| 137 | + |
| 138 | +#endif |
| 139 | + |
| 140 | +int MAIN__(int argc, char *argv[]){ |
| 141 | + |
| 142 | + FLOAT *a,*work; |
| 143 | + FLOAT wkopt[4]; |
| 144 | + blasint *ipiv; |
| 145 | + blasint m, i, j, info,lwork; |
| 146 | + |
| 147 | + int from = 1; |
| 148 | + int to = 200; |
| 149 | + int step = 1; |
| 150 | + |
| 151 | + struct timeval start, stop; |
| 152 | + double time1; |
| 153 | + |
| 154 | + argc--;argv++; |
| 155 | + |
| 156 | + if (argc > 0) { from = atol(*argv); argc--; argv++;} |
| 157 | + if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;} |
| 158 | + if (argc > 0) { step = atol(*argv); argc--; argv++;} |
| 159 | + |
| 160 | + |
| 161 | + fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step); |
| 162 | + |
| 163 | + if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){ |
| 164 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 165 | + } |
| 166 | + |
| 167 | + if (( ipiv = (blasint *)malloc(sizeof(blasint) * to * COMPSIZE)) == NULL){ |
| 168 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 169 | + } |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | + for(j = 0; j < to; j++){ |
| 174 | + for(i = 0; i < to * COMPSIZE; i++){ |
| 175 | + a[i + j * to * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5; |
| 176 | + } |
| 177 | + } |
| 178 | + |
| 179 | + |
| 180 | + lwork = -1; |
| 181 | + m=to; |
| 182 | + |
| 183 | + GETRI(&m, a, &m, ipiv, wkopt, &lwork, &info); |
| 184 | + |
| 185 | + lwork = (blasint)wkopt[0]; |
| 186 | + if (( work = (FLOAT *)malloc(sizeof(FLOAT) * lwork * COMPSIZE)) == NULL){ |
| 187 | + fprintf(stderr,"Out of Memory!!\n");exit(1); |
| 188 | + } |
| 189 | + |
| 190 | + |
| 191 | +#ifdef linux |
| 192 | + srandom(getpid()); |
| 193 | +#endif |
| 194 | + |
| 195 | + fprintf(stderr, " SIZE FLops Time Lwork\n"); |
| 196 | + |
| 197 | + for(m = from; m <= to; m += step){ |
| 198 | + |
| 199 | + fprintf(stderr, " %6d : ", (int)m); |
| 200 | + |
| 201 | + GETRF (&m, &m, a, &m, ipiv, &info); |
| 202 | + |
| 203 | + if (info) { |
| 204 | + fprintf(stderr, "Matrix is not singular .. %d\n", info); |
| 205 | + exit(1); |
| 206 | + } |
| 207 | + |
| 208 | + gettimeofday( &start, (struct timezone *)0); |
| 209 | + |
| 210 | + lwork = -1; |
| 211 | + GETRI(&m, a, &m, ipiv, wkopt, &lwork, &info); |
| 212 | + |
| 213 | + lwork = (blasint)wkopt[0]; |
| 214 | + GETRI(&m, a, &m, ipiv, work, &lwork, &info); |
| 215 | + gettimeofday( &stop, (struct timezone *)0); |
| 216 | + |
| 217 | + if (info) { |
| 218 | + fprintf(stderr, "failed compute inverse matrix .. %d\n", info); |
| 219 | + exit(1); |
| 220 | + } |
| 221 | + |
| 222 | + time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6; |
| 223 | + |
| 224 | + fprintf(stderr, |
| 225 | + " %10.2f MFlops : %10.2f Sec : %d\n", |
| 226 | + COMPSIZE * COMPSIZE * (4.0/3.0 * (double)m * (double)m *(double)m - (double)m *(double)m + 5.0/3.0* (double)m) / time1 * 1.e-6,time1,lwork); |
| 227 | + |
| 228 | + |
| 229 | + } |
| 230 | + |
| 231 | + return 0; |
| 232 | +} |
| 233 | + |
| 234 | +void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__"))); |
0 commit comments