Thread-local storage (TLS) is a programming method that is used to make static and global variables be local to a thread. The '"errno" is a canonical example of TLS method. Actually, a "errno" should be a static variable used by all functions to determine the error status. However, in each thread of a running process, there should be a separated one in order to prevent the infection from other threads in the same process.
The comparing method to achieve the similar function with the TLS is the thread lock for a static or global variable. However, a carelessness of requiring the lock in any threads in the process would affect other threads.
Sunday, 21 October 2012
Saturday, 1 September 2012
Code counting program
For some reasons, I just want to count the number of lines of code which I have already completed locally. There are several methods to achieve this task, such as the Doxygen and the Git tools. They can all produce a rather good report on the program's physical statistics, for example the lines of code. What I was looking for, however, is a lightweight solution which could only count the number of code lines.
SLOCCount is just this kind of tool which is available in the Fedora's package repository. It can also convert the number of code into a financial metric base according to some unknown theory. I am not expect how accurate it would be. It is just quite interesting.
If someone have the similar demands with mine, just have a try on this tool.
SLOCCount is just this kind of tool which is available in the Fedora's package repository. It can also convert the number of code into a financial metric base according to some unknown theory. I am not expect how accurate it would be. It is just quite interesting.
If someone have the similar demands with mine, just have a try on this tool.
Wednesday, 15 August 2012
Deploy Latex writing environment in Fedora 17
At the end of my PhD, a thesis writing with Latex is inevitable. However the Latex is not my primary writing tool during the whole process of my PhD. The Microsoft word seems more easy and intuitive when some small pieces of work are required. In this case, I am going to construct the Latex writing environment before any composing are produced. The last time when I used the Latex for writing was three years ago for the first year long report. It was all accomplished in an apple Mac environment with simple installation process and intuitive user interface. As for this time, I will complete all works in Linux environment. Here I will review how to produce a work using Latex in Linux firstly.
Simple work process:
In order to use the Latex in Fedora, some packages should be installed at the first place. Here is a collection of install packages which are available in Fedora 17 's yum package installation tool:
Using a light-weight text editor to manipulate a latex document is really painful, at least for me. So I found another package available in yum repository:
Simple work process:
- Composing the latex document.
- Compile the latex document: latex <filename.tex>
- Review the dvi file: xdvi <filename.dvi>
- Produce the pdf file: pdflatex <filename.tex>
In order to use the Latex in Fedora, some packages should be installed at the first place. Here is a collection of install packages which are available in Fedora 17 's yum package installation tool:
- texlive: for latex environment.
- texlive-latex: for latex command for front end program.
- xdvik: for dvi viewer.
Using a light-weight text editor to manipulate a latex document is really painful, at least for me. So I found another package available in yum repository:
- texmaker
Monday, 13 August 2012
Dual Monitors on Fedora 17 with Nvidia
I just too excited about my new Nvidia Graphic Card, to take the consideration of Linux driver installation into account. So, here is my updated specification in my little white box:
The problem was shown up when I switched from the i5 integrated Graphic Unit HD4000 to the new external EVGA gtx670 ftw Graphic Card, without changing on my original Operating Systems: Fedora 17 and Windows 7 dual system setting.
On the Windows 7, the EVGA graphic card works fine after installing the card driver software. On the Fedora 17, however, only one display (with smaller resolution) is recognised and the other one (with bigger resolution) is mirrored from that one with the same display resolution. (Sometimes another thing happens. The bigger resolution display is recognised and the smaller resolution display cannot display in that high resolution and then it is totally black.) There is no way to modify display settings like the control panel in Windows to add another display by using the provided display setting GUI tools. In this case, I decide to install the official Nvidia Linux driver to make the new graphic card work in Fedora 17.
Unfortunately, I was failed to install official Nvidia Linux driver. At first, the driver require me to disable the Nouveau driver before the installation of Nvidia driver. After that some other messages are shown on the screen. I cannot remember them. Actually, I didn't know what is really wrong with my installation procedure. But the problem persists after my installation. I assume my installation is unsuccessful at the first place. But I have found some others have already accomplished some work for installing the Nvidia driver in Linux environment.
According to an article on the Internet, the RPM fusion provide the kernel module of the Nvidia driver. This is quite similar with the wireless driver for ASUS's P8Z77-V-Deluxe motherboard which is composed in another my blog. The command used for installing is:
yum install akmod-nvidia xorg-x11-drv-nvidia-libs
By using the akmod package make me not concerned with the kernel update problem. The last step is to disable the Nouveau driver by:
- CPU: i5-3570K
- GPU: EVGA gtx670 ftw
- MEM: 8G 1600Mhz
- Hard_DISK: WD-Black 1T, WD-Blue 500G x 2
- PSU: Corsair AX850
- Motherboard: ASUS P8Z77-V-Deluxe
- Displays: 24" & 19" Samsung
The problem was shown up when I switched from the i5 integrated Graphic Unit HD4000 to the new external EVGA gtx670 ftw Graphic Card, without changing on my original Operating Systems: Fedora 17 and Windows 7 dual system setting.
On the Windows 7, the EVGA graphic card works fine after installing the card driver software. On the Fedora 17, however, only one display (with smaller resolution) is recognised and the other one (with bigger resolution) is mirrored from that one with the same display resolution. (Sometimes another thing happens. The bigger resolution display is recognised and the smaller resolution display cannot display in that high resolution and then it is totally black.) There is no way to modify display settings like the control panel in Windows to add another display by using the provided display setting GUI tools. In this case, I decide to install the official Nvidia Linux driver to make the new graphic card work in Fedora 17.
Unfortunately, I was failed to install official Nvidia Linux driver. At first, the driver require me to disable the Nouveau driver before the installation of Nvidia driver. After that some other messages are shown on the screen. I cannot remember them. Actually, I didn't know what is really wrong with my installation procedure. But the problem persists after my installation. I assume my installation is unsuccessful at the first place. But I have found some others have already accomplished some work for installing the Nvidia driver in Linux environment.
According to an article on the Internet, the RPM fusion provide the kernel module of the Nvidia driver. This is quite similar with the wireless driver for ASUS's P8Z77-V-Deluxe motherboard which is composed in another my blog. The command used for installing is:
yum install akmod-nvidia xorg-x11-drv-nvidia-libs
By using the akmod package make me not concerned with the kernel update problem. The last step is to disable the Nouveau driver by:
## Backup old initramfs nouveau image ## mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r)-nouveau.img ## Create new initramfs image ## dracut /boot/initramfs-$(uname -r).img $(uname -r)
reboot
Tuesday, 26 June 2012
Install MySQL and Development environment in Fedora 17
The installation of MySQL in Fedora is easy and trivial task because the MySQL server package is available in official yum repository. It can be installed both by yum and GUI installer.
The most important task is to configure the MySQL into a usable basic status. Because the Fedora 16/17 introduced another system service manipulating program, "systemctl", which is recommended by Fedora 16/17 in their deployment documentations, the configuration procedure is a little different from the previous Fedora systems that use "service" and "chkconfig" commands. These old programs, however, are still accessible in Fedora 16/17. Here is an example of "systemctl" usage:
Notice that the service name is followed by a word "service".
Enabling a service to start automatically at boot time:
Disabling a service to start at boot time:
Checking the service status:
Running, Stoping and Restarting a service:
After the MySQL service is started and is added to the start queue at boot time, several privilege settings should be done. There are many methods to accomplish this task. I'd like to use the provided program: "mysql_secure_installation". When this step is completed, the password for root is changed, and the anonymous account and test database should be properly set as desired.
In order to access the MySQL from remote machines, do not forget to open the port 3306 for the MySQL server.
More configurations and database set up can be done by using the GUI workbench of MySQL.
The most important task is to configure the MySQL into a usable basic status. Because the Fedora 16/17 introduced another system service manipulating program, "systemctl", which is recommended by Fedora 16/17 in their deployment documentations, the configuration procedure is a little different from the previous Fedora systems that use "service" and "chkconfig" commands. These old programs, however, are still accessible in Fedora 16/17. Here is an example of "systemctl" usage:
systemctl status mysqld.service
Notice that the service name is followed by a word "service".
Enabling a service to start automatically at boot time:
systemctl enable mysqld.service
Disabling a service to start at boot time:
systemctl disable mysqld.service
Checking the service status:
systemctl status mysqld.service
Running, Stoping and Restarting a service:
systemctl [start | stop | restart] mysqld.service
After the MySQL service is started and is added to the start queue at boot time, several privilege settings should be done. There are many methods to accomplish this task. I'd like to use the provided program: "mysql_secure_installation". When this step is completed, the password for root is changed, and the anonymous account and test database should be properly set as desired.
In order to access the MySQL from remote machines, do not forget to open the port 3306 for the MySQL server.
More configurations and database set up can be done by using the GUI workbench of MySQL.
Friday, 22 June 2012
Linux driver for the wifi on P8Z77-V-Deluxe
On Asus P8Z77 motherboard, a powerful wireless network card is provided. It is a dual wireless 802.11 a/b/g/n network card and is more powerful than that is provided by the pro version board, which is a single one with only one antenna without blue tooth. A fabulous set of drivers and utilities is included in the ASUS driver disk for Windows system. However, there is nothing coming with the package even a simple driver to Linux. I cannot found any thing in ASUS website, either.
It is not impossible to drive the wifi on P8Z77 in Linux. I got a box with the latest Fedora 17 32-bit installed. The kernel is 3.4.3 .
I installed a USB wireless card from Cisco Linksys AE1000 on my previous Linux box without too much difficulties. It is not hard to find some articles on the Internet to teach you to install it because the Linux driver is available to the public. The only troublesome task is to identify the correct chipset of the device, which is usually also the most basic and important task to install a device driver in Linux. The AE1000 uses the Ralink's chipset RT3572 according to a website. The Internet is a good tool to save me a lot of time and works to disassemble the network card, which would be a really massive task. Fortunately, the Ralink's official Linux driver is all over the Internet. Downloading, Unpacking and Installing will easily accomplish the task.
My sanguine about the Linux driver of the ASUS wifi go's card keeps until I saw someone's thread saying that the Deluxe version of p8z77 got a wireless network card from broadcom with very limited Linux drivers available on the Internet, especially the official Linux driver. I happened to find an official Linux version driver for broadcom chipset in the official website of the broadcom. However, for some reasons, it cannot be installed correctly because the compilation process is ending with an error message. Fortunately, I found another forum thread representing another method to install this driver.
The chip in the ASUS's board is BCM43228 according to the 'lspci' command in Linux. The only available method to drive this wireless card is to install the official Linux driver which is mentioned above. But, if the RPM fusion is installed in the system, the installation process can be accomplished by a yum installation command, which would be much more reliable. But bear in mind that, the non free repository of RPM fusion should also be installed. The name of package is 'kmod-wl'. However, it cannot be used in my case because I have upgraded my Linux kernel to 3.4.3. The kernel version of both kmod-wl and kmod-wl-PAE require some specific kernel version such as 3.4.2. So I have to use the last one 'akmod-wl', which is kernel version independent. I have successfully installed the driver of the network card by using this method.
In order to find much more information for the wireless network card with broadcom chip installation on Linux you should refer to:
http://forums.fedoraforum.org/showthread.php?t=239922
This guy maintained a very comprehensive article for broadcom chip's Linux installation.
It is not impossible to drive the wifi on P8Z77 in Linux. I got a box with the latest Fedora 17 32-bit installed. The kernel is 3.4.3 .
I installed a USB wireless card from Cisco Linksys AE1000 on my previous Linux box without too much difficulties. It is not hard to find some articles on the Internet to teach you to install it because the Linux driver is available to the public. The only troublesome task is to identify the correct chipset of the device, which is usually also the most basic and important task to install a device driver in Linux. The AE1000 uses the Ralink's chipset RT3572 according to a website. The Internet is a good tool to save me a lot of time and works to disassemble the network card, which would be a really massive task. Fortunately, the Ralink's official Linux driver is all over the Internet. Downloading, Unpacking and Installing will easily accomplish the task.
My sanguine about the Linux driver of the ASUS wifi go's card keeps until I saw someone's thread saying that the Deluxe version of p8z77 got a wireless network card from broadcom with very limited Linux drivers available on the Internet, especially the official Linux driver. I happened to find an official Linux version driver for broadcom chipset in the official website of the broadcom. However, for some reasons, it cannot be installed correctly because the compilation process is ending with an error message. Fortunately, I found another forum thread representing another method to install this driver.
The chip in the ASUS's board is BCM43228 according to the 'lspci' command in Linux. The only available method to drive this wireless card is to install the official Linux driver which is mentioned above. But, if the RPM fusion is installed in the system, the installation process can be accomplished by a yum installation command, which would be much more reliable. But bear in mind that, the non free repository of RPM fusion should also be installed. The name of package is 'kmod-wl'. However, it cannot be used in my case because I have upgraded my Linux kernel to 3.4.3. The kernel version of both kmod-wl and kmod-wl-PAE require some specific kernel version such as 3.4.2. So I have to use the last one 'akmod-wl', which is kernel version independent. I have successfully installed the driver of the network card by using this method.
In order to find much more information for the wireless network card with broadcom chip installation on Linux you should refer to:
http://forums.fedoraforum.org/showthread.php?t=239922
This guy maintained a very comprehensive article for broadcom chip's Linux installation.
Tuesday, 12 June 2012
How to estimate the order of magnitude of Factorial product
The Factorial of a number usually denotes a very big order of magnitude, especially for the computer world. In order to approximate the magnitude of the factorial of a number, it is necessary to find a method to represent the factorial of a number and to keep it into the computer memory. In my example, I am estimating the factorial of 200 which exceeds much more than the capability of any type of C programming language to keep it. An uniform method to represent this big number is important during the estimation. The only way to represent this gigantic big number is by using some smaller numbers that are with in the capability of a C compiler.
My method to represent a number is to use the prime numbers that is smaller that this number. The big number can be factorised into these prime number, so the big number can easily represented the some powers of these prime numbers. For example:
10! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10
= 1 x 2 x 3 x ( 2 x 2 ) x 5 x ( 2 x 3 ) x 7 x ( 2 x 2 x 2 ) x ( 3 x 3 ) x ( 2 x 5 )
= 28 x 34 x 52 x 7
In this case, the factorial of 10 can be represented by these four much smaller prime numbers: 2, 3, 5, 7 with their exponential numbers. Although it is difficult to reproduce the similar procedure for the factorial of 200 by sketching on the paper, the result of the factorial of 200 is not difficult to estimate, because the only difference of the factorial of 200 and that of 10 is the number of prime numbers involved. According to the prime number list referring to the wikipedia page, there are only 47 prime numbers smaller than 200. The factorial of 200 is easily represented by these prime numbers with their exponential numbers. The problem of finding all of the prime numbers smaller than a number is out of discussion of this thread. I will discuss it in more details in another thread.
When we've got the prime-numbers representation of the factorial number, the next task should be concerned is how to estimate its magnitude using this prime_number representation.
As the scientific representation is used to represent a big number, what we concern is the number zeros following the number if the first radix point is placed immediately after the first significant digit, for example, 1.23456 x 1020. The magnitude of this number is ten raised to power of 20. In other words, we are counting the number of zeros when we are talking about the magnitude of a number. The example mentioned above is for decimal number. As for the binary number, zero should still be the digit to be counted, but with different means.
I will give the method for decimal number magnitude estimation, firstly. In order to count the number zero which means a ten (10), we need to make a logarithm to the original number. Using the prime-number representation will make a more convenient way to calculate.
log10(10!) = log10(28 x 34 x 52 x 7)
= log(28) + log10(34) + log10(52) + log10(7)
= 8 x log10(2) + 4 x log10(3) + 2 x log10(5) + log10(7)
These much smaller prime-numbers logarithm is easily to be calculated. Then the number of zeros ( x 10) can be evaluated form this method.
As for a binary number the log2() should be used to calculate the number twos.
My method to represent a number is to use the prime numbers that is smaller that this number. The big number can be factorised into these prime number, so the big number can easily represented the some powers of these prime numbers. For example:
10! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10
= 1 x 2 x 3 x ( 2 x 2 ) x 5 x ( 2 x 3 ) x 7 x ( 2 x 2 x 2 ) x ( 3 x 3 ) x ( 2 x 5 )
= 28 x 34 x 52 x 7
In this case, the factorial of 10 can be represented by these four much smaller prime numbers: 2, 3, 5, 7 with their exponential numbers. Although it is difficult to reproduce the similar procedure for the factorial of 200 by sketching on the paper, the result of the factorial of 200 is not difficult to estimate, because the only difference of the factorial of 200 and that of 10 is the number of prime numbers involved. According to the prime number list referring to the wikipedia page, there are only 47 prime numbers smaller than 200. The factorial of 200 is easily represented by these prime numbers with their exponential numbers. The problem of finding all of the prime numbers smaller than a number is out of discussion of this thread. I will discuss it in more details in another thread.
When we've got the prime-numbers representation of the factorial number, the next task should be concerned is how to estimate its magnitude using this prime_number representation.
As the scientific representation is used to represent a big number, what we concern is the number zeros following the number if the first radix point is placed immediately after the first significant digit, for example, 1.23456 x 1020. The magnitude of this number is ten raised to power of 20. In other words, we are counting the number of zeros when we are talking about the magnitude of a number. The example mentioned above is for decimal number. As for the binary number, zero should still be the digit to be counted, but with different means.
I will give the method for decimal number magnitude estimation, firstly. In order to count the number zero which means a ten (10), we need to make a logarithm to the original number. Using the prime-number representation will make a more convenient way to calculate.
log10(10!) = log10(28 x 34 x 52 x 7)
= log(28) + log10(34) + log10(52) + log10(7)
= 8 x log10(2) + 4 x log10(3) + 2 x log10(5) + log10(7)
These much smaller prime-numbers logarithm is easily to be calculated. Then the number of zeros ( x 10) can be evaluated form this method.
As for a binary number the log2() should be used to calculate the number twos.
Subscribe to:
Posts (Atom)