1 /***************************************************************************
2  *  tools/extras/pq_param.cpp
3  *
4  *  Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  *  Copyright (C) 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
7  *
8  *  Distributed under the Boost Software License, Version 1.0.
9  *  (See accompanying file LICENSE_1_0.txt or copy at
10  *  http://www.boost.org/LICENSE_1_0.txt)
11  **************************************************************************/
12 
13 #include <iostream>
14 #include <cmath>
15 #include <stxxl/types>
16 
17 typedef stxxl::int64 int64;
18 
D(int64 m,int64 k,int64 MaxS,int64 E,int64 B)19 int64 D(int64 m, int64 k, int64 MaxS, int64 E, int64 B)
20 {
21     return (m * m / 4 - (MaxS * E / (k - m)) / B);
22 }
23 
24 using std::cout;
25 using std::endl;
26 
main()27 int main()
28 {
29     int64 IntM = 128 * 1024 * 1024;
30     int64 E = 4;
31     int64 B = 8 * 1024 * 1024;
32     //int64 Bstep = 128 * 1024;
33     int64 MaxS = (int64(128) * int64(1024 * 1024 * 1024)) / E;
34 
35     for ( ; B > 4096; B = B / 2)
36     {
37         int64 m = 1;
38         int64 k = IntM / B;
39         for ( ; m < k; ++m)
40         {
41             int64 c = (k - m);
42             //if( D(m,k,MaxS,E,B)>= 0 && c > 10)
43             if ((k - m) * m * m * B / (E * 4) >= MaxS)
44             {
45                 cout << (k - m) * (m) * (m * B / (E * 4)) << endl;
46                 cout << MaxS << endl;
47                 cout << "D: " << D(m, k, MaxS, E, B) << endl;
48                 cout << "B: " << B << endl;
49                 cout << "c: " << c << endl;
50                 cout << "k: " << k << endl;
51                 int64 Ae = m / 2;
52                 int64 Ae1 = Ae + int64(sqrt((double)D(m, k, MaxS, E, B)));
53                 int64 Ae2 = Ae - int64(sqrt((double)D(m, k, MaxS, E, B)));
54                 int64 x = c * B / E;
55                 int64 N = x / 4096;
56                 cout << "Ae : " << Ae << endl;
57                 cout << "Ae1: " << Ae1 << endl;
58                 cout << "Ae2: " << Ae2 << endl;
59                 cout << "minAe :" << (MaxS / (x * Ae)) << endl;
60                 cout << "x  : " << x << endl;
61                 cout << "N  : " << N << endl;
62                 int64 Cons = x * E + B * (m / 2) + MaxS * B / (x * (m / 2));
63                 cout << "COns : " << Cons << endl;
64                 return 0;
65             }
66         }
67     }
68 
69     cout << "No valid parameter found" << endl;
70 }
71