r1search.c
来自「基于Blas CLapck的.用过的人知道是干啥的」· C语言 代码 · 共 572 行 · 第 1/2 页
C
572 行
/* * Automatically Tuned Linear Algebra Software v3.8.0 * (C) Copyright 1999 R. Clint Whaley * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions, and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the ATLAS group or the names of its contributers may * not be used to endorse or promote products derived from this * software without specific written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ATLAS GROUP OR ITS CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * */#include <stdio.h>#include <stdlib.h>#include <ctype.h>#include <assert.h>#include "atlas_fopen.h"#define ATL_NoBlock(iflag_) ( ((iflag_) | 32) == (iflag_) )double GetAvg(int n, double tolerance, double *mflop){ int i, j; double t0, tavg;/* * Sort results, largest first */ for (i=0; i != n; i++) { for (j=i+1; j < n; j++) { if (mflop[i] < mflop[j]) { t0 = mflop[i]; mflop[i] = mflop[j]; mflop[j] = t0; } } }/* * Throw out result if it is outside tolerance; rerun if two mflop not within * tolerance; this code assumes n == 3 */ if (tolerance*mflop[1] < mflop[0]) /* too big a range in results */ { if (tolerance*mflop[2] < mflop[1]) return(-1.0); tavg = (mflop[1] + mflop[2]) / 2.0; } else if (tolerance*mflop[2] < mflop[0]) tavg = (mflop[0] + mflop[1]) / 2.0; else tavg = (mflop[0] + mflop[1] + mflop[2]) / 3.0; return(tavg);}int GetL1CacheSize(){ FILE *L1f; int L1Size; if (!FileExists("res/L1CacheSize")) { assert(system("make res/L1CacheSize\n") == 0); } L1f = fopen("res/L1CacheSize", "r"); assert(L1f != NULL); fscanf(L1f, "%d", &L1Size); fclose(L1f); fprintf(stderr, "\n Read in L1 Cache size as = %dKB.\n",L1Size); return(L1Size);}void NoEndLineWhiteSpace(char *ln){ int i; for (i=0; ln[i]; i++); if (i) for (i--; isspace(ln[i]); i--) ln[i] = '\0';}int LineIsCont(char *ln){ int i, iret=0; for(i=0; ln[i]; i++); if (i) { for(i--; isspace(ln[i]); i--); if (ln[i] == '\\') iret = 1; } return(iret);}void emit_r1head(char pre, int l1mul, int flag, int mu, int nu){ char ln[256]; sprintf(ln, "./xemit_r1h -p %c -l %d -f %d -x %d -y %d\n", pre, l1mul, flag, mu, nu); assert(system(ln) == 0);}int r1tstcase(char pre, char *r1nam, char *cc, char *ccflags){ char ln[256]; if (cc[0] != '\0' && ccflags[0] != '\0') sprintf(ln, "make %cr1tstcase r1rout=%s %cR1CC=\"%s\" %cR1FLAGS=\"%s\"\n", pre, r1nam, pre, cc, pre, ccflags); else if (cc[0] == '\0' && ccflags[0] != '\0') sprintf(ln, "make %cr1tstcase r1rout=%s EXTFLAGS=\"%s\"\n", pre, r1nam, ccflags); else sprintf(ln, "make %cr1tstcase r1rout=%s\n", pre, r1nam); return(system(ln));}double r1case(char pre, char *r1nam, int flag, int mu, int nu, int cas, char *cc, char *ccflags, int l1mul){ char fnam[128], ln[128]; double mf, mfs[3]; int i; FILE *fp; if (ATL_NoBlock(flag)) sprintf(fnam, "res/%cger1_%d_0", pre, cas); else sprintf(fnam, "res/%cger1_%d_%d", pre, cas, l1mul); if (!FileExists(fnam)) { i = sprintf(ln, "make %cr1case r1rout=%s cas=%d l1mul=%d iflag=%d xu=%d yu=%d", pre, r1nam, cas, l1mul, flag, mu, nu); if (cc[0] != '\0' && ccflags[0] != '\0') i += sprintf(ln+i, " %cR1CC=\"%s\" %cR1FLAGS=\"%s\"", pre, cc, pre, ccflags); else if (cc[0] == '\0' && ccflags[0] != '\0') i += sprintf(ln+i, " EXTFLAGS=\"%s\"", ccflags); i += sprintf(ln+i, "\n"); fprintf(stderr, "%s", ln); if (system(ln)) return(-1.0); /* won't compile here */ } fp = fopen(fnam, "r"); assert(fp); assert(fscanf(fp, " %lf %lf %lf", mfs, mfs+1, mfs+2) == 3); fclose(fp); mf = GetAvg(3, 1.20, mfs); if (mf == -1.0) { fprintf(stderr,"\n\n%s : VARIATION EXCEEDS TOLERENCE, RERUN WITH HIGHER REPS.\n\n", fnam); sprintf(ln, "rm -f %s\n", fnam); system(ln); exit(-1); } return(mf);}void CreateSum(char pre, int l1mul, int ID, char *r1nam, char *auth, int flag, int mu, int nu, double mf){ char fnam[64]; FILE *fp; sprintf(fnam, "res/%cR1RES", pre); fp = fopen(fnam, "w"); assert(fp); fprintf(fp, "%d %d %d %d %d %.2f %s \"%s\"\n", ID, flag, mu, nu, l1mul, mf, r1nam, auth); fclose(fp);}void ReadSum(char pre, int *l1mul, int *ID, char *r1nam, char *auth, int *flag, int *mu, int *nu, double *mf){ char fnam[64]; FILE *fp; sprintf(fnam, "res/%cR1RES", pre); fp = fopen(fnam, "r"); assert(fp); assert(fscanf(fp, " %d %d %d %d %d %lf %s \"%[^\"]", ID, flag, mu, nu, l1mul, mf, r1nam, auth) == 8); fclose(fp);}void GenMakefile(char pre, char *cc, char *ccflags){ int i; FILE *fp; char *typ, *comp, *cflags; char ln[64]; if (pre == 's') typ = "SREAL"; else if (pre == 'd') typ = "DREAL"; else if (pre == 'c') typ = "SCPLX"; else if (pre == 'z') typ = "DCPLX"; else assert(0); if (pre == 's' || pre == 'c') { comp = "$(SKC)"; cflags = "$(SKCFLAGS)"; } else { comp = "$(DKC)"; cflags = "$(DKCFLAGS)"; } sprintf(ln, "Make_%cr1", pre); fp = fopen(ln, "w"); assert(fp); fprintf(fp, "include Make.inc\n\n"); if (cc[0] == '\0') fprintf(fp, "R1CC = %s\n", comp); else fprintf(fp, "R1CC = %s\n", cc); if (cc[0] == '\0' && ccflags[0] != '\0') fprintf(fp, "R1FLAGS = $(CDEFS) %s %s -D%s\n", cflags, ccflags, typ); else if (ccflags[0] != '\0') fprintf(fp, "R1FLAGS = $(CDEFS) %s -D%s\n", ccflags, typ); else fprintf(fp, "R1FLAGS = $(CDEFS) %s -D%s\n", cflags, typ); if (pre == 's' || pre == 'd') fprintf(fp, "\nobj = ATL_%cger1_a1_x1_yX.o\n\n", pre); else fprintf(fp, "\nobj = ATL_%cger1u_a1_x1_yX.o ATL_%cger1c_a1_x1_yX.o\n\n", pre, pre); fprintf(fp, "%clib : lib\nlib : %cr1k.grd\n", pre, pre); fprintf(fp, "%cr1k.grd : $(obj)\n", pre); fprintf(fp, "\t$(ARCHIVER) $(ARFLAGS) $(ATLASlib) $(obj)\n"); fprintf(fp, "\t$(RANLIB) $(ATLASlib)\n"); fprintf(fp, "\ttouch %cr1k.grd\n\n", pre); fprintf(fp, "clean :\n\t rm -f $(obj) %cr1k.grd\n", pre); fprintf(fp, "%cclean : clean\n\n", pre); if (pre == 's' || pre == 'd') { fprintf(fp, "ATL_%cger1_a1_x1_yX.o : ATL_%cger1.c\n", pre, pre); fprintf(fp, "\t$(R1CC) -o $@ -c $(R1FLAGS) ATL_%cger1.c\n", pre); } else { fprintf(fp, "ATL_%cger1u_a1_x1_yX.o : ATL_%cger1.c\n", pre, pre); fprintf(fp, "\t$(R1CC) -o $@ -c $(R1FLAGS) -D%s ATL_%cger1.c\n", typ, pre); fprintf(fp, "ATL_%cger1c_a1_x1_yX.o : ATL_%cger1.c\n", pre, pre); fprintf(fp, "\t$(R1CC) -o $@ -c $(R1FLAGS) -DConj_ ATL_%cger1.c\n", pre); } fclose(fp);}void r1install(char pre, int id, char *r1nam, char *auth, int l1mul, int flag, char *cc, char *ccflags, int mu, int nu){ char ln[128]; double mf; GenMakefile(pre, cc, ccflags); mf = r1case(pre, r1nam, flag, mu, nu, id, cc, ccflags, l1mul); emit_r1head(pre, l1mul, flag, mu, nu); sprintf(ln, "make %cinstall r1rout=%s\n", pre, r1nam); fprintf(stderr, "%s", ln); assert(system(ln) == 0); CreateSum(pre, l1mul, id, r1nam, auth, flag, mu, nu, mf);}int FindL1Mul(char pre, int cas, char *r1nam, int flag, int mu, int nu,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?