tag:blogger.com,1999:blog-33886678607931599032024-03-21T20:33:43.564+07:00Poom Malakul Na AyudhyaPoom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-3388667860793159903.post-1419099054962814832019-12-06T09:46:00.001+07:002019-12-07T12:30:33.479+07:00SkinDx: Machine learning android app for pigmented skin lesion diagnosis with HAM10000 dataset<b>Summary</b><br />
<a href="http://www.almanacsoft.com/skindx">SkinDx</a> is an android mobile app for pigmented skin lesion diagnosis. It is standalone machine learning app that uses models trained with <a href="https://www.nature.com/articles/sdata2018161">HAM10000</a> dataset for diagnosis prediction without connecting to any server. The app can acheive 76.7% in accuracy.<br />
<br />
<b>Background</b><br />
HAM10000 is a dermatoscopic image dataset for machine learning. It is created by Philipp Tschandl and others in 2018. Its aim is to solve the problem of small size and lack of diversity of available dataset of dermatoscopic images. There are 10,015 rows in the CSV file of this dataset. Each row describes a patient episode of skin disease, and each column describes an attribute eg. age, sex, localization, diagnosis and image file name of skin lesion. This dataset also contains 10,015 image files of related skin lesion.<br />
<br />
The diagnosis is categorized into 7 groups: (1) actinic keratoses and intraepithelial carcinoma/bowen's disease (<b>akiec</b>), (2) basal cell carcinoma (<b>bcc</b>), (3) benign keratosis-like lesions (solar lentigines/seborrheic keratoses and lichen-planus like keratoses) (<b>bkl</b>), (4) dermatofibroma (<b>df</b>), (5) melanoma (<b>mel</b>), (6) melanocytic nevi (<b>nv</b>) and (7) vascular lesions (angiomas, angiokeratomas, pyogenic granulomas and hemorrhage) (<b>vasc</b>). The information from this dataset is used for developing android mobile app for diagnosis prediction of pigmented skin lesion.<br />
<br />
<b>Methods</b><br />
1. HAM10000 dataset is checked for missing values and drop them out and then the remaining data is randomly divided into training and testing groups with ratio 80:20.<br />
2.The trained model for classifying lesion image is firstly developed and tested by using transfer training from Mobilenet model.<br />
3. The trained model from above is used to convert lesion image data into new 7 attribute columns in CSV file.<br />
4. One-Hot encoding is used to convert categorical data.<br />
5. The second trained model for diagnosis prediction is then developed and tested.<br />
6. Both trained model are converted to Tensorflow lite model and are used for Android app development.<br />
<br />
<b>Results</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNAtjodzdsk61oljhjnR5PkOeJZID6fLEtZuazMAKE-BEkx92sy40wU9ynDzbo10KWzwT8BkD2HxKDygHR2N_0eL-y4A3eG76OoYQMaLVGpDxiYszftuhXWnu38ebJ89MiiqujtJv_C5JT/s1600/Screenshot_20191115-123600.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="800" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNAtjodzdsk61oljhjnR5PkOeJZID6fLEtZuazMAKE-BEkx92sy40wU9ynDzbo10KWzwT8BkD2HxKDygHR2N_0eL-y4A3eG76OoYQMaLVGpDxiYszftuhXWnu38ebJ89MiiqujtJv_C5JT/s320/Screenshot_20191115-123600.png" width="160" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg90AmpwQIGC5mS72fMw5RQd0RG-m2qoe3Ve-qvIvGMQ1XKxQOdGi6zNcolLuPDUWbWLcIF2OZqUHxCRIi9ElZbQ2_24FBwIJt4aMn_wsaFTnK6hTrLGscfvJYMLHcgxBohhH8emucbkkxK/s1600/Screenshot_20191022-110300.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="800" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg90AmpwQIGC5mS72fMw5RQd0RG-m2qoe3Ve-qvIvGMQ1XKxQOdGi6zNcolLuPDUWbWLcIF2OZqUHxCRIi9ElZbQ2_24FBwIJt4aMn_wsaFTnK6hTrLGscfvJYMLHcgxBohhH8emucbkkxK/s320/Screenshot_20191022-110300.png" width="160" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmFGbvhb84CXfJurm-2Cjz6qOsvIEs-Cg_0qG1A2s4PDBo9-FIyoBmWa0Wq6KhTuJkoXiuM57GkRLvyfCUVN6nYU02d0dTO-RIuggHSPzdq_IDdjpaMROwHyrNynmqsHMFD9CtzJo1W6nT/s1600/Screenshot_20191022-110414.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="800" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmFGbvhb84CXfJurm-2Cjz6qOsvIEs-Cg_0qG1A2s4PDBo9-FIyoBmWa0Wq6KhTuJkoXiuM57GkRLvyfCUVN6nYU02d0dTO-RIuggHSPzdq_IDdjpaMROwHyrNynmqsHMFD9CtzJo1W6nT/s320/Screenshot_20191022-110414.png" width="160" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN-8ztOg6nX3li-68Deft00DHtbhIbh-URT-h9Y3DyKSPP44XdXN_2BJwnNQbPtBsFCOlFCV6xyvbfGReHAXv0wQm7p0W6TPX5cpLXsMWTLmy5934_-b-vtvaC8JRUP9G6xZMxKZBLv6Dn/s1600/Screenshot_20191022-110504.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="800" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN-8ztOg6nX3li-68Deft00DHtbhIbh-URT-h9Y3DyKSPP44XdXN_2BJwnNQbPtBsFCOlFCV6xyvbfGReHAXv0wQm7p0W6TPX5cpLXsMWTLmy5934_-b-vtvaC8JRUP9G6xZMxKZBLv6Dn/s320/Screenshot_20191022-110504.png" width="160" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpmnxVffNMATglMFawxjm1Rty1SVRhFTDiI7hcGqgFzDIeQupnI15IU0WNfER46RMLRbnccntgVpf12Z4bz03Gmc6aaGtSfRqgVWVvMH_Ehlz5pVdZAiONm2i1-W5qF_N6Cf-REJPbArPQ/s1600/Screenshot_20191023-123306.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="800" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhpmnxVffNMATglMFawxjm1Rty1SVRhFTDiI7hcGqgFzDIeQupnI15IU0WNfER46RMLRbnccntgVpf12Z4bz03Gmc6aaGtSfRqgVWVvMH_Ehlz5pVdZAiONm2i1-W5qF_N6Cf-REJPbArPQ/s320/Screenshot_20191023-123306.png" width="160" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen="" class="YOUTUBE-iframe-video" data-thumbnail-src="https://i.ytimg.com/vi/FZEHiRSsukM/0.jpg" frameborder="0" height="266" src="https://www.youtube.com/embed/FZEHiRSsukM?feature=player_embedded" width="320"></iframe></div>
<br />
<br />
The app is tested on android mobile device with 1,992 unseen testing cases for 1st order prediction. The results are as follow:<br />
<div>
<div>
<br /></div>
<div>
Accuracy: 76.7% (1527/1992).</div>
</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx_bBPZwovnAC8it8Uhi0s4MRO5dMQvWlPKoUgx8UI44t_WCAaEQTwjLsqA_oCzr0pPTMKI2xbae4E9VRRiRtFhljeMAT0TyVfkt37F4wFx1v5aVuPXb_7XN4b16eTQekSPbuXo47CLfz5/s1600/table_result.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="791" data-original-width="1481" height="170" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx_bBPZwovnAC8it8Uhi0s4MRO5dMQvWlPKoUgx8UI44t_WCAaEQTwjLsqA_oCzr0pPTMKI2xbae4E9VRRiRtFhljeMAT0TyVfkt37F4wFx1v5aVuPXb_7XN4b16eTQekSPbuXo47CLfz5/s320/table_result.PNG" width="320" /></a></div>
<div>
<div>
<br /></div>
<div>
*Accuracy: correct prediction / all cases</div>
<div>
*Sensitivity: TP / (TP + FN) <span style="white-space: pre;"> </span>*Precision: TP / (TP + FP)</div>
<div>
*TP: True positive <span style="white-space: pre;"> </span>*FP: False positive <span style="white-space: pre;"> </span>*FN: False negative </div>
</div>
<div>
<br /></div>
<div>
<b>Discussion</b></div>
<div>
<div>
1. Practical use of this app depends mainly on precision score for each diagnostic group. For example if the app predicts that the skin lesion is melanoma, there is a chance of 50.3% to be correct.</div>
<div>
2. If using only lesion image without age, sex and localization data, only 69.7% in accuracy can be achieved.</div>
</div>
<div>
<br /></div>
<div>
<b>Reference</b></div>
<div>
Tschandl, P., Rosendahl, C. & Kittler, H. The HAM10000 dataset, a large collection of multi-source dermatoscopic images of common pigmented skin lesions. Sci. Data 5, 180161 doi:10.1038/sdata.2018.161 (2018).<br />
<br /></div>
<a href="https://play.google.com/store/apps/details?id=com.almanacsoft.skindx&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1"><img alt="Get it on Google Play" height="76" src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png" width="200" /></a>Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0tag:blogger.com,1999:blog-3388667860793159903.post-18408507783021154052018-06-04T13:55:00.000+07:002018-06-04T14:08:18.056+07:00Project scheduling with Monte Carlo simulation on mobile<div dir="ltr" id="docs-internal-guid-bb080e3d-c8d4-6c3e-d418-f52c2a49ecb1" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;"><b><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre;">Background</span></b></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">Uncertainty is a common situation in project scheduling. It happens because we lack </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">experience from doing some activities before or have some uncontrollable factors on </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">the project. The classic technique we normally use is PERT (Program Evaluation and </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">Review Technique). But there are some drawbacks with this technique especially when </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">project has activities which are nearly equal in duration and also run in parallel. Nowadays </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">the technique that should be used is Monte Carlo simulation. However using simulation </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">requires at least desktop computer for constructing network model and experimenting </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">with it. Microsoft Project can help us constructing network model. But we need another </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">special software for performing simulation with Microsoft Excel, e.g., <a href="https://www.riskamp.com/">RiskAMP</a>, <a href="http://www.palisade.com/risk/default.asp">@Risk</a>, </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">or without Microsoft Excel, e.g.,<a href="https://www.barbecana.com/full-monte/"> Full Monte</a>. In this article we will show you the way easier </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">by using <a href="https://play.google.com/store/apps/details?id=com.almanacsoft.schemesim">AlmanacSoft SchemeSim</a> app. Only one app for doing all these steps and also </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">on mobile device. </span></span></span></div>
<span style="font-size: small;"><span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></span>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;"><b><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre;">What is AlmanacSoft SchemeSim<a href="https://www.blogger.com/null"> (</a>ASS)</span></b></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">ASS is android app that performs Monte Carlo simulation for project scheduling. It answers </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">three important questions: firstly, when project will be completed, secondly, when each </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">activity will start and end, and finally, the critical probability for each activity in the project. </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">ASS automatically creates network model and do simulation within one step and produces </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">scheduling report as an output. ASS supports two types of random generating for activity </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">durations: Triangular and Pert distribution. It detects how many CPU core the mobile has </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">and uses all of them for parallel native simulation. That is necessary because mobile has </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">limited resource. To perform simulation efficiently needs high performance computing by </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">creating native (binary) code and run it in concurrency. ASS also supports calendar time </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">and working day and time. That means we can specify which day in a week we actually </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">work, e.g., Monday to Friday, and in which time interval, e.g., 8:30 - 16:30.</span></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br />
<span style="font-family: inherit;"><span style="font-size: small;"><b><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; text-decoration: none; vertical-align: baseline; white-space: pre;">ASS overview and installation</span></b></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">ASS can be download and install from google play store. ASS offers in-app purchases. </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">That means by default this app is in basic edition and can be upgraded to professional </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">edition by paying subscription fee. In basic edition it can work for free with project not </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">more than five activities. You also have a free trial period for 30 days after upgrading to </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">professional edition. During this trial period, if you don’t satisfy with it you can cancel </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">subscription with no charge.</span></span></span></div>
<span style="font-family: inherit;"><span style="font-size: small;"><br /></span></span>
<br />
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">When you open the app you will see this following screen. This is the Input page for </span></span></span><br />
<span style="font-family: inherit;"><span style="font-size: small;"><span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;">type in your project data. </span></span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQRdT0A_qO8Z0NhYbrTjdJ7uu3rhpYBNSl4B22yoih6ZVTqRc-0b3K0Zhmt8KGx-XwiU1UyOBq4rJU1hvXzayW_CD3iHW51hLPd7oMivuNrUf41OhwXG91fqchWqQb-wLsxe66795IyGMm/s1600/Screenshot_20180528-133211%255B2%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQRdT0A_qO8Z0NhYbrTjdJ7uu3rhpYBNSl4B22yoih6ZVTqRc-0b3K0Zhmt8KGx-XwiU1UyOBq4rJU1hvXzayW_CD3iHW51hLPd7oMivuNrUf41OhwXG91fqchWqQb-wLsxe66795IyGMm/s320/Screenshot_20180528-133211%255B2%255D.png" width="180" /></a></div>
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; text-align: center;">
<span style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"><span id="docs-internal-guid-9d0f2002-c8d5-1ec0-1aa2-7f3baaac93e4" style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"></span><span style="font-family: "arial" , "helvetica" , sans-serif;"> </span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: "arial" , "helvetica" , sans-serif;"><br /></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="font-family: inherit;"><span style="font-size: small;">There are other two pages,<span style="background-color: transparent; color: black; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"> e.g.,</span> Report and About, you can navigate to them when you tap on three line menu. After simulation has finished, report will be generated in Report page.</span></span></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br /></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<div style="text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmY1JaKOP7B_QbLGAzF-WlSom_fTdbGKXJ7Rks3_qFgiqyOChYSlRBJ3syhqtipWq9DsEo3v_A8Ll7yxVeLnVcEIAjj1IZJH7iL_F_qXb14R_ahA2xG_udVX1KPQ-0_W0QroRFx_Q86RZB/s1600/Screenshot_20180604-105932%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmY1JaKOP7B_QbLGAzF-WlSom_fTdbGKXJ7Rks3_qFgiqyOChYSlRBJ3syhqtipWq9DsEo3v_A8Ll7yxVeLnVcEIAjj1IZJH7iL_F_qXb14R_ahA2xG_udVX1KPQ-0_W0QroRFx_Q86RZB/s320/Screenshot_20180604-105932%255B1%255D.png" width="180" /></a> </div>
<br />
<span style="font-family: inherit;"><b> Project data preparation</b></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLXFP5nDL-f8XguQhL8g0URvUwWPSKKSXIih_CtItgAy1q3BZV1gPDVjn7C4X3W0U0B93mqMolUfc8rGjehyhCwPCJF3xhI8WJl4K8t0pebMWNFWMJalcEJq82ARRfdyRGjg6MQLACwhod/s1600/proj_data.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="166" data-original-width="773" height="85" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLXFP5nDL-f8XguQhL8g0URvUwWPSKKSXIih_CtItgAy1q3BZV1gPDVjn7C4X3W0U0B93mqMolUfc8rGjehyhCwPCJF3xhI8WJl4K8t0pebMWNFWMJalcEJq82ARRfdyRGjg6MQLACwhod/s400/proj_data.PNG" width="400" /></a></div>
<span style="font-family: inherit;">You have to prepare project data as table above before inputing. In this case our project consists of 5 activities. We estimate activity duration by using three-point estimating (<i>a</i> = the best-case, </span><br />
<span style="font-family: inherit;"><i>b</i> = the worst-case, <i>m</i> = the most likely) which a <= m <= b. We also analyze for predecessor of each activity.</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: inherit;"><b>Entering data</b></span><br />
<br />
Type in number of activities (5) and click add button.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNteCuLtcWsLTOSO-3MjnIOS9mqqapeWR8GFjWUfxhSEUwnQLuzySuZFGLEiYqx84h_jtDXv7irCkbAEy1y6hca84tybZhTHiKQ4ej_dzcwQjCI3P4vKIdp1WwMPmMdYPBS1kmPonDXls_/s1600/Screenshot_20180604-124506%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNteCuLtcWsLTOSO-3MjnIOS9mqqapeWR8GFjWUfxhSEUwnQLuzySuZFGLEiYqx84h_jtDXv7irCkbAEy1y6hca84tybZhTHiKQ4ej_dzcwQjCI3P4vKIdp1WwMPmMdYPBS1kmPonDXls_/s320/Screenshot_20180604-124506%255B1%255D.png" width="180" /></a></div>
If you type wrong, you can check the box on the right upper side of each activity and click remove button, If you want to add more activities, you can do it again as many as you want. Type in activity name, distribution, a, b, m and predecessor. For distribution you can choose Triangular or Pert distribution. If you have no experience of this activity before, choose Triangular is better. But if you have it, Pert distribution is better. If you have predecessor more than one activities, type activity name separated by comma with no space.</div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
</div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6y-PpFkRT4r5rphYo9Pg1-KV0OxsrVfZlMaOPaebSsFz53x6FeZ1M5v4juylksK9rj2voHrhyHvl2CO_YXUJePwVVRfVKvzXCOPPCZAoGWDgebacVmsTWIHiDF5nkFWx6HMF-SOgzO5v5/s1600/Screenshot_20180604-125838%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6y-PpFkRT4r5rphYo9Pg1-KV0OxsrVfZlMaOPaebSsFz53x6FeZ1M5v4juylksK9rj2voHrhyHvl2CO_YXUJePwVVRfVKvzXCOPPCZAoGWDgebacVmsTWIHiDF5nkFWx6HMF-SOgzO5v5/s320/Screenshot_20180604-125838%255B1%255D.png" width="180" /></a></div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<br />
Now select project start date and time by click the right button. If you don't select it will use current date & time as a project starting point. In this case I choose 1 October this year and at 9 AM. <br />
For confidence level, I choose 99% and use 100,000 iterations for simulation.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9ogIdaCNrFmKiY7ZWljJ-2TGrWaWYAJc9Lvf2Dht2FtA3l4ljy_HHGTTTrI_NZEh5huFF_iRMsd6Z42-lkrMeLavkeT9oMNyInJj6AOPhfD50XFPdydq6tMprvyfabaiPJAIWabCtRXy9/s1600/Screenshot_20180604-130900%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9ogIdaCNrFmKiY7ZWljJ-2TGrWaWYAJc9Lvf2Dht2FtA3l4ljy_HHGTTTrI_NZEh5huFF_iRMsd6Z42-lkrMeLavkeT9oMNyInJj6AOPhfD50XFPdydq6tMprvyfabaiPJAIWabCtRXy9/s320/Screenshot_20180604-130900%255B1%255D.png" width="180" /></a></div>
<br />
<b>Simulation and report generation</b><br />
You can save input file by click on three dot menu and select save input file for later use. Now it is time to perform simulation, click on the pink button and click run.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfGrSy3wOveKfe4WHCzie2xjorCPVwOi8vpJA56bVuTIZ1D4zhaJJII2sg1XOSaZ38aT3OvFOzIgisSzpsZ1PjyoqGdCb0_1aGHEwMbyt5v-XvgfWGoaSUAGDa2xQ9wAx8LS51GYSUGLQo/s1600/Screenshot_20180604-131850%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfGrSy3wOveKfe4WHCzie2xjorCPVwOi8vpJA56bVuTIZ1D4zhaJJII2sg1XOSaZ38aT3OvFOzIgisSzpsZ1PjyoqGdCb0_1aGHEwMbyt5v-XvgfWGoaSUAGDa2xQ9wAx8LS51GYSUGLQo/s320/Screenshot_20180604-131850%255B1%255D.png" width="180" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYayiqW1gmGBDuyr9n2yFHpPgqVDD-HMBnDH1xdjluW4SLO2vKOZliGNBxfMXM3jMcJBMmRKWKCTxr59gaqoegHvG6ugpzOPNR_JLmgOqVkOI5L2y7O1PuR6_uJ0FJYJh06SZclCLteEw_/s1600/Screenshot_20180604-132109%255B1%255D.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1600" data-original-width="900" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYayiqW1gmGBDuyr9n2yFHpPgqVDD-HMBnDH1xdjluW4SLO2vKOZliGNBxfMXM3jMcJBMmRKWKCTxr59gaqoegHvG6ugpzOPNR_JLmgOqVkOI5L2y7O1PuR6_uJ0FJYJh06SZclCLteEw_/s320/Screenshot_20180604-132109%255B1%255D.png" width="180" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<div class="separator" style="clear: both; text-align: left;">
This project will take 20.258 days with confidence level 99% and will be finished on Sun, 21 October 2018 at 11:29. There are also detail of starting and ending date&time for each activity. Activity d is the most critical with probability 97.604% and the lowest critical is activity e which is 2.396%. You can see that we use just only 2.07 seconds for 100,000 iterations.</div>
<br /></div>
<div style="text-align: center;">
<span id="docs-internal-guid-9d0f2002-c8d5-1ec0-1aa2-7f3baaac93e4" style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"></span></div>
<div style="text-align: center;">
<span id="docs-internal-guid-9d0f2002-c8d5-1ec0-1aa2-7f3baaac93e4" style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"></span></div>
<div style="text-align: center;">
<span id="docs-internal-guid-9d0f2002-c8d5-1ec0-1aa2-7f3baaac93e4" style="background-color: transparent; color: black; font-family: "arial"; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre;"></span></div>
Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0tag:blogger.com,1999:blog-3388667860793159903.post-47358832212066470742017-03-28T14:31:00.000+07:002017-04-07T12:49:48.755+07:00Asio ThreadPool Performance Test<i>Updated: 7 April 2017</i><br />
<b><br /></b>
<b>Category: </b>C++, Concurrency Programming, Thread pool, Asio<br />
<br />
I have tested Asio ThreadPool performance by comparing processing time of three concurrency methods. The first method is<a href="http://www.cplusplus.com/reference/multithreading/"> Standard C++ Multithreading</a> (mthread), the second is<a href="http://pmalakul.almanacsoft.com/2017/03/using-asio-c-library-based-threadpool.html"> Asio ThreadPool</a> (asio) and the last is <a href="https://msdn.microsoft.com/en-us/library/dd492418.aspx">Microsoft Parallel Patterns Library</a> (ppl). All of them were used for calculating PI and Fibonacci numbers on the same machine for both Windows and Linux. They all used the same code except for PPL that is only available on Windows. I have also measured serial processing times for baseline comparison. The C++ compilers used are MSVC 19.10.25017 for Windows, GCC 6.3.1 and Clang 3.9.1 for Linux. The results are as follow:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJT8EEodJ0Ax30ztzvEEucZxVMRwHlPJw7nLEvUPeYS7SUGaPjRyDAjvOJ9vrMG2aXXftmgXmaw7fkgcb2qZWaFsREsTSzUlyQJxW1e2CteOGD_Z6re3y6pMgkzcgOdvRx6V044DU8-FJP/s1600/data.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="177" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJT8EEodJ0Ax30ztzvEEucZxVMRwHlPJw7nLEvUPeYS7SUGaPjRyDAjvOJ9vrMG2aXXftmgXmaw7fkgcb2qZWaFsREsTSzUlyQJxW1e2CteOGD_Z6re3y6pMgkzcgOdvRx6V044DU8-FJP/s320/data.PNG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<b>Comparing time used between MSVC, GCC and Clang</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGETggg-h1IzPTUKjQBruijf22QU8kL18lU1v89tEEEaRWvrR0br7WfkZsg_-0ZSa9j6c9_T4rPPCpAmKc-EG0jxfNt3fUwKazPLTWBqfx4W6MlURxCyYy5aFn3DHaVZvLL6PxvCMmrTm5/s1600/pi.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="202" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGETggg-h1IzPTUKjQBruijf22QU8kL18lU1v89tEEEaRWvrR0br7WfkZsg_-0ZSa9j6c9_T4rPPCpAmKc-EG0jxfNt3fUwKazPLTWBqfx4W6MlURxCyYy5aFn3DHaVZvLL6PxvCMmrTm5/s320/pi.PNG" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4WJ3lD1dJW490XSAUuxKwFJusY_3GHTd-_h7HDyufTMgI17CJw46v-tJW0AwVTFCanlOSFVv7n7MrxvoOWscGAFvoOcEyxMXszRApfKVk8jZrgET60zxPSqHt1T8gs2HbaPhms8NDKLw1/s1600/fib.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="204" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4WJ3lD1dJW490XSAUuxKwFJusY_3GHTd-_h7HDyufTMgI17CJw46v-tJW0AwVTFCanlOSFVv7n7MrxvoOWscGAFvoOcEyxMXszRApfKVk8jZrgET60zxPSqHt1T8gs2HbaPhms8NDKLw1/s320/fib.PNG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
GCC is the fastest in all scenarios (not including ppl). The second is MSVC except for fibonacci with asio that Clang comes the second.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDrhCuciBS4-NycM2a5rLrsLuBlWpy_3_FRQsiTDZSjPvY3K-W-7GT6RP-PQQq3ElSKuPKO3Gk1RwOTw4u8xvzzVYc2owKHyu_EaFeToG0gBaBOu_pnbcGe-wosb9zqoFA2BNX0xZW4t6L/s1600/fib_win.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"> </a> </div>
<br />
<b>Comparing each concurrency method with serial processing</b><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-wXnqWkFVIvP84hZesG2UsUB7AstWd9w9FQWY2BLjtBAI0e22cR36lXpnjeZ34748WiRZHS_B-x_Pg-b2zL3tliN5D_cN8Hc0F-ZfZy2BCUfDnDvm2PEm6CzfXMNF7-kPQXe5hFs74o-s/s1600/msvc.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-wXnqWkFVIvP84hZesG2UsUB7AstWd9w9FQWY2BLjtBAI0e22cR36lXpnjeZ34748WiRZHS_B-x_Pg-b2zL3tliN5D_cN8Hc0F-ZfZy2BCUfDnDvm2PEm6CzfXMNF7-kPQXe5hFs74o-s/s320/msvc.PNG" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<u>Using MSVC</u><br />
There is no big difference in time used for PI among mthread, asio and ppl. However for Fabonacci, mthread and ppl approximately process at the same speed and faster than asio which is the slowest.<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEwhDNMx_bFEI0Xbzck4jigVIlOMxJKpPvYRGpUj8qT55ava5NZtqJLDH6cno0lnoeFnFmMueDXI0ENifLlZX3-mTczUtQsd0ILvD8X60MyRG-LGgdLNjzBk0mWgMQi_0qqteV7gaN5zZM/s1600/gcc.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgEwhDNMx_bFEI0Xbzck4jigVIlOMxJKpPvYRGpUj8qT55ava5NZtqJLDH6cno0lnoeFnFmMueDXI0ENifLlZX3-mTczUtQsd0ILvD8X60MyRG-LGgdLNjzBk0mWgMQi_0qqteV7gaN5zZM/s320/gcc.PNG" width="320" /></a></div>
<br />
<br />
<u>Using GCC</u><br />
There is no big difference between mthread and asio in time used for PI. But for Fabonacci, mthread has a little bit faster than asio.<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEwJRQ7RYCVWHHK0fTtqRozc1ruWiGSOFo5V2wFsLO-PFDmdXehjGLeD6XzuYxh-VnGO5xNGkdvcjmN8sjWuOFT_F9zolAIEfnZntqzwSYpTZAaG6IiZCOQZC2LLZPAC-TgcY2mC_3ucBT/s1600/clang.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="194" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEwJRQ7RYCVWHHK0fTtqRozc1ruWiGSOFo5V2wFsLO-PFDmdXehjGLeD6XzuYxh-VnGO5xNGkdvcjmN8sjWuOFT_F9zolAIEfnZntqzwSYpTZAaG6IiZCOQZC2LLZPAC-TgcY2mC_3ucBT/s320/clang.PNG" width="320" /></a></div>
<br />
<u>Using Clang</u><br />
There is no big difference between mthread and asio for both PI and Fibonacci.<br />
<br />
<br />
<b>Conclusions</b><br />
<ul>
<li>The concurrency processing speed depends mainly on three factors: compiler, computational type and concurrency method respectively. </li>
</ul>
<ul>
<li>Asio ThreadPool does not perform well with MSVC on some computational type (Fibonacci) when comparing with GCC and Clang.</li>
</ul>
The code is <a href="https://github.com/pmalakul/ThreadPool/tree/master/PerformanceTest">here</a>. <br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0tag:blogger.com,1999:blog-3388667860793159903.post-63606185530657749272017-03-04T12:22:00.001+07:002017-03-10T13:59:38.999+07:00Using Asio C++ library based ThreadPool class<b>Category: </b>C++, Concurrency Programming, Thread pool, Asio<br />
<br />
<b>Prerequisites:</b> C++, Asio C++ programming concept, Multithreading<br />
<br />
<b>Requirement:</b> Asio C++ library<br />
<br />
<b>What is it? </b><br />
It is only a C++ header file that defines ThreadPool class based on <a href="http://think-async.com/">Asio C++ Library</a>.<br />
<br />
<b>Why is it created?</b><br />
It is created to serve the following purposes:<br />
<ol>
<li>To use C++ multithreading with thread pool.</li>
<li>To use task based concurrency programming.</li>
<li>Can use strictly sequential invocation of handlers.</li>
<li>Can use C++ Exception handling. </li>
</ol>
<br />
<b>How can you use it?</b> <br />
<ol>
<li>Create the client class that will use thread pool.</li>
<script class="brush: cpp" type="syntaxhighlighter"><![CDATA[
// client.h
#include "ThreadPool.h"
class client : public std::enable_shared_from_this<client> {
public:
client(PMConcurrency::ThreadPool & threadPool) : _threadPool(threadPool) {}
private:
PMConcurrency::ThreadPool & _threadPool;
};
]]></script>
<li>Create any tasks that you want to execute in sequential or parallel order. In our case we use sequential for simplicity.</li>
<script class="brush: cpp" type="syntaxhighlighter"><![CDATA[
//client.h
#include "ThreadPool.h"
class client : public std::enable_shared_from_this<client> {
public:
client(PMConcurrency::ThreadPool & threadPool) : _threadPool(threadPool) {}
~client() {}
void start();
private:
void runConcurrency();
PMConcurrency::ThreadPool & _threadPool;
};
]]></script>
<script class="brush: cpp" type="syntaxhighlighter"><![CDATA[
void client::runConcurrency() {
auto self(shared_from_this());
_threadPool.enqueue(
[this, self] () {
std::cout << "First Task from tid: " << _threadPool.getThisThreadId() << std::endl;
// throw std::runtime_error("throw exception");
auto self(shared_from_this());
_threadPool.enqueue(
[this, self] () {
std::cout << "Second Task from tid: " << _threadPool.getThisThreadId() << std::endl;
auto self(shared_from_this());
_threadPool.enqueue(
[this, self] () {
std::cout << "Third Task from tid: " << _threadPool.getThisThreadId() << std::endl;
auto self(shared_from_this());
_threadPool.enqueue(
[this, self] () {
std::cout << "Fourth Task from tid: " << _threadPool.getThisThreadId() << std::endl;
});
});
});
});
}
]]></script>
<li>If you want to handle exception. Modify previous code, add final task to start and stop MainIoService as shown in the following code.</li>
<script class="brush: cpp" type="syntaxhighlighter"><![CDATA[
// client.cpp
void client::start() {
runConcurrency();
_threadPool.startMainIoService();
}
void client::runConcurrency() {
auto self(shared_from_this());
_threadPool.enqueue(
[this, self] () {
std::cout << "First Task from tid: " << _threadPool.getThisThreadId() << std::endl;
auto self(shared_from_this());
_threadPool.enqueueMainIoService(
[this, self] () {
_threadPool.stopMainIoService();
});
});
}
]]></script>
<li>In the main code, create ThreadPool instance. Then create client instance by using shared_ptr. Make a call from the client and try to throw an exception in the client code to test exception handling.</li>
<script class="brush: cpp" type="syntaxhighlighter"><![CDATA[
// main.cpp
#include "ThreadPool.h"
#include "client.h"
int main() {
try {
PMConcurrency::ThreadPool threadPool;
std::shared_ptr<client> myClient = std::make_shared<client>(threadPool);
myClient->start();
return 0;
}
catch(std::exception const & e) {
std::cout << "Error: " << e.what() << std::endl;
}
return 0;
}
]></script>
<li>If you use _threadPool.strand() instead of _threadPool.enqueue(), any tasks called can not be executed concurrently.</li>
</ol>
<b>How to dowload the ThreadPool Class?</b><br />
The ThreadPool Class is in <a href="https://github.com/pmalakul/ThreadPool">ThreadPool.h header file on github</a>.<br />
<b> </b><br />
<b> </b><br />
<ol>
</ol>
Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0tag:blogger.com,1999:blog-3388667860793159903.post-5336674578252230132013-09-12T14:06:00.001+07:002013-09-21T12:30:53.280+07:00Introduction to AlmanacSoft Payer 1.0<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<b>Category: </b>Windows Store app, PayPal, REST API, eCommerce<br />
<br />
<b>What is AlmanacSoft Payer 1.0?</b><br />
<br />
<a href="http://www.almanacsoft.com/payer">AlmanacSoft Payer 1.0</a> is Windows Store app running on Windows 8.1 Preview or later. It is payment app that uses new <a href="https://developer.paypal.com/">PayPal's REST APIs</a> with standards-based technologies such as OAuth and JSON for paying money on the Internet. It supports both Direct Credit Card Payment and PayPal Account Payment. The app is native code written in C++/CX and developed by Poom Malakul Na Ayudhya.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia2EcH1VU68B2cXcX2KqF6AAKPdx1thA3hY0GRKbjRcmpy87UlO128sTpyxzz3V7HKeFCTNZ2aB_MAKmgJDKHtSdnt0qnrJTPPzuqqQ5KAIukYI_UAm1SDpkCIKaJC906a7Fjp4JNFLxmi/s1600/payer_concept.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEia2EcH1VU68B2cXcX2KqF6AAKPdx1thA3hY0GRKbjRcmpy87UlO128sTpyxzz3V7HKeFCTNZ2aB_MAKmgJDKHtSdnt0qnrJTPPzuqqQ5KAIukYI_UAm1SDpkCIKaJC906a7Fjp4JNFLxmi/s1600/payer_concept.jpg" height="171" width="320" /></a></div>
<br />
<br />
<b>How to Install</b><br />
<ol>
<li>Download AlmanacSoft Payer 1.0 and you will get the file named "Payer_1.0.0.0_Win32_Test.zip".</li>
<li>Extract it and right click on "Add-AppDevPackage.ps1" to Run with PowerShell. </li>
<li> You may be asked to acquire the developer license if you don't have it yet. Use your Microsoft account to log in and get the license for free. It will be expired in one month and you can renew it.</li>
<li>You may be asked for Execution Policy Change, you have to answer "[Y] Yes"</li>
<li>You may be asked for installing the signing certificate, you have to answer "[Y] Yes". </li>
<li>AlmanacSoft Payer will be installed successfully.</li>
</ol>
<br />
<b>How to use</b><br />
<br />
<i>For Merchants</i><br />
<ol>
<li>You have to register at <a href="http://www.paypal.com/">PayPal</a> for PayPal merchant account.</li>
<li>Log in at <a href="https://developer.paypal.com/">https://developer.paypal.com/</a> with your merchant account. Then create an application to get merchant's Client Id and Secret.</li>
<li>Run AlmanacSoft Payer and select credentials page. Use your Client ID and Secret to apply and export your encrypted <b>merchant data file</b> (MDF).</li>
<li>Send encrypted MDF<b> </b>to your customers by e-mail or let them download from your website.</li>
<li>Tell your customers to use AlmanacSoft Payer to import or download your MDF and use it to make payment for you.</li>
</ol>
<i>For Customers</i><br />
<ol>
<li>Run AlmanacSoft Payer. If you are behind proxy server, set your proxy credentials first.</li>
<li>Using AlmanacSoft Payer to import or download encrypted MDF provided by the merchant you want to pay.</li>
<li>Select appropriate payment method for merchant in the <a href="https://developer.paypal.com/webapps/developer/docs/integration/direct/rest_api_payment_country_currency_support/">countries supported by PayPal</a>. </li>
</ol>
<br />
<ol>
</ol>
Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0tag:blogger.com,1999:blog-3388667860793159903.post-42542710461341823412013-03-27T14:46:00.000+07:002013-04-19T09:42:46.978+07:00C++ AMP: How fast is it?<b>Category: </b>Windows Store app, C++ AMP, GPU Programming<br />
<b>Prerequisites:</b> C++, C++ AMP<br />
<br />
<a href="https://docs.google.com/file/d/0Bw9L2YNnxdSQZFJjRE85NDJCMGc/edit?usp=sharing">Full Text in Thai (PDF 1.13 MB)</a><br />
<br />
This study measures time used in millisecond for calculating square matrix multiplication at different dimension sizes starting from 256x256 to 2048x2048. The C++ AMP tested engines are two GPUs (Intel HD Graphics 4000 and NVIDIA Geforce GT-650M) and one software engine (Microsoft Basic Render Driver). Two C++ AMP methods (simple and tiling) are used. The study also measures time used by normal sequential code for using as a baseline comparison. The testing software is C++ Windows Store app running on Intel i7 RAM 8 MB.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjovpa6PvucPuCl8FU5GQaS1QhgOvW2pj9Va81OTu2st3JYZB_6M3DUKiiZ-hej6z-XyeuD1gBHkbG0Sa8UpiG6dFwa-GRz88VuygPiyL2mSxkgNvbGFpDhjhcbAz1mxDCDUyXdbgVQh5RP/s1600/fig1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjovpa6PvucPuCl8FU5GQaS1QhgOvW2pj9Va81OTu2st3JYZB_6M3DUKiiZ-hej6z-XyeuD1gBHkbG0Sa8UpiG6dFwa-GRz88VuygPiyL2mSxkgNvbGFpDhjhcbAz1mxDCDUyXdbgVQh5RP/s1600/fig1.png" height="179" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
The figure above shows Windows Store app used in this study. It also has 3D rotating cube in background for testing with DirectX.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIGc3eJPjU1uI-G9z0OP_ro6Q6MkNrzlFHek54cJcpTwcZI-tRgBJAE7dKBXVoiUgmWdsaOtlh60oP9qke6YbPYSeFgHspVe4vWpd8NAtoUHTPaJP0ngZvRRaKdTGvhPBT4zF_vD_Q8y4f/s1600/27-03-2013+13-08-32.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIGc3eJPjU1uI-G9z0OP_ro6Q6MkNrzlFHek54cJcpTwcZI-tRgBJAE7dKBXVoiUgmWdsaOtlh60oP9qke6YbPYSeFgHspVe4vWpd8NAtoUHTPaJP0ngZvRRaKdTGvhPBT4zF_vD_Q8y4f/s1600/27-03-2013+13-08-32.png" height="253" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
This is the result table of time used measured in milliseconds. The table also shows computed ratio (in red) comparing between MS Basic Render Driver and Sequential code and also between both GPUs and MS Basic Render Driver. The size means the matrix dimension starting from 256x256 to 2048x2048.</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsybjWhOgM5d1WZZCgSSU-CC5dLGSlMlOfmMCf_u2FOBi1Vmz1rH_V2uQzHBTB23GaiTWPTfZi46kFwuX2kq8dnAt7kTO-lFQnGO_WAQDeHfrZxeDttwDMSvXcgRDGtQaXua8yHYY0bm1t/s1600/fig2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsybjWhOgM5d1WZZCgSSU-CC5dLGSlMlOfmMCf_u2FOBi1Vmz1rH_V2uQzHBTB23GaiTWPTfZi46kFwuX2kq8dnAt7kTO-lFQnGO_WAQDeHfrZxeDttwDMSvXcgRDGtQaXua8yHYY0bm1t/s1600/fig2.png" height="209" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
From the above figure, MS Render Driver speed is around five to ten times comparing with sequential code when using simple method and five to twenty times when using tile method.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyCRf07TUj52KJ0TOvtixXft4zw4eLaumBMmkqOuT1JqwOONFKThjkgSPvu12K6UmXjFYHPYfEMjQf8dSSkvH7PMW8KakGOvendzjVNCyeynALDt-ih26UO37s-tUJCPEH0rHjrXUCgk8d/s1600/fig3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyCRf07TUj52KJ0TOvtixXft4zw4eLaumBMmkqOuT1JqwOONFKThjkgSPvu12K6UmXjFYHPYfEMjQf8dSSkvH7PMW8KakGOvendzjVNCyeynALDt-ih26UO37s-tUJCPEH0rHjrXUCgk8d/s1600/fig3.png" height="173" width="320" /></a></div>
<br />
When using simple method, NVIDIA's speed is ten to thirty times comparing with MS Render Driver while Intel's speed is around five times comparing with MS Render Driver.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXl5HbGgLU_pn5O4PYzU9oBsMAGynOSxE_VRsfrJRPr12BJSpcqdIuOee_KFo-mbr0-KCIBUlQx4AWpjEXhJJptElJcW6o5emEpAfgiOwfJcHj13MnvpldzLhfN5zOCgLtW6VUuk3trsHY/s1600/fig4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXl5HbGgLU_pn5O4PYzU9oBsMAGynOSxE_VRsfrJRPr12BJSpcqdIuOee_KFo-mbr0-KCIBUlQx4AWpjEXhJJptElJcW6o5emEpAfgiOwfJcHj13MnvpldzLhfN5zOCgLtW6VUuk3trsHY/s1600/fig4.png" height="180" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
When using tile method, NVIDIA's speed is from fifteen to twenty five times comparing with MS Render Driver while Intel's speed is around five times comparing with MS Render Driver.</div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<br />Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0tag:blogger.com,1999:blog-3388667860793159903.post-69269183843594452892013-02-15T14:41:00.001+07:002013-02-16T13:04:06.944+07:00Run-time Data Binding<b>Category:</b> Windows Store App Developing<br />
<b>Prerequisites:</b> XAML, C++, C++/CX, Simple Data Binding<br />
<br />
Data binding lets you synchronise UI control elements in XAML with data source that can be dataset, data object or any primitive data types. Usually you just set binding property for any UI control elements and then set <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.data.bindableattribute.aspx">BindableAttribute</a> attribute for the ref class in the code behind. And when you compile your code, the compiler will do the rest and all properties in your class will be bindable.<br />
<br />
<b>The Problem</b><br />
Sometimes you may need data class that uses dynamic properties. That means you don’t know at compile time what and how many data properties and types the class should have. This is a common situation such as when you retrieve data set from the SQL server that you usually specify data fields at run time. In these cases, BindableAttribute attribute doesn't help.<br />
<br />
<b>The Solution</b><br />
<div>
My solution is to implement <a href="http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.ui.xaml.data.icustompropertyprovider.aspx">ICustomPropertyProvider</a> for the ref class. In this article I call this technique as Run-time Data Binding. The steps are as follows:<br />
<br />
1. First, create new ref class with inheriting and implementing ICustomProperty. This class will be used for representing run-time property you will create later.<br />
<ol>
</ol>
<script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
public ref class CustomProperty sealed
: Windows::UI::Xaml::Data::ICustomProperty
{..};
]]></script>
<br />
2. Create another new ref class with inheriting and implementing ICustomPropertyProvider. If you want to be notified when your property changed you can also inherit and implement INotifyPropertyChanged here. Don't forget to inherit from DependencyObject, this is mandatory.<br />
<br />
<script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
public ref class CustomPropertyProvider
: Windows::UI::Xaml::Data::ICustomPropertyProvider
, Windows::UI::Xaml::DependencyObject
{..};
]]></script>
<br />
In this class I used Map Collection to store my CustomProperty objects and created two public methods for getting and setting value for CustomProperty target.<br />
<br />
<script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
property Windows::Foundation::Collections::IMap<Platform::String^, Windows::UI::Xaml::Data::ICustomProperty^>^ CustomProperties
{
Windows::Foundation::Collections::IMap<Platform::String^, Windows::UI::Xaml::Data::ICustomProperty^>^ get()
{
return _properties;
}
}
Object^ GetPropertyValue(Platform::String^ propName);
void SetPropertyValue(Platform::String^ propName, Object^ value);
]]></script>
<br />
Now you will have two ref class that can be used for run-time data binding.<br />
<br />
3. Create new ref class to be used for run-time binding which inherit from CustomPropertyProvider ref class. In this case I'll create Person Class that will have name property created at run-time.<br />
<br />
<script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
public ref class Person sealed : CustomPropertyProvider
{
};
]]></script>
<br />
4. Insert name property at rum-time.<br />
<script type="syntaxhighlighter" class="brush: cpp"><![CDATA[
Person^ myPerson = ref new Person();
Windows::UI::Xaml::Interop::TypeName myTypeName;
CustomProperty^ myCustomProperty = nullptr;
myTypeName.Name = "Platform::String";
myTypeName.Kind = TypeKind::Metadata;
myCustomProperty =
ref new CustomProperty("Name", myTypeName, true, true);
myCustomProperty->SetValue(this, ""); // Initial value
// Insert new property at run-time
myPerson->CustomProperties->Insert("Name", myCustomProperty);
// Change to new name
myPerson->SetPropertyValue("Name", "MyNewName");
]]></script>
<br /></div>Poom Malakul Na Ayudhyahttp://www.blogger.com/profile/02796764008479619915noreply@blogger.com0