File: sparsity.sh

package info (click to toggle)
cppad 2026.00.00.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,584 kB
  • sloc: cpp: 112,960; sh: 6,146; ansic: 179; python: 71; sed: 12; makefile: 10
file content (83 lines) | stat: -rwxr-xr-x 2,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /bin/bash -e
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
# SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
# SPDX-FileContributor: 2003-22 Bradley M. Bell
# ----------------------------------------------------------------------------
gigabytes='1.0'   # memory limit in gigabytes
# -----------------------------------------------------------------------------
kilobytes=`echo "($gigabytes * 10^9) / 1024" | bc`
ulimit -Sv $kilobytes
cat << EOF
This is testing the idea that
   vector< std::set<size_t> > sparsity;
is inefficient compared to
   vector<size_t> row, col;
The results on one system for this script are:
   ./sparsity set 1e7 elapsed_seconds = 3.62206
   ./sparsity set 2e7 std::bad_alloc
   ./sparsity vec 2e7 elapsed_seconds = 1.34243
   ./sparsity vec 4e7 std::bad_alloc
EOF
cat << EOF > bug.$$
# include <cppad/cppad.hpp>

int main(int argc, char *argv[])
{  using CppAD::elapsed_seconds;
   if( argc != 3 )
   {  std::cerr << "usage: $0 (set|vec) n" << std::endl;
      return 1;
   }
   bool set  = std::strcmp(argv[1], "set") == 0;
   bool vec  = std::strcmp(argv[1], "vec") == 0;
   bool ok   = vec || set;
   if( ! ok )
   {  std::cerr << "usage: $0 (set|vec) n" << std::endl;
      return 1;
   }
   size_t n = size_t( std::atof( argv[2] ) );
   const char* label;
   elapsed_seconds();
   try
   {
      if( set )
      {  std::vector< std::set<size_t> > my_set(n);
         for(size_t i = 0; i < n; i++)
            my_set[i].insert(i);
      }
      else
      {  std::vector<size_t> row;
         std::vector<size_t> col;
         for(size_t i = 0; i < n; i++)
         {  row.push_back(i);
            col.push_back(i);
         }
      }
      for(int i = 0; i < argc; i++)
         std::cout << argv[i] << " ";
      std::cout << "elapsed_seconds = " << elapsed_seconds() << std::endl;
   }
   catch( std::bad_alloc& bad )
   {
      for(int i = 0; i < argc; i++)
         std::cout << argv[i] << " ";
      std::cout << bad.what() << std::endl;
   }
   return 0;
}
EOF
# -----------------------------------------------------------------------------
if [ ! -e build ]
then
   mkdir build
fi
cd build
echo "$0"
name=`echo $0 | sed -e 's|.*/||' -e 's|\..*||'`
mv ../bug.$$ $name.cpp
echo "g++ -I../.. -DNDEBUG --std=c++11 $name.cpp -o $name"
g++ -I../.. -DNDEBUG --std=c++11 $name.cpp -o $name
#
./$name set 1e7
./$name set 2e7
./$name vec 2e7
./$name vec 4e7