How to benchmark a C++ code

As the last step of software development you should test the performance of your code. This is a simple example how to benchmark the time consumption of different procedures in a C or C++ code. We will compare two procedures: calculating sinus and exponential values for 5e7 numbers. Let write a code with name test.cpp

#include
#define LIMIT 50000000
void exponential(){
double a;
for(int i=1; i != LIMIT; i++)
a=exp(i/1000.0);
}
void sinus(){
double a;
for(int i=1; i != LIMIT; i++
)
a=sin(i/1000.0);
}
int main(){
exponential();
sinus();
return 0;
}

and
compile by g++:

g++ -pg test.cpp -o test.out
After running the ./test.out file a new file gmon.out will appear in your working directory. This file contains the profile information of your code. This information can be read by running the command
gprof test.out

which will tell us:

Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
51.66 1.17 1.17 1 1.17 1.17 sinus()
48.99 2.27 1.11 1 1.11 1.11 exponential()

that our program 51.6% of time spent for calculation of
sinus() procedure and 48.99% for exponential().

How to Periodically remove temporary files in Linux

To remove periodically some files from a specific directory you can easily setup a cron entry. Execute in shell

crontab -e

and add

*/60 * * * * find /home/my_home/some_dir/ -name '*.dat' -mmin +60 -exec rm {} \;

where .dat is the suffix of the files and "-mmin +60 -exec rm {}" is the option telling to remove the files with data modified more than 60 minutes ago.

If your crontab uses Vim for editing use :wq to save you changes and "INSERT", "ESC" to switch between Insert and Normal mode.

How to Encrypt directories using EncFS

  1. Install EncFS:

    sudo apt-get install encfs

  2. EncFS uses the fuse kernel extension, which we need to load into the kernel

    sudo sh -c "echo fuse >> /etc/modules"
    sudo modprobe fuse

  3. Add yourself into the fuse group

    sudo addgroup my_login_name fuse

  4. Log out and log in.
  5. Create your encrypted directory:

    cd ~
    mkdir .encrypt
    mkdir encrypt
    encfs $HOME/.encrypt $HOME/encrypt

    Press enter few times, and chose a password.
    Voala! The encrypted data will be stored in ~/.encrypt directory and it will be readable/writable trough the ~/encrypt directory. We used the $HOME parameter because encfs requires a full path to the directories. The password can be changed anytime using the encfsctl command.

How to change MAC address of your WIFI or Ethernet card

Open a terminal window and type the following command



sudo ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx


replace xx:xx:xx:xx:xx:xx with the MAC address that you want to change to

How to Setup Transparent Squid Proxy Server in Ubuntu

This is a short guide how to set up a transparent cache proxy on Ubuntu Server. Basically, there are two reasons why you may be interested setting up a Squid proxy: speed up your web access and save your bandwidth. Let assume that you already set up a Linux gateway using iptables. It is possible to run squid also on Windows but unfortunately it is extremely hard to find a hardware on which Windows is able to survive more than one week. Other words, windows is out of scope of this article.
The first step is to install squid 3

apt-get install squid3

edit the squid 3 configuration file in your favorite editor

sudo vi /etc/squid3/squid.conf

and set the transparency and the allowed hosts

http_port 3128 transparent
acl our_networks src 192.168.0.0/24
acl localnet src 127.0.0.1/255.255.255.255
http_access allow our_networks
http_access allow localnet

where 192.168.0.0/24 is the IP range of local network. Probably you need adjust the swap size

cache_dir ufs /var/spool/squid3 7000 16 256

where the first number denotes the size of cache in megabytes. Save you changes and restart the squid proxy by

sudo /etc/init.d/squid3 restart

For more detailed configuration read the manual of Squid or check the configuration examples on Squid wiki page.
Remember, the memory and processor usage of squid is a function of swap size.
Last but not the least we need to redirect the HTTP traffic to your new shiny proxy

iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.0.1:3128
iptables -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128

where eth1, eth0 are the LAN, WAN devices and 192.168.0.1 is the IP address of your LAN device.

After all, probably you feel the need to monitor the performance of your proxy. Unfortunately, most of the squid log parsers in the Ubuntu repository are configured for Squid 2.x. Nevertheless, squid 3 uses the same log format, so you can change the log file path in your parser config file (sarg, calamaris, etd.) or simply link the log directory of squid 3 to the correct path

ln -s /var/log/squid3 /var/log/squid

How to convert CHM to PDF in LInux

1. Install dependencies by running in the Terminal:
sudo apt-get install htmldoc libchm-bin python-chm
2. Download chm2pdf by clicking this.
3. Now extract the downloaded file.
4. Open your Terminal and browse to the folder you extracted and run:
sudo python setup.py install
5. You’re done!

Now to use it is very simple:
In Terminal, type:
chm2pdf --book filename.chm
# (Where filename is obviously your required file to be converted.)

Google To Switch To EXT4

Google is in the process of migrating their EXT2 file-systems over to the modern EXT4 file-system. This was brought up in a JFS benchmarking discussion. Google's Michael Rubin shared that they chose EXT4 after benchmarking it as well as XFS and JFS. Their results showed EXT4 and XFS performing close to one another, but with it being easier to upgrade from EXT2 to EXT4 rather than EXT2 to XFS, they went with the easier path. Btrfs is still too experimental for Google to even consider that an option at this point.

How to disable KVM in running kernel to solve errors while running VirtualBox

Issue this following commands as root or with sudo permission

rmmod kvm_intel
rmmod kvm


after that run VirtualBox

To solve the problem permenantly add these commands to scripts that will be executed when system starts like /etc/rc.local

40,000 processors and 104 TB of RAM Assembled to Render Avatar

As the special-effects-driven blockbuster AVATAR stuns audiences with its lush computer-animated fantasy scenes, a data center in Wellington, New Zealand, has played a backstage, but vitally crucial role.

New Zealand-based visual effects company Weta Digital (www.wetafx.co.nz) was able to manage the intense streams of data required to render the cutting-edge 3D animation used in movies like I, Robot, and X-Men: The Last Stand, and it latest, AVATAR, has been perhaps the most challenging yet, according to a report from trade journal Information Management.

The company uses all non-windows software to achieve all these cutting edge graphics. The systems used to render these graphics were all using RHEL as their OS and were all HP Blade server clusters. All these systems are 64 bit and the cluster at Weta Digital is one of the world’s largest linux clusters. It is ranked #193 amongst the top 500 supercomputers of the world with processing capabilities of 10 Gigaflops.

It is great to know that most of the software used to render these graphics were all Linux software like SoftImage, CompTime, Cine-Paint etc.
While James Cameron's directing and fine performances by Sam Worthington, Zoe Saldana and others help, the immersive experience of AVATAR comes from the many hours or days of attention to each of about 240,000 frames that go into the final product, each requiring 12 megabytes per frame.

Weta operates a 10,000-square-foot facility that uses HP BL2x220c blades to process the effects for AVATAR and other films. The computing core contains some 40,000 processors and 104 terabytes of RAM.

The heat generated is dissipated using enclosed, water cooled racks, Weta data center systems administrator Paul Gunn told Information Management. Hot air is sucked into a radiator and cycled back through the front of the machines. "[W]e run the machines a bit warm, which modern gear doesn't mind, and the room itself is fairly cool," Gunn said, noting that they save tens of thousands of dollars changing the temperature by as little as a degree.


Related Post : Hollywood Movies which used Linux for  graphic Rendering

[ ubuntu ] Quick and Dirty method to remove a corruted partially installed package

This method can be used when  commands related to aptitude or dpkg is not able to solve the problem


If you have tried everything else, a last resort is this.

1. Backup your /var/lib/dpkg/status file NB You MUST do this first, becuase if you lose this file, your system is hosed.

2. In a terminal, type in the following command: sudo gedit /var/lib/dpkg/status

3. The errant package seems to ardour, is this correct? If so, do a search for it in the opened file.

4. When you have located it, CAREFULLY delete all references to it.

5. Save the file and re-boot.

Hopefully, all should go well, as Synaptic is no longer aware of this package and although it hasn't actually been deleted, over time, it will be over-written.

Credits : Roger

http://ubuntuforums.org/showthread.php?t=455541

How to enable file and folder listing in apache

Option # 1: Using Apache config file

Add directory option to Apache configuration file /etc/httpd/httpd.conf or /etc/apache2/apache2.conf:
# vi /etc/apache2/apache2.conf

Add following code:

Options Indexes FollowSymLinks

Save and close the file. Restart Apache:
# /etc/init.d/httpd restart

OR
# /etc/init.d/apache2 restart

Option #2: Using .htaccess Files with Apache

You can place config line Options Indexes in .htaccess file. Make sure .htaccess file support is enabled.
Change directory to pdfs
$ cd pdfs

Open .htaccess file
$ vi .htaccess

Append following apache directive:
Options Indexes

Save and close the file.