int aiff_isfile(const uint8_t *data, size_t input_len, struct file_info *info) { size_t length; const char *ext; uint32_t format; if (input_len < AIFF_HEADER_SIZE) return 0; if (MAGIC(data) != FORM_MAGIC) return 0; length = be32toh(*(const uint32_t *)(data + 4)) + 8; if (input_len < length) return 0; format = MAGIC(data + 8); if (format == AIFF_MAGIC) ext = "aiff"; else if (format == AIFC_MAGIC) ext = "aifc"; else return 0; if (info) { info->length = length; info->ext = ext; } return 1; }
static void tryToDemangleAout(char *file) { obj_n = file; if ((sym=fopen(obj_n, "r+")) == NULL) cerr << "demangle: can't open " << obj_n << endl; else { xsetbuf(sym, symb); HDR x; fread((char*)&x, HDRSZ, 1, sym); #if 1 if (N_BADMAG(x)) #else // on system v, used to get the magic number in the // auxiliary unix header following the file header aouthdr y; fread((char*)&y, sizeof(aouthdr), 1, sym); if (N_BADMAG(y)) #endif { cerr << "demangle: " << obj_n << " not an object file (magic is 0" << oct << MAGIC(x) << dec << ")" << endl; } else { long nsyms = N_SYMS(x); if (nsyms > 0) // else it's a stripped object, and there's nothing to do. demangleAout(&x, nsyms); } fclose(sym); } }
static inline EcBool check_node(ec_list_node p) { if (MAGIC(p) != NODE_MAGIC) { fprintf( stderr, "CORRUPTED/NOT A NODE: 0x%08lX\n", (unsigned long)p ); return FALSE; } return TRUE; }
static inline EcBool check_iter(ec_list_iterator p) { if (MAGIC(p) != ITER_MAGIC) { fprintf( stderr, "CORRUPTED/NOT AN ITERATOR: 0x%08lX\n", (unsigned long)p ); return FALSE; } return TRUE; }
static inline EcBool check_list(ec_list p) { if (MAGIC(p) != LIST_MAGIC) { fprintf( stderr, "CORRUPTED/NOT A LIST: 0x%08lX\n", (unsigned long)p ); return FALSE; } return TRUE; }
/** * Shared prologue for functions generating random bytes from an ottery_state. * Make sure that the state is initialized. */ static inline int ottery_st_rand_check_init(struct ottery_state *st) { #ifndef OTTERY_NO_INIT_CHECK if (UNLIKELY(st->magic != MAGIC(st))) { ottery_fatal_error_(OTTERY_ERR_STATE_INIT); return -1; } #else (void)st; #endif return 0; }
static inline void dyn_free_block (void *p, int words) { assert (words >= PTR_INTS); FreeCnt[words]++; if (!((long) p & 7)) { NX(p) = FreeBlocksAligned[words]; FreeBlocksAligned[words] = p; } else { NX(p) = FreeBlocks[words]; FreeBlocks[words] = p; } if (words > PTR_INTS) { MAGIC(p) = DYN_FREE_MAGIC; } }
int __fdtable_free(__fdtable_t * fdtable) { if(fdtable == 0) { errno = EINVAL; return (-1); } __free(&fdtable->Descriptors); memset(fdtable, 0, sizeof(*fdtable)); fdtable->Signature = MAGIC('B', 'A', 'A', 'D'); return (0); }
static inline void make_magic_node(ec_list_node p) { MAGIC(p) = NODE_MAGIC; }
static inline void make_magic_iter(ec_list_iterator p) { MAGIC(p) = ITER_MAGIC; }
void *dyn_alloc (long size, int align) { int tmp; char *r = 0; assert (size >= 0 && (unsigned long) size < (unsigned long) dynamic_data_buffer_size); size = (size + 3) & -4; if (dyn_mark_top) { r = dyn_cur + ((align - (long) dyn_cur) & (align - 1)); if (dyn_top <= r || dyn_top < r + size) { if (verbosity > 0) { fprintf (stderr, "unable to allocate %ld bytes\n", size); } return 0; } dyn_cur = r + size; return r; } if (size < PTRSIZE) { size = PTRSIZE; } long t = ((unsigned long) size >> 2); if (t < MAX_RECORD_WORDS && FreeBlocks[t] && align == 4) { r = FreeBlocks[t]; assert (r >= dyn_first && r <= dyn_last - size && !(((long) r) & 3)); if (t > PTR_INTS) { assert (MAGIC(r) == DYN_FREE_MAGIC); MAGIC(r) = 0; } FreeBlocks[t] = NX(r); FreeCnt[t]--; UsedCnt[t]++; NewAllocations[t][1]++; return r; } if (t < MAX_RECORD_WORDS && FreeBlocksAligned[t] && (align == 4 || align == 8)) { r = FreeBlocksAligned[t]; assert (r >= dyn_first && r <= dyn_last - size && !(((long) r) & 7)); if (t > PTR_INTS) { assert (MAGIC(r) == DYN_FREE_MAGIC); MAGIC(r) = 0; } FreeBlocksAligned[t] = NX(r); FreeCnt[t]--; UsedCnt[t]++; NewAllocations[t][1]++; return r; } if (t < MAX_RECORD_WORDS) { tmp = SplitBlocks[t]; if (tmp) { if (tmp > 0) { assert (tmp >= t + PTR_INTS); if (FreeBlocks[tmp] && (PTR_INTS == 1 || align == 4 || tmp >= t + 5)) { r = FreeBlocks[tmp]; } else if (FreeBlocksAligned[tmp]) { r = FreeBlocksAligned[tmp]; } else { tmp = -t - PTR_INTS; } } if (tmp < 0) { tmp = -tmp; int tmp2 = tmp + 5; if (tmp2 > MAX_RECORD_WORDS - 1) { tmp2 = MAX_RECORD_WORDS - 1; } while (++tmp < tmp2) { if (FreeBlocks[tmp] && (PTR_INTS == 1 || align == 4 || tmp >= t + 5)) { r = FreeBlocks[tmp]; break; } else if (FreeBlocksAligned[tmp]) { r = FreeBlocksAligned[tmp]; break; } } if (tmp < MAX_RECORD_WORDS) { SplitBlocks[t] = -tmp; } } } } if (t < MAX_RECORD_WORDS && r && (align == 4 || align == 8)) { char *q = r + size; assert (tmp > t); assert (r >= dyn_first && r <= dyn_last - size && !(((long) r) & 3)); if (t > PTR_INTS) { assert (MAGIC(r) == DYN_FREE_MAGIC); MAGIC(r) = 0; } if (r == FreeBlocks[tmp]) { FreeBlocks[tmp] = NX(r); } else { FreeBlocksAligned[tmp] = NX(r); } FreeCnt[tmp]--; UsedCnt[t]++; NewAllocations[t][2]++; if (align == 4 || !((long) r & 7)) { tmp -= t; dyn_free_block (q, tmp); return r; } else if ((tmp - t) & 1) { tmp -= t; dyn_free_block (r, tmp); return r + tmp*4; } else { int z = 2 * PTR_INTS - 1; dyn_free_block (r, z); r += z*4; q += z*4; tmp -= t + z; assert (tmp >= 0); if (tmp > 0) { dyn_free_block (q, tmp); } return r; } } r = dyn_cur + ((align - (long) dyn_cur) & (align - 1)); if (dyn_top <= r || dyn_top < r + size) { if (verbosity > 0) { fprintf (stderr, "unable to allocate %ld bytes\n", size); } return 0; } if (t < MAX_RECORD_WORDS) { NewAllocations[t][0]++; UsedCnt[t]++; } dyn_cur = r + size; return r; }
static inline void make_magic_list(ec_list p) { MAGIC(p) = LIST_MAGIC; }
int main(int argc, char *argv[]) { // DA memory create const int h_mem = atoi(argv[1]); const int w_mem = atoi(argv[2]); const int h_page = atoi(argv[3]); const int w_page = atoi(argv[4]); const int h_dataset = atoi(argv[5]); const int w_dataset = atoi(argv[6]); WIDTH = atoi(argv[7]); sqrtWIDTH = sqrt(WIDTH); //const int h_mem = 4 * 2 * 32; //const int w_mem = 4 * 16 * 32; //const int h_page = 1 * 16; //const int w_page = 8 * 16; //const int h_dataset = 1; //const int w_dataset = 8; //const int h_mem = 1 * 16 * 32; //const int w_mem = 1 * 16 * 32; //const int h_page = 1 * 16; //const int w_page = 4 * 16; //const int h_dataset = 1; //const int w_dataset = 8; //const int h_mem = 1 * 16 * 32; //const int w_mem = 1 * 16 * 32; //const int h_page = 1 * 4; //const int w_page = 8 * 4; //const int h_dataset = 1; //const int w_dataset = 8; // POLICY = (Arranger_padding | Arranger_concatenating | Arranger_hyperpadding) DAmemory<POLICY, Scheduler_LRU> damemory(h_mem, w_mem, h_page, w_page, h_dataset, w_dataset); int i, j, k; float I; float *A; //FILE *ofile; //printf("&i: %p\t&j: %p\t&k: %p\t&I: %p\n", &i, &j, &k, &I); //printf("&a: %p\n", &A); //printf("transaction\tmatrix size: (%d, %d)\tvalue range: (0, %d)\n", WIDTH, WIDTH, MAX); /////////////// malloc A = (float *)malloc(WIDTH*WIDTH*sizeof(float)); auto m_a = damemory.allocate("a", WIDTH, WIDTH, sizeof(float)); if (!A) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", A, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", A, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &k); //fprintf(ofile, "%p\n", &I); //fprintf(ofile, "%p\n", &A); //fflush(ofile); //fclose(ofile); /////////////// initialization for (i=0; i<WIDTH; i++) for (j=0; j<WIDTH; j++) { A[i*WIDTH+j] = i<j ? i+1 : j+1; } /////////////// print result #ifdef PRINT printf("test case: \n"); for (i=0; i<WIDTH; i++) { for (j=0; j<WIDTH; j++) printf("%f ", A[i*WIDTH+j]); printf("\n"); } #endif /////////////// left-looking cholesky factorization MAGIC(3); for (j=0; j<WIDTH; j++) { for (i=j; i<WIDTH; i++) for (k=0; k<j; k++) { MAGIC(1); I = A[i*WIDTH+k] * A[j*WIDTH+k]; m_a.load(i, k); m_a.load(j, k); MAGIC(1); MAGIC(2); A[i*WIDTH+j] -= I; m_a.write(i, j); MAGIC(2); // A[i*WIDTH+j] = A[i*WIDTH+j] - A[i*WIDTH+k] * A[j*WIDTH+k]; } MAGIC(1); // A[j*WIDTH+j] = A[j*WIDTH+j] * A[j*WIDTH+j]; I = A[j*WIDTH+j]; m_a.load(j, j); A[j*WIDTH+j] = I * I; m_a.write(j, j); MAGIC(1); MAGIC(2); for (i=j+1; i<WIDTH; i++) { A[i*WIDTH+j] = A[i*WIDTH+j] / A[j*WIDTH+j]; m_a.load(i, j); m_a.load(j, j); m_a.write(i, j); } MAGIC(2); } MAGIC(3); /////////////// print result #ifdef PRINT printf("result: \n"); for (j=0; j<WIDTH; j++) for (i=j+1; i<WIDTH; i++) A[j*WIDTH+i] = 0; for (i=0; i<WIDTH; i++) { for (j=0; j<WIDTH; j++) printf("%f ", A[i*WIDTH+j]); printf("\n"); } #endif /////////////// free free(A); damemory.report("left.csv"); return 0; }
int main(int argc, char **argv) { quantum_reg qr; int i; int width, swidth; int x = 0; int N; int c, q, a, b, factor; #if defined(SPEC_CPU) spec_srand(26); #else srandom(time(0)); #endif /* SPEC_CPU */ if(argc == 1) { printf("Usage: shor [number]\n\n"); return 3; } N = atoi(argv[1]); if(N<15) { printf("Invalid number\n\n"); return 3; } width = quantum_getwidth(N * N); swidth = quantum_getwidth(N); printf("N = %i, %i qubits required\n", N, width + 3* swidth + 2); if(argc >= 3) { x = atoi(argv[2]); } while((quantum_gcd(N, x) > 1) || (x < 2)) { #if defined(SPEC_CPU) x = (long)(spec_rand() * 2147483647L) % N; #else x = random() % N; #endif /* SPEC_CPU */ } printf("Random seed: %i\n", x); qr = quantum_new_qureg(0, width); for (i = 0; i < width; i++) quantum_hadamard(i, &qr); quantum_addscratch(3* swidth + 2, &qr); cur_reg = &qr; pthread_t push_thread_id = thread_spawn((void*)&push_thread_func); #if defined(SIMICS) MAGIC(9006); #endif #if defined(SIMICS) MAGIC(9007); #endif //~ syscall(500, 0); // enter detailed simulation #ifdef MIPS_1 asm volatile ("addiu $0,$0,3720"); #endif quantum_exp_mod_n(N, x, width, swidth, &qr); for(i=0;i<3*swidth+2;i++) { quantum_bmeasure(0, &qr); } quantum_qft(width, &qr); for(i=0; i<width/2; i++) { quantum_cnot(i, width - i - 1, &qr); quantum_cnot(width - i - 1, i, &qr); quantum_cnot(i, width - i - 1, &qr); } c = quantum_measure(qr); if(c==-1) { printf("Impossible Measurement!\n"); exit(1); } if(c==0) { printf("Measured zero, try again.\n"); exit(2); } q = 1 << (width); printf("Measured %i (%f), ", c, (float) c / q); quantum_frac_approx(&c, &q, width); printf("fractional approximation is %i/%i.\n", c, q); if((q % 2 == 1) && (2*q<(1<<width))) { printf("Odd denominator, trying to expand by 2.\n"); q *= 2; } if(q % 2 == 1) { printf("Odd period, try again.\n"); exit(2); } printf("Possible period is %i.\n", q); a = quantum_ipow(x, q / 2) + 1 % N; b = quantum_ipow(x, q / 2) - 1 % N; a = quantum_gcd(N, a); b = quantum_gcd(N, b); if (a > b) factor = a; else factor = b; //thread_destroy(push_thread_id); cur_reg = NULL; #if defined(SIMICS) MAGIC(9008); #endif if((factor < N) && (factor > 1)) { printf("%i = %i * %i\n", N, factor, N / factor); } else { printf("Unable to determine factors, try again.\n"); #if defined(SPEC_CPU) exit(0); #else exit(2); #endif /* SPEC_CPU */ } quantum_delete_qureg(&qr); /* printf("Memory leak: %i bytes\n", (int) quantum_memman(0)); */ return 0; }
void Sound::load(const QString& filename) { qDebug() << filename; data=QVector<Q_INT32>(); QFile file(filename); if(!file.open(IO_ReadOnly)) { qWarning() <<"unable to open file" ; return; } QDataStream stream(&file); stream.setByteOrder( QDataStream::LittleEndian ); Q_INT32 magic; MAGIC("RIFF"); READ_FROM_STREAM(quint32,ChunkSize); MAGIC("WAVE"); MAGIC("fmt "); READ_FROM_STREAM(quint32,ChunkSize2); READ_FROM_STREAM(Q_INT16,AudioFormat); READ_FROM_STREAM(Q_UINT16,NumberOfChannels); READ_FROM_STREAM(quint32,SampleRate); _fs=SampleRate; READ_FROM_STREAM(quint32,ByteRate); READ_FROM_STREAM(Q_UINT16,BlockAlign); READ_FROM_STREAM(Q_UINT16,BitsPerSample); MAGIC("data"); READ_FROM_STREAM(QByteArray,SoundData); NumberOfChannels=1; //Wav i play are broken file.close(); uint BytePS=BitsPerSample/8; uint NumberOfSamples = (SoundData.size())/(NumberOfChannels*BytePS); data.resize(NumberOfSamples); // qDebug() << NumberOfSamples << " samples"; max=0; for(unsigned long int f=0;f<NumberOfSamples;f++) { Q_INT32 nb=0; for(uint k=0;k<BytePS;k++) { nb |= (SoundData[(unsigned int)(f*BytePS+k)]&0x000000FF) << (k*8); } if(nb & (1 << (BytePS*8 -1)) ) nb = nb-(1<<BytePS*8); data[f]=nb; if(ABS(nb)>max) { max=ABS(nb); } } /* static int q=0; QString name="test" + QString::number(q++) + ".wav"; save(name);*/ }
int main() { int i, j, k; float I; float *A; //FILE *ofile; //printf("&i: %p\t&j: %p\t&k: %p\t&I: %p\n", &i, &j, &k, &I); //printf("&a: %p\n", &A); //printf("transaction\tmatrix size: (%d, %d)\tvalue range: (0, %d)\n", WIDTH, WIDTH, MAX); /////////////// malloc A = (float *)malloc(WIDTH*WIDTH*sizeof(float)); if (!A) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", A, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", A, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &k); //fprintf(ofile, "%p\n", &I); //fprintf(ofile, "%p\n", &A); //fflush(ofile); //fclose(ofile); /////////////// initialization for (i=0; i<WIDTH; i++) for (j=0; j<WIDTH; j++) A[i*WIDTH+j] = i<j ? i+1 : j+1; /////////////// print result #ifdef PRINT printf("test case: \n"); for (i=0; i<WIDTH; i++) { for (j=0; j<WIDTH; j++) printf("%f ", A[i*WIDTH+j]); printf("\n"); } #endif /////////////// left-looking cholesky factorization MAGIC(3); for (j=0; j<WIDTH; j++) { for (i=j; i<WIDTH; i++) for (k=0; k<j; k++) { MAGIC(1); I = A[i*WIDTH+k] * A[j*WIDTH+k]; MAGIC(1); MAGIC(2); A[i*WIDTH+j] -= I; MAGIC(2); // A[i*WIDTH+j] = A[i*WIDTH+j] - A[i*WIDTH+k] * A[j*WIDTH+k]; } MAGIC(1); // A[j*WIDTH+j] = A[j*WIDTH+j] * A[j*WIDTH+j]; I = A[j*WIDTH+j]; A[j*WIDTH+j] = I * I; MAGIC(1); MAGIC(2); for (i=j+1; i<WIDTH; i++) A[i*WIDTH+j] = A[i*WIDTH+j] / A[j*WIDTH+j]; MAGIC(2); } MAGIC(3); /////////////// print result #ifdef PRINT printf("result: \n"); for (j=0; j<WIDTH; j++) for (i=j+1; i<WIDTH; i++) A[j*WIDTH+i] = 0; for (i=0; i<WIDTH; i++) { for (j=0; j<WIDTH; j++) printf("%f ", A[i*WIDTH+j]); printf("\n"); } #endif /////////////// free free(A); return 0; }
/** * Initialize or reinitialize a PRNG state. * * @param st The state to initialize or reinitialize. * @param prf The configuration to use. (Ignored for reinit) * @return An OTTERY_ERR_* value (zero on success, nonzero on failure). */ static int ottery_st_initialize(struct ottery_state *st, const struct ottery_config *config, int locked) { const struct ottery_prf *prf = NULL; struct ottery_config cfg_tmp; int err; /* We really need our state to be aligned. If it isn't, let's give an * error now, and not a crash when the SIMD instructions start to fail. */ if (((uintptr_t)st) & 0xf) return OTTERY_ERR_STATE_ALIGNMENT; if (!config) { ottery_config_init(&cfg_tmp); config = &cfg_tmp; } prf = config->impl; if (!prf) prf = ottery_get_impl(NULL); memset(st, 0, sizeof(*st)); if (locked) { /* Now set up the spinlock or mutex or hybrid thing. */ if (INIT_LOCK(&st->mutex)) return OTTERY_ERR_LOCK_INIT; } /* Check invariants for PRF, in case we wrote some bad code. */ if ((prf->state_len > MAX_STATE_LEN) || (prf->state_bytes > MAX_STATE_BYTES) || (prf->state_bytes > prf->output_len) || (prf->output_len > MAX_OUTPUT_LEN)) return OTTERY_ERR_INTERNAL; /* Check whether some of our structure size assumptions are right. */ if ((sizeof(struct ottery_state) > OTTERY_STATE_DUMMY_SIZE_) || (sizeof(struct ottery_config) > OTTERY_CONFIG_DUMMY_SIZE_)) return OTTERY_ERR_INTERNAL; memcpy(&st->entropy_config, &config->entropy_config, sizeof(struct ottery_entropy_config)); /* Copy the PRF into place. */ memcpy(&st->prf, prf, sizeof(*prf)); if ((err = ottery_st_reseed(st))) return err; /* Set the magic number last, or else we might look like we succeeded * when we didn't */ st->magic = MAGIC(st); st->pid = getpid(); return 0; }
void Matrix_Chain_Order(int argc, char *argv[], int p[],int num) { // DA memory create const int h_mem = atoi(argv[1]); const int w_mem = atoi(argv[2]); const int h_page = atoi(argv[3]); const int w_page = atoi(argv[4]); const int h_dataset = atoi(argv[5]); const int w_dataset = atoi(argv[6]); // POLICY = (Arranger_padding | Arranger_concatenating | Arranger_hyperpadding) DAmemory<POLICY, Scheduler_LRU> damemory(h_mem, w_mem, h_page, w_page, h_dataset, w_dataset); int *m; int *s; int q = 0; int i, j, k, l; int n = num; //FILE *ofile; //printf("multiplex\tmatrix size: (%d, %d)\tvalue range: (1, %d)\n", WIDTH, WIDTH, MAX); /////////////// malloc m = (int *)malloc(WIDTH*WIDTH*sizeof(int)); auto m_m = damemory.allocate("m", WIDTH, WIDTH, sizeof(int)); s = (int *)malloc(WIDTH*WIDTH*sizeof(int)); if (!m || !s) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", m, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", s, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", m, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", s, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &k); //fprintf(ofile, "%p\n", &l); //fprintf(ofile, "%p\n", &n); //fprintf(ofile, "%p\n", &q); //fprintf(ofile, "%p\n", &m); //fprintf(ofile, "%p\n", &s); //fflush(ofile); //fclose(ofile); /////////////// matrix chain order for(i = 1; i <= n; i++) { m[i*WIDTH+i] = 0; m_m.write(i, i); } for(l = 2; l <= n; l++) for(i = 1; i <= (n - l + 1); i++) { j = i + l - 1; m[i*WIDTH+j] = INT_MAX; m_m.write(i, j); } MAGIC(3); //for(l = 2000; l <= n; l++) for(l = 1; l <= n; l++) for(i = 1; i <= (n - l + 1); i++) { j = i + l - 1; // m[i*WIDTH+j] = INT_MAX; for(k = i; k <= j - 1; k++) { MAGIC(1); q = m[i*WIDTH+k]; m_m.load(i, k); MAGIC(1); MAGIC(2); q += m[(k+1)*WIDTH+j] + p[i-1] * p[k] * p[j]; m_m.load(k+1, j); MAGIC(2); MAGIC(1); if(q < m[i*WIDTH+j]) { m[i*WIDTH+j] = q; m_m.write(i, j); #ifdef PRINT s[i*WIDTH+j] = k; #endif } m_m.load(i, j); MAGIC(1); } } MAGIC(3); #ifdef PRINT printf("MULTIPLICATION SEQUENCE IS : "); printf("\n\n\t"); print(s, i-1, j); printf("\n\n"); printf("The Minimum No. of Multiplication Required is:\n\n"); printm(m,n); printf("\n"); #endif /////////////// free free(m); free(s); damemory.report("chain.csv"); }
static inline void del_magic_iter(ec_list_iterator p) { MAGIC(p) = 0; }
//#define PLACEMENT_INFO_FILE "base.in" //#define REGISTER_INFO_FILE "regs.in" //#define MAX 5 //#define WIDTH 3 //#define PRINT int main() { int i, j, k; int m, n; register int I, J; int *A, *B, *C; //FILE *ofile; m = n = WIDTH; //printf("multiplex\tmatrix size: (%d, %d)\tvalue range: (0, %d)\n", m, n, MAX); /////////////// malloc A = (int *)malloc(m*n*sizeof(int)); B = (int *)malloc(m*n*sizeof(int)); C = (int *)malloc(m*n*sizeof(int)); if (!A || !B || !C) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", A, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", B, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", C, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", A, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", B, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", C, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &A); //fprintf(ofile, "%p\n", &B); //fprintf(ofile, "%p\n", &C); //fflush(ofile); //fclose(ofile); /////////////// initialization srand(time(0)); for (i=0; i<m; i++) for (j=0; j<n; j++) { I = rand()%(MAX+1); A[i*WIDTH+j] = I; // currently no surport write I = rand()%(MAX+1); B[i*WIDTH+j] = I; // currently no surport write C[i*WIDTH+j] = 0; // currently no surport write } /////////////// multiplex MAGIC(3); for (i=0; i<m; i++) for (j=0; j<n; j++) { I = 0; for (k=0; k<WIDTH; k++) { MAGIC(1); J = A[i*WIDTH+k]; MAGIC(1); MAGIC(2); I += J * B[k*WIDTH+j]; MAGIC(2); } MAGIC(1); C[i*WIDTH+j] = I; // currently no surport write MAGIC(1); } MAGIC(3); #ifdef PRINT /////////////// print results printf("\nA:\n"); for (i=0; i<m; i++) { for (j=0; j<n; j++) printf("%d ", A[i*WIDTH+j]); printf("\n"); } printf("\nB:\n"); for (i=0; i<m; i++) { for (j=0; j<n; j++) printf("%d ", B[i*WIDTH+j]); printf("\n"); } printf("\nC:\n"); for (i=0; i<m; i++) { for (j=0; j<n; j++) printf("%d ", C[i*WIDTH+j]); printf("\n"); } #endif /////////////// free free(A); free(B); free(C); return 0; }
int main(int argc, char *argv[]) { // DA memory create const int h_mem = atoi(argv[1]); const int w_mem = atoi(argv[2]); const int h_page = atoi(argv[3]); const int w_page = atoi(argv[4]); const int h_dataset = atoi(argv[5]); const int w_dataset = atoi(argv[6]); WIDTH = atoi(argv[7]); sqrtWIDTH = sqrt(WIDTH); // POLICY = (Arranger_padding | Arranger_concatenating | Arranger_hyperpadding) DAmemory<POLICY, Scheduler_LRU> damemory(h_mem, w_mem, h_page, w_page, h_dataset, w_dataset); // float c[WIDTH+1*WIDTH+WIDTH+1]; // c[2^7*WIDTH+2^8] // float cp[WIDTH+1*WIDTH+WIDTH+1]; // c[2^7*WIDTH+2^8] float *c, *cp; int row, column; int i,j,k; //FILE *ofile; //printf("&i: %p\t&j: %p\t&k: %p\t&row: %p\t&column: %p\n", &i, &j, &k, &row, &column); //printf("&a: %p\t&b: %p\n", &c, &cp); // printf("transaction\tmatrix size: (%d, %d)\tvalue range: (0, %d)\n", WIDTH, WIDTH, MAX); //printf("transaction\tmatrix size: (%d, %d)\n", WIDTH, WIDTH); /////////////// malloc c = (float *)malloc((WIDTH+1)*(WIDTH+1)*sizeof(float)); auto m_c = damemory.allocate("c", WIDTH+1, WIDTH+1, sizeof(float)); cp = (float *)malloc((WIDTH+1)*(WIDTH+1)*sizeof(float)); auto m_cp = damemory.allocate("cp", WIDTH+1, WIDTH+1, sizeof(float)); if (!c || !cp) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", c, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", cp, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", c, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", cp, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &k); //fprintf(ofile, "%p\n", &row); //fprintf(ofile, "%p\n", &column); //fflush(ofile); //fclose(ofile); /////////////// initialization for (row=1; row<=WIDTH; row++) for (i=1; i<=WIDTH; i++) { c[row*WIDTH+i] = c[row*WIDTH+i] / sqrtWIDTH; } for (column=1; column<=WIDTH; column++) for (i=1; i<=WIDTH; i++) { c[i*WIDTH+column] = c[i*WIDTH+column] / sqrtWIDTH; } /////////////// standard wavelet compression of image (Haar basis) MAGIC(3); MAGIC(1); for (row=1; row<=WIDTH; row++) { // for (i=1; i<=WIDTH; i++) // c[row*WIDTH+i] = c[row*WIDTH+i] / sqrt(WIDTH); for (j=WIDTH; j>=2; j/=2) for (k=1; k<=j/2; k++) { cp[row*WIDTH+k] = (c[row*WIDTH+(2*k-1)]+c[row*WIDTH+(2*k)]) / sqrt2; m_c.load(row * WIDTH / (WIDTH + 1), 2 * k - 1); m_c.load(row * WIDTH / (WIDTH + 1), 2 * k); m_cp.write(row * WIDTH / (WIDTH + 1), k); cp[row*WIDTH+(j/2+k)] = (c[row*WIDTH+(2*k-1)] - c[row*WIDTH+(2*k)]) / sqrt2; m_c.load(row * WIDTH / (WIDTH + 1), 2 * k - 1); m_c.load(row * WIDTH / (WIDTH + 1), 2 * k); m_cp.write(row * WIDTH / (WIDTH + 1), j / 2 + k); } } MAGIC(1); MAGIC(3); MAGIC(2); for (column=1; column<=WIDTH; column++) { // for (i=1; i<=WIDTH; i++) // c[i*WIDTH+column] = c[i*WIDTH+column] / sqrt(WIDTH); for (j=WIDTH; j>=2; j/=2) for (k=1; k<=j/2; k++) { cp[k*WIDTH+column] = (c[(2*k-1)*WIDTH+column]+c[(2*k)*WIDTH+column]) / sqrt2; m_c.load((2 * k - 1) * WIDTH / (WIDTH + 1), column); m_c.load((2 * k) * WIDTH / (WIDTH + 1), column); m_cp.write(k * WIDTH / (WIDTH + 1), column); cp[(j/2+k)*WIDTH+column] = (c[(2*k-1)*WIDTH+column] - c[(2*k)*WIDTH+column]) / sqrt2; m_c.load((2 * k - 1) * WIDTH / (WIDTH + 1), column); m_c.load((2 * k) * WIDTH / (WIDTH + 1), column); m_cp.write((j / 2 + k) * WIDTH / (WIDTH + 1), column); } } MAGIC(2); MAGIC(3); /////////////// free free(c); free(cp); damemory.report("wco.csv"); return 0; }
static inline void del_magic_list(ec_list p) { MAGIC(p) = 0; }
int do_extract(const uint8_t *filedata, size_t filesize, const struct extract_options *options, size_t *numfilesptr, size_t *sumsizeptr) { const uint8_t *ptr = NULL, *end = NULL; enum fileformat format = NONE; size_t sumsize = 0; size_t length = 0; int success = 1; int formats = options->formats; char *outfilename = NULL; size_t numfiles = 0; const char *filename = basename(options->filepath); // max. ext length is 16 characters size_t namelen = strlen(options->outdir) + strlen(filename) + 37; struct mpg123_info mpg123; struct ogg_info ogg; struct file_info info = {0, 0}; size_t count = 0; // e.g. for tracks count in midi const uint8_t *audio_start = NULL; size_t input_len = 0; outfilename = malloc(namelen); if (outfilename == NULL) { perror(options->filepath); goto error; } if (!options->quiet) { double slice_size = 0; const char *slice_unit = format_size(filesize, &slice_size); printf("Extracting 0x%08"PRIx64" ... 0x%08"PRIx64" (%g %s) from %s\n", options->offset, options->offset + filesize, slice_size, slice_unit, options->filepath); } #define WRITE_FILE(data, length, ext) \ if (write_file((data), length, options, filename, (size_t)((data) - filedata), (ext), outfilename, namelen)) \ { \ ++ numfiles; \ sumsize += length; \ } ptr = filedata; end = filedata + filesize; for (input_len = filesize; input_len >= 4; input_len = (size_t)(end - ptr)) { uint32_t magic = MAGIC(ptr); if (formats & OGG && magic == OGG_MAGIC && ogg_ispage(ptr, input_len, &ogg)) { uint32_t pageno = ogg.pageno; audio_start = ptr; for (;;) { ptr += ogg.length; if (!ogg_ispage(ptr, (size_t)(end - ptr), &ogg) || ogg.pageno <= pageno) break; pageno = ogg.pageno; } WRITE_FILE(audio_start, ptr - audio_start, "ogg"); continue; } if (formats & RIFF && magic == RIFF_MAGIC && riff_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & AIFF && magic == FORM_MAGIC && aiff_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & MIDI && magic == MIDI_MAGIC && midi_isheader(ptr, input_len, &length, &count)) { audio_start = ptr; do { ptr += length; } while (count-- > 0 && midi_istrack(ptr, (size_t)(end - ptr), &length)); if (count != 0 && !(options->quiet)) { fprintf(stderr, "warning: midi file misses %"PRIzu" tracks\n", count); } WRITE_FILE(audio_start, ptr - audio_start, "mid"); continue; } format = NONE; if (formats & ID3v2 && IS_ID3v2_MAGIC(ptr) && id3v2_istag(ptr, input_len, 0, &length)) { format = ID3v2; } if (formats & MPG123 && IS_MPG123_MAGIC(ptr)) { format = MPG123; length = 0; } if (format & (ID3v2 | MPG123) && mpg123_isframe(ptr + length, input_len - length, &mpg123)) { uint8_t version = mpg123.version; uint8_t layer = mpg123.layer; audio_start = ptr; ptr += length; do { ptr += mpg123.frame_size; } while (mpg123_isframe(ptr, (size_t)(end - ptr), &mpg123) && mpg123.version == version && mpg123.layer == layer); if (id3v1_istag(ptr, (size_t)(end - ptr), &length)) { ptr += length; } if (formats & ID3v2 && id3v2_istag(ptr, (size_t)(end - ptr), 1, &length)) { ptr += length; } WRITE_FILE(audio_start, ptr - audio_start, layer == 1 ? "mp1" : layer == 2 ? "mp2" : layer == 3 ? "mp3" : "mpg"); continue; } if (formats & IT && magic == IT_MAGIC && it_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "it"); ptr += length; continue; } if (formats & XM && magic == XM_MAGIC && xm_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "xm"); ptr += length; continue; } if (formats & ASF && magic == ASF_MAGIC && asf_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "asf"); ptr += length; continue; } if (formats & AU && magic == AU_MAGIC && au_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "au"); ptr += length; continue; } if (formats & PNG && magic == PNG_MAGIC && png_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "png"); ptr += length; continue; } if (formats & GIF && magic == GIF_MAGIC && gif_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "gif"); ptr += length; continue; } if (formats & (MPEG1 | MPEGPS | MPEGVS) && IS_MPEG_MAGIC(magic) && mpeg_isfile(ptr, input_len, formats, &length)) { WRITE_FILE(ptr, length, "mpg"); ptr += length; continue; } if (formats & MPEGTS && IS_MPEG_TS_MAGIC(ptr) && mpeg_isfile(ptr, input_len, formats, &length)) { WRITE_FILE(ptr, length, "mpg"); ptr += length; continue; } if (formats & JPEG && IS_JPG_MAGIC(magic) && jpg_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "jpg"); ptr += length; continue; } if (formats & BINK && IS_BINK_MAGIC(magic) && bink_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "bik"); ptr += length; continue; } if (formats & BMP && IS_BMP_MAGIC(ptr) && bmp_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "bmp"); ptr += length; continue; } if (formats & SMK && IS_SMK_MAGIC(magic) && smk_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "smk"); ptr += length; continue; } if (formats & MP4 && input_len > MP4_HEADER_SIZE && MAGIC(ptr + MP4_MAGIC_OFFSET) == MP4_MAGIC && mp4_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & S3M && input_len > S3M_MAGIC_OFFSET + 4 && MAGIC(ptr + S3M_MAGIC_OFFSET) == S3M_MAGIC && s3m_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "s3m"); ptr += length; continue; } if (formats & MOD && input_len > MOD_MAGIC_OFFSET + 4) { const uint8_t *modmagic = ptr + MOD_MAGIC_OFFSET; if (IS_MOD_MAGIC(modmagic) && mod_isfile(ptr, input_len, &length)) { WRITE_FILE(ptr, length, "mod"); ptr += length; continue; } } if (formats & UTF_32LE && utf32le_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & UTF_32BE && utf32be_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & UTF_16LE && utf16le_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & UTF_16BE && utf16be_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } if (formats & UTF_8 && utf8_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } else if (formats & ASCII && ascii_isfile(ptr, input_len, &info)) { WRITE_FILE(ptr, info.length, info.ext); ptr += info.length; continue; } ++ ptr; } goto cleanup; error: success = 0; cleanup: if (outfilename) free(outfilename); if (numfilesptr) *numfilesptr = numfiles; if (sumsizeptr) *sumsizeptr = sumsize; return success; }
static inline void del_magic_node(ec_list_node p) { MAGIC(p) = 0; }
static int ottery_st_add_seed_impl(struct ottery_state *st, const uint8_t *seed, size_t n, int locking, int check_magic) { #ifndef OTTERY_NO_INIT_CHECK if (check_magic && UNLIKELY(st->magic != MAGIC(st))) { ottery_fatal_error_(OTTERY_ERR_STATE_INIT); return OTTERY_ERR_STATE_INIT; } #endif /* If the user passed NULL, then we should reseed from the operating * system. */ uint8_t *tmp_seed = NULL; size_t tmp_seed_len = 0; uint32_t flags = 0; if (!seed || !n) { int err; tmp_seed_len = ottery_get_entropy_bufsize_(st->prf.state_bytes); tmp_seed = alloca(tmp_seed_len); if (!tmp_seed) return OTTERY_ERR_INIT_STRONG_RNG; n = tmp_seed_len; if ((err = ottery_get_entropy_(&st->entropy_config, &st->entropy_state, 0, tmp_seed, st->prf.state_bytes, &n, &flags))) return err; if (n < st->prf.state_bytes) return OTTERY_ERR_ACCESS_STRONG_RNG; seed = tmp_seed; } if (locking) LOCK(st); /* The algorithm here is really easy. We grab a block of output from the * PRNG, that the first (state_bytes) bytes of that, XOR it with up to * (state_bytes) bytes of our new seed data, and use that to set our new * state. We do this over and over until we have no more seed data to add. */ while (n) { unsigned i; size_t m = n > st->prf.state_bytes/2 ? st->prf.state_bytes/2 : n; ottery_st_nextblock_nolock_norekey(st); for (i = 0; i < m; ++i) { st->buffer[i] ^= seed[i]; } st->prf.setup(st->state, st->buffer); st->block_counter = 0; n -= m; seed += m; } /* Now make sure that st->buffer is set up with the new state. */ ottery_st_nextblock_nolock(st); st->entropy_src_flags |= flags; st->last_entropy_flags = flags; if (locking) UNLOCK(st); /* If we used stack-allocated seed material, wipe it. */ if (tmp_seed) ottery_memclear_(tmp_seed, tmp_seed_len); return 0; }
int main() { int i,j,k; float I; float *a, *L, *U; //FILE *ofile; //printf("&i: %p\t&j: %p\t&k: %p\t&I: %p\n", &i, &j, &k, &I); //printf("&a: %p\t&L: %p\t&U: %p\n", &a, &L, &U); //printf("transaction\tmatrix size: (%d, %d)\tvalue range: (0, %d)\n", WIDTH, WIDTH, MAX); /////////////// malloc a = (float *)malloc(WIDTH*WIDTH*sizeof(float)); L = (float *)malloc(WIDTH*WIDTH*sizeof(float)); U = (float *)malloc(WIDTH*WIDTH*sizeof(float)); if (!a || !L || !U) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", a, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", L, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", U, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", a, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", L, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", U, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &k); //fprintf(ofile, "%p\n", &I); //fprintf(ofile, "%p\n", &a); //fprintf(ofile, "%p\n", &L); //fprintf(ofile, "%p\n", &U); //fflush(ofile); //fclose(ofile); /////////////// initialization srand(time(0)); for(i=1; i<WIDTH; i++) for(j=1;j<WIDTH;j++) a[i*WIDTH+j] = (int)(rand()%(MAX+1)); /* start to the procedure of LU decomposition */ for(i=0; i<WIDTH; i++) for(j=0; j<WIDTH;j++) { L[i*WIDTH+j]=0.0; U[i*WIDTH+j]=0.0; } for(i=1; i<WIDTH; i++) L[i*WIDTH+1]=a[i*WIDTH+1]; for(j=1; j<WIDTH; j++) U[1*WIDTH+j]=a[1*WIDTH+j]/L[1*WIDTH+1]; for(j=2; j<WIDTH; j++) U[j*WIDTH+j]=1.0; /////////////// LU-decomposition kernel MAGIC(3); // for(j=2; j<WIDTH; j++){ for(j=WIDTH/2; j<WIDTH; j++){ for(i=j; i<WIDTH;i++){ MAGIC(2); L[i*WIDTH+j] = a[i*WIDTH+j]; MAGIC(2); for(k=1;k<=j-1;k++) { MAGIC(1); I = L[i*WIDTH+k]; MAGIC(1); MAGIC(2); L[i*WIDTH+j] -= I * U[k*WIDTH+j]; MAGIC(2); } } // MAGIC(1); // U[j*WIDTH+j]=1.0; // MAGIC(1); for(i=j+1;i<WIDTH;i++){ MAGIC(1); U[j*WIDTH+i] = a[j*WIDTH+i]; MAGIC(1); for(k=1; k<=j-1;k++) { MAGIC(2); I = U[k*WIDTH+i]; MAGIC(2); MAGIC(1); U[j*WIDTH+i] -= L[j*WIDTH+k] * I; MAGIC(1); } MAGIC(1); U[j*WIDTH+i] /= L[j*WIDTH+j]; MAGIC(1); } } MAGIC(3); /////////////// print result #ifdef PRINT printf("a\n"); mprint(a); printf("L\n"); mprint(L); printf("U\n"); mprint(U); #endif /////////////// free free(a); free(L); free(U); return 0; }/*End of main() */
int main(int argc, char *argv[]) { // DA memory create const int h_mem = atoi(argv[1]); const int w_mem = atoi(argv[2]); const int h_page = atoi(argv[3]); const int w_page = atoi(argv[4]); const int h_dataset = atoi(argv[5]); const int w_dataset = atoi(argv[6]); WIDTH = atoi(argv[7]); sqrtWIDTH = sqrt(WIDTH); // POLICY = (Arranger_padding | Arranger_concatenating | Arranger_hyperpadding) DAmemory<POLICY, Scheduler_LRU> damemory(h_mem, w_mem, h_page, w_page, h_dataset, w_dataset); int i,j,k; float I; float *a, *L, *U; //FILE *ofile; //printf("&i: %p\t&j: %p\t&k: %p\t&I: %p\n", &i, &j, &k, &I); //printf("&a: %p\t&L: %p\t&U: %p\n", &a, &L, &U); //printf("transaction\tmatrix size: (%d, %d)\tvalue range: (0, %d)\n", WIDTH, WIDTH, MAX); /////////////// malloc a = (float *)malloc(WIDTH*WIDTH*sizeof(float)); auto m_a = damemory.allocate("a", WIDTH, WIDTH, sizeof(float)); L = (float *)malloc(WIDTH*WIDTH*sizeof(float)); auto m_L = damemory.allocate("L", WIDTH, WIDTH, sizeof(float)); U = (float *)malloc(WIDTH*WIDTH*sizeof(float)); auto m_U = damemory.allocate("U", WIDTH, WIDTH, sizeof(float)); if (!a || !L || !U) { printf("malloc failed\n"); exit(1); } //printf("base: %p\tsize: (%d, %d)\n", a, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", L, WIDTH, WIDTH); //printf("base: %p\tsize: (%d, %d)\n", U, WIDTH, WIDTH); /////////////// declare 2d memory //ofile = fopen(PLACEMENT_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", PLACEMENT_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p %d %d\n", a, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", L, WIDTH, WIDTH); //fprintf(ofile, "%p %d %d\n", U, WIDTH, WIDTH); //fflush(ofile); //fclose(ofile); /////////////// declare register variable //ofile = fopen(REGISTER_INFO_FILE, "w"); //if (!ofile) //{ // printf("open file failed: %s\n", REGISTER_INFO_FILE); // exit(1); //} //fprintf(ofile, "%p\n", &i); //fprintf(ofile, "%p\n", &j); //fprintf(ofile, "%p\n", &k); //fprintf(ofile, "%p\n", &I); //fprintf(ofile, "%p\n", &a); //fprintf(ofile, "%p\n", &L); //fprintf(ofile, "%p\n", &U); //fflush(ofile); //fclose(ofile); /////////////// initialization srand(time(0)); for(i=1; i<WIDTH; i++) for(j=1;j<WIDTH;j++) { a[i*WIDTH+j] = (int)(rand()%(MAX+1)); } /* start to the procedure of LU decomposition */ for(i=0; i<WIDTH; i++) for(j=0; j<WIDTH;j++) { L[i*WIDTH+j]=0.0; U[i*WIDTH+j]=0.0; } for(i=1; i<WIDTH; i++) { L[i*WIDTH+1]=a[i*WIDTH+1]; } for(j=1; j<WIDTH; j++) { U[1*WIDTH+j]=a[1*WIDTH+j]/L[1*WIDTH+1]; } for(j=2; j<WIDTH; j++) { U[j*WIDTH+j]=1.0; } /////////////// LU-decomposition kernel MAGIC(3); // for(j=2; j<WIDTH; j++){ for(j=WIDTH/2; j<WIDTH; j++){ for(i=j; i<WIDTH;i++){ MAGIC(2); L[i*WIDTH+j] = a[i*WIDTH+j]; m_a.load(i, j); m_L.write(i, j); MAGIC(2); for(k=1;k<=j-1;k++) { MAGIC(1); I = L[i*WIDTH+k]; m_L.load(i, k); MAGIC(1); MAGIC(2); L[i*WIDTH+j] -= I * U[k*WIDTH+j]; m_U.load(k, j); m_L.write(i, j); MAGIC(2); } } // MAGIC(1); // U[j*WIDTH+j]=1.0; // MAGIC(1); for(i=j+1;i<WIDTH;i++){ MAGIC(1); U[j*WIDTH+i] = a[j*WIDTH+i]; m_a.load(j, i); m_U.write(j, i); MAGIC(1); for(k=1; k<=j-1;k++) { MAGIC(2); I = U[k*WIDTH+i]; m_U.load(k, i); MAGIC(2); MAGIC(1); U[j*WIDTH+i] -= L[j*WIDTH+k] * I; m_L.load(j, k); m_U.write(j, i); MAGIC(1); } MAGIC(1); U[j*WIDTH+i] /= L[j*WIDTH+j]; m_L.load(j, j); m_U.write(j, i); MAGIC(1); } } MAGIC(3); /////////////// print result #ifdef PRINT printf("a\n"); mprint(a); printf("L\n"); mprint(L); printf("U\n"); mprint(U); #endif /////////////// free free(a); free(L); free(U); damemory.report("lu.csv"); return 0; }/*End of main() */