5th International Conference on Advanced Technology & Sciences (ICAT'17)
May 09-12, Istanbul /TURKEY
___________________________________________________________________________________________________________
of them are located in city centres, some are found at the locations where there is a lot of air pollution. Different parameters (PM10, SO2, NO2, NO, CO etc.), determining the air pollution, are measured at these stations according to stations’ specifications. AQS in Adıyaman measures only PM10 and SO2 air pollutant parameters hourly. These parameter values are hourly published from ministry web site but there aren’t any mobile device applications for monitoring these parameters. Moreover, to make this need we decided to develop a web and mobile based application monitoring air quality parameters. Firstly, we have developed this application as a web site. Then this application has been converted for use in mobile device. Because there aren’t any web services for getting these parameters, we have developed a parser in PHP monitoring these parameters and air quality index (AQI). CURL tool in PHP have been employed for parsing these parameters. CURL tool has many procedures and function for transferring data among servers to realize this application. In the next section, we described Air Quality Index, Particular Matter 10 (PM10) and Sulfur dioxide (SO2) pollutant parameters, PHP, CURL tool and Android Applications. In third section we discussed the results of the study. And the last section, study is concluded with some proposal goals in the next. II. MATERIALS AND METHODS In this section, the methods which we employed in our study are described.
A. Air Quality Index(AQI) Air quality index (AQI) is a numerical scale used for reporting day to day air quality with regard to human health and the environment. The daily results of the index are used to convey to the public an estimate of air pollution level. The higher the AQI value the greater the level of air pollution and the greater the health concern. Each category corresponds to a different level of health concern. Below is an explanation of the categories and their meanings.0 – 50 indicates “Good” AQI. At this level the quality of air is deemed to be satisfactory, and air pollution poses little or no risk. 51 – 100 indicate “Medium” AQI. This means acceptable Air quality. However, some pollutants might arouse modest health concern for a limited number of people. For instance, persons who are remarkably sensitive to ozone may experience respiratory symptoms. 101 – 150 indicate “Sensitive” AQI. This category may not be able to affect the general health of the public. However, children, older adults, and persons with lung disease are at a greater risk from ozone exposure. Older children, adults and people with lung and heart disease are at greater risk from exposure to particulate matter. 151 – 200 indicate “Unhealthy” AQI. In this category, every person might experience some adverse health effects. Sensitive group members may experience more serious effects. People with heart or lung disease, older adults and children should cut back or reschedule strenuous activities. 201 – 300 indicate “Bad” AQI. This would issue a health alert to mean that everybody may experience very serious health
implications[2,3,5,6]. People with heart or lung disease, older adults and children should significantly cut back or reschedule strenuous activities. Greater than 300 indicate “Dangerous” AQI. Air quality at this level is life-threatening and would issue warnings of emergency conditions for the entire population. TABLE I NATIONAL AIR QUALITY INDEX CUTTING POINTS Index
Good
AQI
0-50
51-100
101-150
0-100
101-250
0-100
101-200
SO2 [µg/m³] NO2 [µg/m³] CO [µg/m³] O3 [µg/m³] PM10 [µg/m³]
Medium Sensitive Unhealthy
0-5500 5501-10000
Bad
Dangerous
151-200
201-300
301-500
251-500
501-800
851-1100
>1101
201-500
501-1000 1001-2000
>2001
100116000
1600124000
2400132000
>32001
0-120
121-160
161-180
181-240
241-700
>701
0-50
51-100
101-260
261-400
401-520
>521
B. Particulate Matter(PM10) and SO2 Particulate matter, also known as particle pollution or PM, is a term that describes extremely small solid particles and liquid droplets suspended in air. The PM10 standard limits the mass concentration of airborne particles whose aerodynamic diameter is less than 10 micrometres. There are many health effects from exposure to particulate matter. Numerous studies have showed associations between exposure to particles and increased hospital admissions as well as death from heart or lung diseases[2,3,5,6]. Sulfur dioxide is a primary pollutant. It may deposit to the earth’s surface either as a gaseous molecule or dissolved in rain droplets. The more important fate, however, is atmospheric oxidation to sulphuric acid and subsequent deposition. The oxidation process has a time scale of several days and may occur either in the gas phase or in liquid water droplets. SO2 is respiratory irritant that can have adverse effects on breathing, contribute to respiratory illness, alter the defense mechanisms of the lungs, and aggravate existing pulmonary and cardiovascular disease. Sulfur dioxide can also damage crops and trees[2,3,5,6].
C. Air Quality Monitoring Stations The Air Quality Monitoring Stations were installed under the control of the Republic of Turkey’s Ministry of Environment and Forest to measure and publish air quality and air pollution values in terms of predefined air pollutants in Turkey. Air quality observation stations monitor global changes in the atmosphere as well as pollutants from domestic sources and neighbouring countries. These pollutants come as gases and trace elements, in rainwater and as airborne particulates. Particulates also include dust from natural sources. Two control parameter air pollutants (Sulfur dioxide (SO2) and particulate matter (PM10)) are commonly monitored at the stations connected to the system network. In addition to these two criteria pollutants, some other pollutants have also been monitored at a very limited number of the stations.
323
5th International Conference on Advanced Technology & Sciences (ICAT'17)
May 09-12, Istanbul /TURKEY
___________________________________________________________________________________________________________
D. PHP and Curl PHP scripting language was developed by Rasmus Lerdorf in 1994 and PHP was re-coded by Andi Gutmans, Zeev Suraski and Lerdorf as PHP3 in 1997[9]. PHP is a scripting language. Namely, codes in PHP are written in plain text and recorded in this format. Moreover, today PHP is most widely used all over the world as server side scripting language. PHP codes are written in HTML codes with its special brackets. A sample code is given in the following. Fig. 1 A sample codes for PHP scripting language
CURL (Client URL library function) provides too many different types of servers communicate each other using PHP supports libcurl, a library created by Daniel Stenberg, that allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading HTTP form based upload, proxies, cookies, and user+password authentication. In order to use PHP's cURL functions there is need to install the libcurl package[10]. A basic CURL example in PHP is given in the following. Fig. 2 A sample codes belonging to CURL in PHP
SDK provides software engineer some utilities such as debugger, software libraries and emulator. Android is especially developed for 32-bit ARMv7 processors. Furthermore, the Android x-86 project supports x86 processors. The requirements for Android 5.1 are as follows: 512 MB RAM, 32-bit ARMv7, MIPS or x86 architecture processor, a GPU is compatible with OpenGL ES 2.0. 64-bit support for x86, ARM and MIPS platforms is also available with the Android 5.x Lollipop release. Because each manufacturer product a ROM containing its own Android variant, updates may not be appropriate for every model of Android operating system at the same time. III. RESULTS AND DISCUSSIONS Air pollution parameters are hourly recorded by the Environment and Urban Ministry and published on this institutions site for each province. There are no mobile applications showing these parameters yet. We wanted to record weather images in accordance with the dirtiness of the weather in another study. In this study, we needed a system that warns if the air is dirty. We intended to design a system that could give early warning to eliminate this need. This warning system would inform us about the air pollution and we could be directed to take an air related views from the atmosphere. We have developed a web application in PHP using CURL both to make such a need and to build the infrastructure of mobile software displaying air pollution. This web application aims to read the data belonging air pollution parameters from the site of the ministry. Data is html format. And our application parses the web site and gets the related parameters. Parsing parameters are monitored in our developed web site. This web site’s URL is http://ozbeyaz.adiyaman.edu.tr/HKI.php. Requested web site and its view are given in the following figure.
In above codes, cURL session is initialized using the curl_init(), then all options can be set with the curl_setopt(), then the session can be executed with the curl_exec() and then session is finished off using the curl_close().
E. Android Operating System Android is an operating system employed Linux kernel. It is developed by Google, Open Handset Alliance and free software communities. It is primarily designed for touchscreens, however Android is also popular among hightech devices looking for a low-cost, customizable operating system. Initially, Android has been used only in devices such as mobile devices and tablets; today it has also been used in devices such as televisions, cars, game consoles, digital cameras and clocks. According to a survey, more than 71% of software developers are developing their apps in Android operating system. For Android, applications are written in Java language using the Android Software Development Kit (SDK). This
Fig. 3 A view from developed web application at 12
In this application five values are shown. These are the last hour’s PM10, SO2, AQI values, and air quality situation. Date and time value is get to web site. The lower rectangular box takes its own color value according to the value of the air pollution quality at that time. Because the air pollution situation in this way is good, this rectangular box is painted in
324
5th International Conference on Advanced Technology & Sciences (ICAT'17)
May 09-12, Istanbul /TURKEY
___________________________________________________________________________________________________________
absence of a mobile application of the ministry’s web application appears to be a shortcoming. Our aim has been to develop a mobile application for monitoring air pollutant function curl($url, $post=false) parameters. Thanks to our developed software, only the data { stored in a station at a certain location can be displayed. Thus, $user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17(KHTML, like Gecko) we can fast observe the air pollutant parameters for Adiyaman Chrome/24.0.1312.52 Safari/537.17'; Province. Thanks to our application, it is possible to decide $ch = curl_init(); the taking times of pictures of air in case of pollution. The curl_setopt ($ch, CURLOPT_URL, trim($url)); developed software is web based and written in PHP using curl_setopt($ch, CURLOPT_USERAGENT,$user_agent); CURL toolkit. This application has been served in a specific curl_setopt($ch, CURLOPT_TIMEOUT, 60); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); web address ((http://ozbeyaz.adiyaman.edu.tr/HKI.php). Five curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); different values can be monitored for Adıyaman province. curl_setopt($ch, CURLOPT_COOKIEFILE,""); These are PM10, SO2, AQI, air pollution situation and time curl_setopt($ch, CURLOPT_COOKIEJAR,"/cookie.txt"); slice of these values received. This application is also curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($ch); developed in Android Operating System to display air quality if(curl_errno($ch)){ indices via mobile devices. The benefits obtained from this echo 'Curl error: ' . curl_error($ch); developed software are given in the following clauses; } else This software has created the infrastructure of a work with { which one can monitor air pollution information through curl_close($ch); mobile devices. return $result; Air quality information will be tracked and weather } } images will be recorded according to the parameter values Fig. 4 CURL function developed in the study. coming from this software in mobile devices. This application is important with this aspect for developing Moreover, we have compiled the developed air pollution other works in the field. monitoring application in PHP using CURL in Android This study has been developed as a software which only operating system. This operation is simply done with a tool shows the air pollution parameters for Adıyaman province, that calls a website over Android. The interface of the however feasibility of this software will be demonstrated software monitoring air pollution quality level for Adiyaman and more robust software will be developed to monitor air Province has been developed for Android is given below quality for all provinces in Turkey over mobile devices in figure. the future. green color above figure. The curl function we have developed in the study is given below.
REFERENCES [1]
Fig. 5 Mobile based Android application of the developed software in the study.
IV. CONCLUSIONS In this study, the web application address (http://havaizleme.gov.tr/Default.ltr.aspx) developed by the Ministry of Environment and Urbanism has been employed for monitoring the air pollution parameters in an another web application working on a web address developed by us. The
E. Zamora, M. Scholar, C.S. Major, Using Image Processing Techniques to Estimate the Air Quality, in: UNLV, University of Nevada, Las Vegas, Las Vegas, 2012: p. 1. [2] D.G. Hadjimitsis, K. Themistocleous, A. Nisantzi, Air Pollution Monitoring Using Earth Observation & GIS, Intech. (2011). [3] F.J. Kelly, G.W. Fuller, H.A. Walton, J.C. Fussell, Monitoring air pollution: Use of early warning systems for public health, Respirology. 17 (2012) 7–19. doi:10.1111/j.1440-1843.2011.02065.x. [4] M. Lin, J. Tao, C.Y. Chan, J.J. Cao, Z.S. Zhang, L.H. Zhu, R.J. Zhang, Regression analyses between recent air quality and visibility changes in megacities at four haze regions in china, Aerosol and Air Quality Research. 12 (2012) 1049–1061. doi:10.4209/aaqr.2011.11.0220. [5] ADIYAMAN ÇEVRE VE ŞEHİRCİLİK İL MÜDÜRLÜĞÜ, Adıyaman İli Temiz Hava Eylem Planı, Adıyaman, 2014. [6] H. BOZBAY, ADIYAMAN İLİ 2014 YILI ÇEVRE DURUM RAPORU, Adıyaman, 2014. doi:10.1017/CBO9781107415324.004. [7] R. Trestian, A.N. Moldovan, C.H. Muntean, O. Ormond, G.M. Muntean, Quality utility modelling for multimedia applications for android mobile devices, IEEE International Symposium on Broadband Multimedia Systems and Broadcasting, BMSB. (2012) 1–6. doi:10.1109/BMSB.2012.6264328. [8] T. Amanatidis, A. Chatzigeorgiou, Studying the evolution of PHP web applications, Information and Software Technology. 72 (2016) 48–67. doi:10.1016/j.infsof.2015.11.009. [9] N. Langley, Pre-built functionality and ease of use makes PHP beginners’ choice, Computer Weekly. (2004) 6. [10] The PHP Group, PHPNET, Http://php.net/. (2017) 1. http://php.net/.
325
5th International Conference on Advanced Technology & Sciences (ICAT'17)
May 09-12, Istanbul /TURKEY
___________________________________________________________________________________________________________
A Novel Optimization Approach Based on Reciprocal Forces for Astronomical N-Body Simulation on GPU Celil Özkurt*, Eyüp Gedikli+ *
[email protected],
[email protected] Department of Software Engineering, Karadeniz Technical University Trabzon, Turkey Abstract— Astronomical N-body simulations are widely used to investigate the formation and evolution of various astronomical systems, such as planetary systems, global clusters, galaxies, galaxy clusters, and large-scale constructions of the universe. In this systems each body continuously interacts with every other body via gravity forces. The all-pairs method is a brute-force technique that calculates all pairwise interaction among the N bodies. Although it is a simple method, it is not used in large-scale simulations since the computational complexity is O (N2). However, it can be used for close range calculations when combined with hierarchical methods that are used in long distance calculations. Reciprocal forces fij = -fji can be used to reduce the number of force calculation in the all-pairs method by half. However, until March 2015, it was difficult to implement this optimization effectively with CUDA. With the release of the concurrent streams feature in CUDA 7, this optimization has become effective. In this paper, the classical CUDA application with the reciprocal forces optimized CUDA application was compared in terms of memory usage and calculation time. It has observed that reciprocal forces optimization uses about 42% less memory than classical CUDA implementation and about 19% faster when the number of body is 73,728. In addition, as the number of body increases, the reciprocal forces optimized CUDA application runs even faster. Keywords—Astronomical N-body; Reciprocal forces; Parallel Programming; Optimization with CUDA; GPU Programming
I. INTRODUCTION An N-body simulation is a simulation of a dynamical system of bodies in which each body continuously interacts with any other body. N-body simulations have been widely used to investigate the formation and evolution of various astronomical systems such as planetary systems, globular clusters, galaxies, clusters of galaxies, and other large scale structures in the universe[1][2]. The use of N-body simulation is not limited to astronomy. It is used in many areas of computational science such as computer graphics, molecular dynamics [3][4], fluid mechanics [5][6], electromagnetic[7] etc. N-body simulations have been one of the most challenging problems in computational science. Research on N-body simulations has won Gordon Bell award many times [8][9][10][11][12][13], organized by ACM (Association for Computing Machinery). In astronomical N-body simulations, planets, stars, or galaxies are regarded as bodies interacting with each other. Interactions between bodies are numerically evaluated
according to Newton's law of universal gravitation Eq. 1 and bodies are moved according to Newton's law of motion Eq. 2. 𝐹𝑖 ≈ 𝐺𝑚𝑖 . ∑ 1≤𝑗≤𝑁 (
𝑚𝑗 𝑟𝑖𝑗 2
‖𝑟𝑖𝑗 ‖ + 𝜀 2 )
3⁄ 2
(1)
In Eq. 1, mi and mj are the masses of bodies i and j, respectively; rij = xj − xi is the vector from body i to body j; ε2 is softening factor; and G is the gravitational constant. In astrophysical simulations, collisions between bodies are generally precluded; this is reasonable if the bodies represent galaxies that may pass right through each other. For this reason, the softening factor ε2>0 is added and the denominator is guaranteed to be greater than zero. a i = F i / mi
(2)
In Eq. 2, mi is the mass of body i; Fi is the net force applied on the body i; and ai is the acceleration of body i. After the acceleration is calculated, the position and velocity of the body in the next step are calculated. In the literature, studies about N-body simulations are divided into two groups as software and hardware. The software part can be divided into two as brute-force methods and hierarchical methods. Brute force methods, such as the all-pair method, require a lot of time to solve the problem since the calculation complexity is O (N2). Hence, the vast majority of scientific research focuses on hierarchical methods. Hierarchical methods, unlike brute-force methods, do not evaluate all interactions between bodies. In general, hierarchical methods divide space into hierarchical levels according to certain criteria and evaluate the interactions between these levels. The important hierarchical methods in the literature and the complexities of these methods are given in Table 1. The hardware part can be divided into two as specially designed CPUs and GPU usage. GRAPE-1 (GRAvity PipE) [14] produced in 1990 is the first CPU manufactured for the N-body problem and its performance is 100 Mflop/s. To solve the problem, a cluster is created from these CPUs. The latest GRAPE-8 [15], produced in 2012, has 48 data buses and has 480 Gflop/s processing power. GPU programming started in the late 1990s. But putting the software and hardware together,
326
5th International Conference on Advanced Technology & Sciences (ICAT'17)
May 09-12, Istanbul /TURKEY
___________________________________________________________________________________________________________
NVIDIA unveiled CUDA in 2006, the world's first solution for general-computing on GPUs. One of the few scientific problems that can benefit from this new programming paradigm is the N-body problem. The first study, which describes how the N-body problem can be applied to CUDA and examines which parameters can improve performance, was done in 2007 [16]. Since there was no algorithmic improvement in this study, we called it classical CUDA in our own study. With the release of CUDA, there were two major factors that influenced the rapid use of GPUs in such scientific problems. The first was a similar structure to the GRAPE hardware, so the existing code could be implemented on the GPU without any major changes [17]. The second was that GPUs were accessible to everyone since it was a mass production product, unlike GRAPE. Thanks to its ability to be used in artificial intelligence studies, CUDA's popularity continues to grow.
The a typical CUDA program flow consists of 4 basic steps, as shown in Fig. 2.
TABLE I. HIERARCHICAL METHODS AND THEIR COMPLEXITIES Hierarchical Methods
Complexities
Treecode[18]
O(N log N)
Fast Multipole Methods[19]
O(N log N) – O(N)
Particle-Mesh(PM) codes[20]
Fig. 2. Processing flow on CUDA
The smallest processing unit in CUDA is thread. CUDA exposes a thread hierarchy abstraction to enable you to organize your threads. This is a two-level thread hierarchy decomposed into blocks of threads and grids of blocks, as shown in Fig. 3.
O(N log N) 3
Particle-Particle-Particle-Mesh(P M)[21]
O(N log N)
PM-Tree codes[22]
O(N log N)
The remaining part of this paper is organized as following: Section II presents background information about CUDA. Section III explains the classical CUDA implementation, reciprocal optimized CUDA implementation and compares these two implementations. Finally, Section IV presents our conclusions. II. CUDA CUDA is a parallel computing platform and application programming interface (API) developed by NVIDIA. CUDA allows software developers to do general-purpose calculations using the GPUs. Its programming language is CUDA C. It has developed based on ANSI C. The CUDA platform and its API consists of 4 components, as shown in Fig 1. Fig. 3. Thread hierarchy on CUDA
Fig. 1 Cuda Platform
All of the sequential operations in Fig. 2 called a stream. Before CUDA 7.0, which was released in March 2015, multiple streams could be started on the GPU. However, the streams were run in a serial manner, as shown in Fig. 4. With version 7.0, CUDA has gained concurrent streams feature as shown in Figure 5. With this feature, you can solve different problems independently of each other at the same time. Or, as we did in this study, you can solve a problem with divide and conquer strategies. Although there is no theoretically any limit, the maximum number of concurrent streams is limited to the resources of the device. When device resources are not enough, other streams run in serial manner.
327