Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits/stdc++.h>
- using namespace std;
- double thresh = 256; // 2^8
- int vectorSize = 8;
- int lo = 0;
- int hi = 100000; // 10^5 for now
- double vectorCost = 1.5;
- double spawnCost = 10;
- double serialCost = 1;
- double DAC_Cost(double n){
- double tmp= n / thresh;
- int h =(int) (ceil(log2(tmp))); // Height of DAC tree
- int total_leaves = 1 << h;
- int k = (int)(n / total_leaves); // Size of smallest leaf
- int y = n - k * total_leaves;
- int x = total_leaves - y;
- int total_spawns = total_leaves - 1;
- int total_vectors_instr = (k/vectorSize)*x + ((k+1)/vectorSize)*y;
- int total_serial_instr = (k % vectorSize)* x + ((k+1)%vectorSize)*y;
- double costEstimate = total_spawns * spawnCost + total_vectors_instr * vectorCost + total_serial_instr * serialCost;
- printf("x : %d y: %d height:%d small leaf size:%d n: %lf \n", x, y,h,k,n);
- return costEstimate;
- }
- double LIE_Cost(int n){
- int a[35];
- int msb = 0;
- int cur_n = n;
- while( cur_n > 0){
- a[msb] = cur_n%2;
- cur_n = cur_n /2;
- msb++;
- }
- msb--;
- int total_leaves = 1; // for last leaf
- int total_vectors_instr = 0;
- int total_serial_instr = 0;
- cur_n = n;
- int i = msb;
- while(cur_n >= thresh){
- if (a[i] == 1){
- int rootSize = 1 << i;
- cur_n = cur_n - rootSize;
- int leafSize = thresh;
- int leafNo = rootSize/thresh;
- total_leaves += leafNo;
- total_vectors_instr += ((thresh/vectorSize)*leafNo);
- }
- i--;
- }
- total_vectors_instr += (cur_n/vectorSize);
- total_serial_instr += (cur_n%vectorSize);
- int total_spawns = total_leaves - 1;
- double costEstimate = total_spawns * spawnCost + total_vectors_instr * vectorCost + total_serial_instr * serialCost;
- return costEstimate;
- }
- int main() {
- double cst1 = DAC_Cost(1100*1.0);
- double cst2 = LIE_Cost(1100);
- cout<< cst1 << " " <<cst2;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement