void testrun_performance_des(void){ uint64_t t; char str[16]; uint8_t key[8], data[8]; calibrateTimer(); print_overhead(); memset(key, 0, 8); memset(data, 0, 8); startTimer(1); des_enc(data, data, key); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tencrypt time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); des_dec(data, data, key); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); uart_putstr_P(PSTR("\r\n")); }
void testrun_performance_rabbit(void){ uint64_t t; char str[16]; uint8_t key[16]; rabbit_ctx_t ctx; calibrateTimer(); print_overhead(); memset(key, 0, 16); startTimer(1); rabbit_init(key, 128, NULL, &ctx); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); startTimer(1); rabbit_gen(&ctx); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tencrypt time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); cli_putstr_P(PSTR("\r\n")); }
void testrun_performance_grain(void) { uint64_t t; char str[16]; uint8_t key[10], iv[8]; grain_ctx_t ctx; calibrateTimer(); print_overhead(); memset(key, 0, 10); memset(iv, 0, 8); startTimer(1); grain_init(key, iv, &ctx); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tctx-gen time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); startTimer(1); grain_enc(&ctx); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tencrypt time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); cli_putstr_P(PSTR("\r\n")); }
void testrun_performance_noekeon(void){ uint64_t t; char str[16]; uint8_t key[16], data[16]; noekeon_ctx_t ctx; calibrateTimer(); print_overhead(); memset(key, 0, 16); memset(data, 0, 16); startTimer(1); noekeon_init(key, &ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); noekeon_enc(data, &ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tencrypt time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); noekeon_dec(data, &ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); uart_putstr_P(PSTR("\r\n")); }
void testrun_performance_entropium(void){ uint64_t t; char str[16]; uint8_t data[32]; calibrateTimer(); print_overhead(); startTimer(1); entropium_addEntropy(128, data); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tadd entropy time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); startTimer(1); entropium_getRandomBlock(data); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tget random time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); cli_putstr_P(PSTR("\r\n")); }
void testrun_performance_shabea(void){ uint64_t t; char str[16]; uint8_t key[32], data[32]; calibrateTimer(); print_overhead(); memset(key, 0, 32); memset(data, 0, 32); startTimer(1); shabea256(data, key, 256, 1, 16); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tencrypt time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); startTimer(1); shabea256(data, key, 256, 0, 16); t = stopTimer(); cli_putstr_P(PSTR("\r\n\tdecrypt time: ")); ultoa((unsigned long)t, str, 10); cli_putstr(str); cli_putstr_P(PSTR("\r\n")); }
void testrun_performance_shacal2enc(void){ uint64_t t; uint8_t key[SHACAL2_KEYSIZE_B], data[SHACAL2_BLOCKSIZE_B]; calibrateTimer(); print_overhead(); memset(key, 0, SHACAL2_KEYSIZE_B); memset(data, 0, SHACAL2_BLOCKSIZE_B); startTimer(1); shacal2_enc(data, key, SHACAL2_KEYSIZE); t = stopTimer(); print_time_P(PSTR("\tencrypt time: "), t); cli_putstr_P(PSTR("\r\n")); }
void testrun_performance_twister512(void){ uint64_t t; char str[16]; uint8_t data[64]; twister_big_ctx_t ctx; calibrateTimer(); print_overhead(); memset(data, 0, 64); startTimer(1); twister_big_init(&ctx, 512); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); twister_big_nextBlock(&ctx, data); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tone-block time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); twister_big_lastBlock(&ctx, data, 0); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tlast block time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); twister_big_ctx2hash(data, &ctx, 512); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tctx2hash time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); uart_putstr_P(PSTR("\r\n")); }
void testrun_performance_sha256(void){ uint64_t t; char str[16]; uint8_t data[32]; sha256_ctx_t ctx; calibrateTimer(); print_overhead(); memset(data, 0, 32); startTimer(1); sha256_init(&ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); sha256_nextBlock(&ctx, data); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tone-block time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); startTimer(1); sha256_lastBlock(&ctx, data, 0); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tlast block time: ")); ultoa((unsigned long)t, str, 10); uart_putstr(str); uart_putstr_P(PSTR("\r\n")); }
int main(int argc, char *argv[]) { int i,j,k; int n; int iterations; FILE *file; double time; double omega; double eps; double temp,err1; int node_id; int nodes; int start; int end; double **send; double **send2; double *data; double *_data; double *g_err; char name[4]; int row_size; d2mce_barrier_t b1; d2mce_mutex_t m1; d2mce_sem_t **sem; nodes = NODES; n = SIZE; eps = EPS; omega = OMEGA; iterations = ITERATIONS; if (argc > 1) { for ( i = 1 ; i < argc ;) { if (strcmp(argv[i],"-s") == 0) { n = atoi(argv[i+1]); n = n; i+=2; } else if (strcmp(argv[i],"-n") == 0) { nodes = atoi(argv[i+1]); i+=2; } else if (strcmp(argv[i],"-i") == 0) { iterations = atoi(argv[i+1]); i+=2; } else { print_usage(); return 0; } } } //init printf("init...\n"); d2mce_init(); node_id = d2mce_join("sor","d2mce_orig", 0); printf("my node id:%d\n", node_id); startend(node_id, nodes, n, &start, &end); start++; printf("start %d end %d\n", start, end); d2mce_mutex_init(&m1,"m1"); d2mce_barrier_init(&b1,"b1"); data = d2mce_malloc("data", sizeof(double)* (n+2) * (n+2)); _data = malloc(sizeof(double)* (n+2) * (n+2)); g_err = d2mce_malloc("g_err", sizeof(double)); send= (double **)malloc(sizeof(double*) * nodes); send2 = (double **)malloc(sizeof(double*) * nodes); sem = (d2mce_sem_t **)malloc(sizeof(d2mce_sem_t*) * nodes); for (i=0;i<nodes;i++) { sem[i] = (d2mce_sem_t*)malloc(sizeof(d2mce_sem_t)); snprintf(name, 3,"b%d", i); d2mce_sem_init(sem[i], name , 0); snprintf(name , 4, "s1%d", i); send[i] = (double*)d2mce_malloc(name, sizeof(double)* (n+3)); snprintf(name , 4, "s2%d", i); send2[i] = (double*)d2mce_malloc(name, sizeof(double)* (n+3)); } //read data if (node_id == 0) { file = fopen("input.data","r"); if (file==NULL) { printf("can't not open the input.data file\n"); return -1; } fread(data, sizeof(double), (n+2)*(n+2), file); fclose(file); *g_err = 0; } else { d2mce_load(g_err); d2mce_load(data); d2mce_sethome(send[node_id]); d2mce_sethome(send2[node_id]); } memcpy(_data, data, sizeof(double)*(n+2)*(n+2)); d2mce_barrier(&b1, nodes); row_size = n+2; //processing printf("d2mce SOR processing...\n"); time = -d2mce_time(); for (k=1; k<iterations; k++) { printf("%d \n",k); err1 = 0.0; //get up node's end dataA if (node_id < (nodes-1)) { d2mce_acq(); for (j=0; j<=(n+1); j++) { send[node_id][j] = _data[end*row_size+j]; } d2mce_store(send[node_id]); d2mce_sem_post(sem[node_id]); } if (node_id > 0) { d2mce_sem_wait(sem[node_id-1]); d2mce_load( send[node_id-1] ); for (j=0; j<=(n+1); j++) { _data[(start-1)*row_size+j] = send[node_id-1][j]; } } //white // i == columnA #ifdef OPENMP #pragma omp parallel for private(temp, j) #endif for (i=start; i<=end; i+=2) { // j == row for (j=1; j<=n; j++) { temp=0.125*( _data[(i-1)*row_size+j]+_data[(i+1)*row_size+j]+_data[i*row_size+j-1]+_data[i*row_size+j+1]+ _data[(i-1)*row_size+j-1]+_data[(i-1)*row_size+j+1]+_data[(i+1)*row_size+j-1]+_data[(i+1)*row_size+j+1] )-_data[i*row_size+j]; _data[i*row_size+j]+=omega*temp; if (temp < 0) temp=-temp; if (temp > err1) err1=temp; } } // d2mce_barrier(&b1, nodes); //get next node's start data if (node_id > 0) { d2mce_acq(); for (j=0; j<=(n+1); j++) { send2[node_id][j] = _data[start*row_size+j]; } d2mce_store(send2[node_id]); d2mce_sem_post(sem[node_id]); } if (node_id < (nodes-1)) { d2mce_sem_wait(sem[node_id+1]); d2mce_load( send2[node_id+1] ); for (j=0; j<=(n+1); j++) { _data[(end+1)*row_size+j] = send2[node_id+1][j]; } } //black #ifdef OPENMP #pragma omp parallel for private(temp, j) #endif for (i=start+1; i<=end; i+=2) { for (j=1; j<=n; j++) { temp=0.125*( _data[(i-1)*row_size+j]+_data[(i+1)*row_size+j]+_data[i*row_size+j-1]+_data[i*row_size+j+1]+ _data[(i-1)*row_size+j-1]+_data[(i-1)*row_size+j+1]+_data[(i+1)*row_size+j-1]+_data[(i+1)*row_size+j+1] )-_data[i*row_size+j]; _data[i*row_size+j]+=omega*temp; if (temp < 0) temp=-temp; if (temp > err1) err1=temp; } } *g_err = 0.0; //get max err1; d2mce_mutex_lock(&m1); d2mce_load(g_err); if (err1 > *g_err) { *g_err = err1; d2mce_store(g_err); } d2mce_mutex_unlock(&m1); d2mce_barrier(&b1, nodes); d2mce_load(g_err); if (*g_err <= eps) break; // d2mce_barrier(&b1, nodes); } // get all data d2mce_mutex_lock(&m1); d2mce_load(data); /* #ifdef OPENMP #pragma omp parallel for private(temp, j) #endif */ for (i = start; i <= end; i++) for (j = 0; j <= (n+1); j++) data[i*row_size+j] = _data[i*row_size+j]; d2mce_store(data); d2mce_mutex_unlock(&m1); d2mce_barrier(&b1, nodes); if (node_id == 0) d2mce_load(data); time+=d2mce_time(); printf("\n====================================================\n"); printf("Result:\n"); printf("\tTIME\tVector_Size\tLoops\tErr\n"); printf("\t%f\t%d\t%d\t%.5e\n", time, n, k, *g_err); file = fopen("d2mce_output.data","w"); if (file == NULL) { printf("can't not open signal_output.data\n"); return -1; } fwrite(data, sizeof(double), (n+2)*(n+2), file); fclose(file); print_overhead(); d2mce_finalize(); return 0; }
int main(int argc, char *argv[]){ int i,j,k; int _vector_size = VECTOR_SIZE; int _iteration = ITERATION; double _initval = INITVAL; int _nodes = NODES; int _column = VECTOR_SIZE+1; int ans_index=0; int change=1; d2mce_mutex_t lock; d2mce_barrier_t b1; int node_id; int *initialized; // int local_index; double computing; double *matrix; double *ans; double *_ans[2]; double time; int comp_size = 0; FILE *file; // processing argument if(argc > 1){ for( i = 1 ; i < argc ;){ if( !strcmp(argv[i], "-s" )){ if(argv[i+1] == NULL){ usage_info(); return 0; } _vector_size = atoi(argv[i+1]); _column = _vector_size + 1; i+=2; } else if( !strcmp(argv[i], "-i")){ if(argv[i+1] == NULL){ usage_info(); return 0; } _iteration = atoi(argv[i+1]); i+=2; } else if( !strcmp(argv[i], "-v")){ if(argv[i+1] == NULL){ usage_info(); return 0; } _initval = atof(argv[i+1]); i+=2; } else if( !strcmp(argv[i], "-n")){ if(argv[i+1] == NULL){ usage_info(); return 0; } _nodes = atoi(argv[i+1]); i+=2; } else{ usage_info(); return 0; } } } comp_size = _vector_size /_nodes; if(_vector_size%_nodes !=0) comp_size++; srand( RANDOM_SEED ); d2mce_init(); node_id = d2mce_join("jacobi", "eps308", 0); printf("my id%d\n", node_id); d2mce_mutex_init(&lock, "lock"); d2mce_barrier_init(&b1, "b1"); // init value initialized = (int*)d2mce_malloc("initialized", sizeof(int)); matrix = (double*) d2mce_malloc("matrix", sizeof(double)* _vector_size * _column ); ans = (double*) d2mce_malloc("ans", sizeof(double)* _vector_size ); //the old ans; // ans[1] = (double*) d2mce_malloc("ans[1]", sizeof(double), _vector_size ); _ans[0] = (double*) malloc(sizeof(double) * _vector_size ); //the new ans; _ans[1] = (double*) malloc(sizeof(double) * _vector_size ); //local index to check the data is dirty if(node_id == 0){ d2mce_mutex_rw(&lock, 3, initialized, "rw", matrix, "rw", ans, "rw"); for( i=0; i < _vector_size; i++){ ans[i] = (double)_initval; _ans[0][i] = (double)_initval; _ans[1][i] = 0.0; for( j=0; j< _column ; j++){ if(i == j) matrix[i*_column + j] = 0; else matrix[i*_column + j] = create_init_value(); } } *initialized = 0; d2mce_mutex_unlock(&lock); } else{ while (! initialized) { d2mce_mutex_rw(&lock, 1,initialized,"r"); d2mce_mutex_unlock(&lock); } d2mce_mutex_rw(&lock, 2, matrix, "r", ans, "r" ); d2mce_mutex_unlock(&lock); for( i=0; i < _vector_size; i++){ _ans[0][i] = ans[i]; _ans[1][i] = 0.0; } } if(_nodes >1) d2mce_barrier(&b1, _nodes); /* for( i=0; i < _vector_size; i++){ for( j=0; j< _column ; j++){ printf("%f ", matrix[i*_column + j]); } printf("\n"); } printf("\n\n"); for( j=0; j< _column ; j++){ printf("%f ", ans[j]); } printf("\n\n"); for( j=0; j< _column ; j++){ printf("%f ", _ans[0][j]); } printf("\n\n"); for( j=0; j< _column ; j++){ printf("%f ", _ans[1][j]); } printf("\n\n"); */ /* ans[0][0]=-1.5; ans[0][1]=2.5; ans[0][2]=-0.5; matrix[0]=-0; matrix[1]=-0.125; matrix[2]=0.25; matrix[3]=-(double)11/8; matrix[_column]=-(double)2/9; matrix[_column+1]=0; matrix[_column+2]=-(double)1/9; matrix[_column+3]=(double)22/9; matrix[2*_column]=(double)1/11; matrix[2*_column+1]=(double)2/11; matrix[2*_column+2]=0; matrix[2*_column+3]=-(double)15/11; */ /* * jacobi method computing */ time = -d2mce_time(); for( i=0; i<_iteration; i++){ for( j=node_id*comp_size; j<(node_id*comp_size+comp_size) && j<_vector_size; j++){ computing =0; for( k=0; k<_vector_size; k++){ if(j!=k) computing += matrix[j*_column + k]*_ans[ans_index][k]; } computing += matrix[j*_column + _vector_size]; _ans[ans_index + change][j] = computing; } ans_index += change; change = -change; // d2mce_barrier(&b1, _nodes); d2mce_mutex_rw(&lock, 1, ans, "rw"); for( j=node_id*comp_size; j<(node_id*comp_size+comp_size) && j<_vector_size; j++){ ans[j] = _ans[ans_index][j]; } d2mce_mutex_unlock(&lock); d2mce_barrier(&b1, _nodes); d2mce_load(ans); if( i != _iteration){ #ifdef OPENMP #pragma omp parallel for #endif for( j=0; j<_vector_size; j++){ _ans[ans_index][j] = ans[j]; } } } time += d2mce_time(); /* * print the result information */ /* printf("the ans:\n"); for( i=0; i < _vector_size; i++){ printf("%f ", ans[i]); } printf("\n"); */ printf("Result:\n"); printf("\tTIME\tVector_Size\n"); printf("\t%f\t%d\n", time, _vector_size); file = fopen("d2mce_output.data","w"); fwrite(ans, sizeof(double), _vector_size, file); fclose(file); print_overhead(); d2mce_finalize(); free(_ans[0]); free(_ans[1]); return 0; }
int main(int argc, char *argv[]) { int i,j,k; int n; int *data; int *_data; int *tmp; FILE *file; double time; int node_id; int nodes; int block_size; int root; d2mce_barrier_t b1; d2mce_mutex_t m1; n=SIZE; nodes = NODES; if (argc > 1) { for ( i = 1 ; i < argc ;) { if (strcmp(argv[i],"-s") == 0) { n = atoi(argv[i+1]); i+=2; } else if (strcmp(argv[i],"-n") == 0) { nodes = atoi(argv[i+1]); i+=2; } else { print_usage(); return 0; } } } block_size = n / nodes; if (n % nodes !=0) { printf("size error\n"); return -1; } printf("init...\n"); d2mce_init(); node_id = d2mce_join("asp","d2mce_orig", 0); printf("my node id:%d\n", node_id); d2mce_mutex_init(&m1,"m1"); d2mce_barrier_init(&b1,"b1"); data = d2mce_malloc("data", sizeof(int)* n * n); tmp = d2mce_malloc("tmp", sizeof(int)*n); _data = malloc(sizeof(int)*n*n); //read data if (node_id == 0) { file = fopen("input.data","r"); if (file==NULL) { printf("can't not open the input.data file\n"); return -1; } fread(data, sizeof(int), n*n, file); fclose(file); } else { d2mce_load(data); } //memcpy(_data, data, sizeof(int)*n*n); d2mce_barrier(&b1, nodes); //processing printf("d2mce ASP processing...\n"); time = -d2mce_time(); for (k = 0; k < n; k++) { root = k/block_size; if(node_id == root){ for(j=0;j<n;j++) tmp[j] = data[k*n+j]; d2mce_acq(); d2mce_store(tmp); d2mce_barrier(&b1, nodes); }else{ d2mce_barrier(&b1, nodes); d2mce_load(tmp); } #ifdef OPENMP #pragma omp parallel for private(j) #endif for (i = node_id * block_size; i < node_id *block_size + block_size; i++){ for (j = 0; j < n; j++) { if (data[i*n+j] > (data[i*n+k] + tmp[j])) data[i*n+j] = data[i*n+k] + tmp[j]; } } d2mce_barrier(&b1, nodes); } //gather /* d2mce_mutex_lock(&m1); d2mce_load(data); #ifdef OPENMP #pragma omp parallel for private(j) #endif for (i = node_id * block_size; i < node_id *block_size + block_size; i++) for (j = 0; j < n; j++) data[i*n+j] = _data[i*n+j]; d2mce_store(data); d2mce_mutex_unlock(&m1); */ d2mce_mstore(data, node_id * block_size * n * sizeof(int), block_size * n * sizeof(int)); d2mce_barrier(&b1, nodes); if(node_id == 0) d2mce_load(data); time+=d2mce_time(); printf("Result:\n"); printf("\tTIME\tVector_Size\n"); printf("\t%f\t%d\n", time, n); if(node_id == 0){ file = fopen("d2mce_output.data","w"); fwrite(data, sizeof(int), n*n, file); fclose(file); } print_overhead(); d2mce_finalize(); free(_data); return 0; }
void bcal_performance(const bcdesc_t* bcd){ bcdesc_t bc; memcpy_P(&bc, bcd, sizeof(bcdesc_t)); uint8_t ctx[bc.ctxsize_B]; uint8_t data[(bc.blocksize_b+7)/8]; uint16_t keysize = get_keysize(bc.valid_keysize_desc); uint8_t key[(keysize+7)/8]; uint64_t t; uint8_t i; if(bc.type!=BCDESC_TYPE_BLOCKCIPHER) return; calibrateTimer(); print_overhead(); cli_putstr_P(PSTR("\r\n\r\n === ")); cli_putstr_P(bc.name); cli_putstr_P(PSTR(" performance === " "\r\n type: blockcipher" "\r\n keysize (bits): ")); printvalue(keysize); cli_putstr_P(PSTR("\r\n ctxsize (bytes): ")); printvalue(bc.ctxsize_B); cli_putstr_P(PSTR("\r\n blocksize (bits): ")); printvalue(bc.blocksize_b); t=0; if(bc.init.init1){ if((bc.flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){ for(i=0; i<32; ++i){ startTimer(0); START_TIMER; (bc.init.init1)(key, &ctx); STOP_TIMER; t += stopTimer(); if(i!=31 && bc.free){ bc.free(&ctx); } } } else { for(i=0; i<32; ++i){ startTimer(0); START_TIMER; (bc.init.init2)(key, keysize, &ctx); STOP_TIMER; t += stopTimer(); if(i!=31 && bc.free){ bc.free(&ctx); } } } t>>=5; cli_putstr_P(PSTR("\r\n init (cycles): ")); printvalue(t); } t=0; for(i=0; i<32; ++i){ startTimer(0); START_TIMER; bc.enc.enc1(data, &ctx); STOP_TIMER; t += stopTimer(); } t>>=5; cli_putstr_P(PSTR("\r\n encrypt (cycles): ")); printvalue(t); t=0; for(i=0; i<32; ++i){ startTimer(0); START_TIMER; bc.dec.dec1(data, &ctx); STOP_TIMER; t += stopTimer(); } t>>=5; cli_putstr_P(PSTR("\r\n decrypt (cycles): ")); printvalue(t); if(bc.free){ bc.free(&ctx); } }