2016년 10월 16일 일요일

OpenMP 예제: For loop iterations w/ no data dependency

Notes:

1. Visual Studio 2015 setting은:

2. #include <omp.h>
  • omp_get_thread_num()를 위해 필요함.

3. OpenMP constructs:
  • #pragma omp parallel for
  • #pragma omp critical
    • Optional name을 이용해서 서로 다른 여러 개의 critical section을 정의할 수 있음:
      #pragma omp critical (name_of_the_critical_section)
    • All CRITICAL sections which are unnamed, are treated as the same section (https://computing.llnl.gov/tutorials/openMP/#CRITICAL).

4. 참고로, #include "Windows.h"Sleep()을 위한 것임 (OpenMP와 상관 없음).

#include <iostream>

#include <omp.h>

#include "Windows.h"

using namespace std;

void First();
void Second();
void Third();

int main() {
#pragma omp parallel for
  for (int i = 0; i < 100; ++i) {
    const int tid = omp_get_thread_num();
#pragma omp critical
    cout << tid << ": * Processing: " << i << endl;

#pragma omp critical
    cout << tid << ":   1. The first job" << endl;
    First();

#pragma omp critical
    cout << tid << ":   2. The second job" << endl;
    Second();

#pragma omp critical
    cout << tid << ":   3. The third job" << endl;
    Third();

    cout << endl;
  }

  return 0;
}

void First()  { Sleep(1000); }
void Second() { Sleep(500);  }
void Third()  { Sleep(2000); }

2016년 10월 5일 수요일

Windows 10 - KB3194496 update 설치 실패 해결

Microsoft community의 [이 글]에 따르면, 아래와 같이 두 가지 방법이 있음:
  1. Bypass Windows Update by installing the latest version directly [Simple]
    Solution posted by Sean8102 on October 1st (page 16)
    Go to the Get Windows 10 webpage and click download tool now.  When you run the tool, select "Upgrade This PC Now" and choose to keep everything (files, apps, and settings).  This will apply the update directly without impacting any of your installed programs at all.  You can also use the tool to create a bootable USB stick and install from that, but no USB stick is necessary if you use the "Upgrade This PC Now" option.
  2. Remove Tasks and Registry for Tasks that that Block The Update [Advanced]
    Solution posted by TomislavRex on October 3rd (page 23 with additional details on page 29)
    Deleted all references to task  \Microsoft\XblGameSave\XblGameSaveTask in the System32 folder, AND all traces of them from the registry (in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache tree.  Noted that deleting some of these involved changing ownership of the keys. The tasks have been recreated during the installation of the update.
이 글에서는 더 쉬운 방법인 1번 방법을 설명함.

[해결 방법 1]

1. [이 글]에 가서 "Download tool now"를 click하여 "MediaCreationTool.exe" file을 받는다. 

2. Download 받은 file을 실행하면 Windows 10 download가 시작된다: 

3. 아래 화면에서 "동의"를 click:

4. 다음과 같이 update가 download된다:

5. "설치 준비 완료" 화면에서 "개인 파일, 앱을 유지합니다."가 check된 것을 확인한 후에 "설치"를 click한다:
(만약 check가 안 되어 있다면 "유지할 항목 변경"에서 설정한다.)

6. 몇 번의 재 booting을 통해 Windows가 설치된다.

7. 설치가 끝나고 update를 확인해보면 다음과 같이 (KB3194496를 포함하는) 모든 update가 설치된 것을 확인할 수 있다:

2016년 9월 26일 월요일

SystemC regression test with Visual Studio 2015

1. Download the SystemC regression test file (systemc_regressions-2.3.1.tar) from http://www.accellera.org/.

2. Untar the file to the directory where the regression test is going to be performed.
e.g. D:\systemc_regressions-2.3.1

3. Install Cygwin with Perl package.

4. In Cygwin, rename /usr/bin/link.exe to /usr/bin/link_cyg.exe.
This is required because Visual Studio's link.exe should be used instead of that of Cygwin.

5. Modify scripts\vsvars.bat file as below:
(The file on the left is the original. Click the image to read in detail.)

6. Modify scripts\verify.pl file as below:
(The file on the left is the original. Click the image to read in detail.)

7. Follow the steps as below (Click the image to read in detail):

8. The results for SystemC and TLM tests are as below.
(SystemC is assumed to be installed using the directions in [this article].)

8-1. SystemC:
-------------------------------------------------------------------------------
 Tests that failed :
-------------------------------------------------------------------------------
                diff                : systemc/bugs/sc_bigint_part_select/test01/test01.cpp
             compiling              : systemc/compliance_1666/test228/test228.cpp
                diff                : systemc/datatypes/fx/fast_constructors/test.f
                diff                : systemc/datatypes/fx/ranges/test.f
                diff                : systemc/datatypes/int/misc/test02/test02.cpp
                diff                : systemc/datatypes/int/parse_binary_bits/test01/test01.cpp
                diff                : systemc/datatypes/int/parse_binary_bits/test02/test02.cpp
                diff                : systemc/datatypes/misc/concat/test07/test07.cpp
                diff                : systemc/kernel/phase_callbacks/test04/register_phase_callbacks.cpp
                diff                : systemc/kernel/phase_callbacks/test05/simulation_callbacks.cpp
             compiling              : systemc/kernel/sc_time/test01/test01.cpp
                diff                : systemc/misc/stars/star130782/test.cpp

Total passed : 828
Total failed : 12

   GUT METER : 98 %

8-2. TLM:
-------------------------------------------------------------------------------
 Tests that failed :
-------------------------------------------------------------------------------

Total passed : 18
Total failed : 0

   GUT METER : 100 %

2016년 9월 25일 일요일

SystemC with Visual Studio 2015

1. Download the SystemC source code (systemc-2.3.1.tgz) from http://www.accellera.org/.

2. Untar the downloaded file to the directory where SystemC is to be installed.
e.g. D:\systemc-2.3.1

3. Make a directory msvc14 and create a "Static library" Visual Studio 2015 project, systemc, under it.

4. Add the source files (*.cpp and *.h) under src directory and below (except those under src\sysc\packages and src\sysc\qt), to the systemc project.
(Use "Add → Existing Item" in Visual Studio. Alternatively, drag-and-dropping from Windows File Explorer to the Solution Explorer in Visual Studio also works.)

4-1. In my case, I temporarily moved src\sysc\packages and src\sysc\qt directories to outside of the SystemC directory hierarchy. Then I searched for *.cpp and *.h files under src directory in Windows File Explorer. Finally, I drag-and-dropped the searched file into the Solution Explorer in Visual Studio and moved back the two directories to their original locations.

5. Add src directory to "Additional Include Directories" of the systemc project.

6. Set "Enable Run-Time Type Info" of the systemc project to "Yes".

7. Add /vmg to "Additional Options" of the systemc project.

8. Modify the src\systemc.h file using a text editor (e.g. Vim) as below (Comment out the line, std::gets):

9. Modify the src\sysc\packages\boost\config\compiler\visualc.hpp file as the following (Comment out the version check):

10. Build for both Debug and Release configurations.

11. The results from the regression tests provided in http://www.accellera.org/ are shown in [this article]. In short, I think in general, if the SystemC datatypes that failed the tests are not used, this installation acts as expected.

2016년 9월 16일 금요일

C++ XML parsing & iteration

특이사항들:
  • XML file을 저장할 data type은 boost::property_tree::ptree.
    • #include <boost/property_tree/ptree.hpp>
  • read_xml(ifname, ptree)
    • #include <boost/property_tree/xml_parser.hpp>
    • 참고로, property tree는 XML 외에 다른 tree 구조 file들도 parsing할 수 있음 (e.g. JSON, INI, INFO).
  • Iterate하려면 ptreebegin(), end()를 이용해야겠지?
    • Iterator의 type은 ptree::iterator (혹은 ptree::const_iterator).
    • Iterator를 dereference한 value의 type은 ptree::value_type.
      • ptree::value_type은 별 거 아니고, pair<string, basic_ptree> 임. 즉, first가 key이고 second가 sub-tree임.
  • XML의 attribute는 key가 <xmlattr>ptree::value_type 변수의 second에 있는 sub-tree에 주~욱 저장되어 있음. 
  • tree.data() 로 저장된 값에 접근함. 
#include <iostream>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>

using namespace std;
using namespace boost::property_tree;

int main(int argc, char *argv[]) {
  const string ifname("books.xml");
  ptree tree;
  read_xml(ifname, tree);

  const string sep(2, ' ');

  for (ptree::iterator i = tree.begin(); i != tree.end(); ++i) {
    const ptree::value_type &v = *i;
    const string k0 = v.first;
    const ptree t0 = v.second;

    cout << k0 << endl; // catalog

    for (ptree::const_iterator j = t0.begin(); j != t0.end(); ++j) {
      const string k1 = j->first;
      const ptree t1 = j->second;

      const string sep1 = sep;
      cout << sep1 << k1 << endl; // book

      for (ptree::const_iterator k = t1.begin(); k != t1.end(); ++k) {
        const string k2 = k->first;
        const ptree t2 = k->second;

        const string sep2 = sep1 + sep;
        cout << sep2 << k2 << " = "; // <xmlattr>, author, title, genre, 
                                     // price, publish_date, description

        if (k2 == "<xmlattr>") {
          for (ptree::const_iterator l = t2.begin(); l != t2.end(); ++l) {
            const string k3 = l->first;
            const ptree t3 = l->second;

            cout << endl;
            const string sep3 = sep2 + sep;
            cout << sep3 << k3 << " = "; // id
            cout << t3.data() << endl;
          } // for (l: t2)
        } else {
          cout << t2.data() << endl;
        }
      } // for (k: t1)
    } // for (j: t0)
  } // for (i: tree)

  return 0;
}

위의 program을 Microsoft에서 제공하는 books.xml을 이용하여 실행하면 다음과 같은 출력이 나온다:
catalog
  book
    <xmlattr> = 
      id = bk101
    author = Gambardella, Matthew
    title = XML Developer's Guide
    genre = Computer
    price = 44.95
    publish_date = 2000-10-01
    description = An in-depth look at creating applications 
      with XML.
  book
    <xmlattr> = 
      id = bk102
    author = Ralls, Kim
    title = Midnight Rain
    genre = Fantasy
    price = 5.95
    publish_date = 2000-12-16
    description = A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.
  book
    <xmlattr> = 
      id = bk103
    author = Corets, Eva
    title = Maeve Ascendant
    genre = Fantasy
    price = 5.95
    publish_date = 2000-11-17
    description = After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new society.
  book
    <xmlattr> = 
      id = bk104
    author = Corets, Eva
    title = Oberon's Legacy
    genre = Fantasy
    price = 5.95
    publish_date = 2001-03-10
    description = In post-apocalypse England, the mysterious 
      agent known only as Oberon helps to create a new life 
      for the inhabitants of London. Sequel to Maeve 
      Ascendant.
  book
    <xmlattr> = 
      id = bk105
    author = Corets, Eva
    title = The Sundered Grail
    genre = Fantasy
    price = 5.95
    publish_date = 2001-09-10
    description = The two daughters of Maeve, half-sisters, 
      battle one another for control of England. Sequel to 
      Oberon's Legacy.
  book
    <xmlattr> = 
      id = bk106
    author = Randall, Cynthia
    title = Lover Birds
    genre = Romance
    price = 4.95
    publish_date = 2000-09-02
    description = When Carla meets Paul at an ornithology 
      conference, tempers fly as feathers get ruffled.
  book
    <xmlattr> = 
      id = bk107
    author = Thurman, Paula
    title = Splish Splash
    genre = Romance
    price = 4.95
    publish_date = 2000-11-02
    description = A deep sea diver finds true love twenty 
      thousand leagues beneath the sea.
  book
    <xmlattr> = 
      id = bk108
    author = Knorr, Stefan
    title = Creepy Crawlies
    genre = Horror
    price = 4.95
    publish_date = 2000-12-06
    description = An anthology of horror stories about roaches,
      centipedes, scorpions  and other insects.
  book
    <xmlattr> = 
      id = bk109
    author = Kress, Peter
    title = Paradox Lost
    genre = Science Fiction
    price = 6.95
    publish_date = 2000-11-02
    description = After an inadvertant trip through a Heisenberg
      Uncertainty Device, James Salway discovers the problems 
      of being quantum.
  book
    <xmlattr> = 
      id = bk110
    author = O'Brien, Tim
    title = Microsoft .NET: The Programming Bible
    genre = Computer
    price = 36.95
    publish_date = 2000-12-09
    description = Microsoft's .NET initiative is explored in 
      detail in this deep programmer's reference.
  book
    <xmlattr> = 
      id = bk111
    author = O'Brien, Tim
    title = MSXML3: A Comprehensive Guide
    genre = Computer
    price = 36.95
    publish_date = 2000-12-01
    description = The Microsoft MSXML3 parser is covered in 
      detail, with attention to XML DOM interfaces, XSLT processing, 
      SAX and more.
  book
    <xmlattr> = 
      id = bk112
    author = Galos, Mike
    title = Visual Studio 7: A Comprehensive Guide
    genre = Computer
    price = 49.95
    publish_date = 2001-04-16
    description = Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.

2016년 7월 9일 토요일

a2ps 설치 (bash on Windows)

1. "a2ps"를 넣어서 설치가 안 된 것을 확인.
2. 안내에 나오는 대로 다음 명령을 넣는다.
sudo apt-get install a2ps
3. Superuser 권한을 얻기 위해 password를 넣는다.
4. "계속 하시겠습니까 [Y/n]"에서 "Y"로 계속한다.

5. 다음과 같이 설치가 된다.

6. 설치가 제대로 되었는지 확인하기 위해 다음 명령을 넣어본다.
a2ps -h

2016년 6월 19일 일요일

SystemC on Windows (using Bash on Windows)

1. Normally, SystemC uses dynamically linked library. However, it does not work (yet) in Bash on Windows:
The error message goes: "error while loading shared libraries: libsystemc-2.3.1.so: cannot enable executable stack as shared object requires: Invalid argument".

Note that I've already set the environment variable, LD_LIBRARY_PATH, to the directory where SystemC library resides as below:

2. A workaround is to use static-linking:
Note the flags used in the linking command:
-Wl, -Bstatic -lsystemc -Wl, -Bdynamic -pthread

SystemC를 Ubuntu에서 이용하는 방법 (Hello world program)

0. 가정: SystemC 설치 방법을 설명한 이 글에서와 같이, SystemC는 "$HOME/sysc"에 설치되어 있음을 가정.

1. SystemC hello world program의 code (main.cpp):
#include <iostream>

#include "systemc.h"

using namespace std;

int sc_main(int argc, char *argv[]) {
  cout << "Hello, world!" << endl;
  return 0;
}

2. "LD_LIBRARY_PATH" 환경 변수 설정을 위해 "$HOME/.bashrc"에 다음을 추가:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/sysc/lib-linux64
export LD_LIBRARY_PATH

3. Compile을 위한 command:
g++ -o main -I$HOME/sysc/include -L$HOME/sysc/lib-linux64 main.cpp -lsystemc

4. 다음과 같이 실행됨:

SystemC를 Ubuntu에 설치하는 방법

1. Accellera website (http://accellera.org/)에서 "Downloads" → "Accellera Standards" 선택.

2. "Available Accellera Systems Initiative Standards" 화면에서 "SystemC" 선택.

3. "SystemC" 화면에서 "Core SystemC Language and Examples" 선택.

4. "SystemC Open Source License Agreement" 화면이 나오는데, "I accept the SystemC Open Source License" 선택.

5. 다시 한 번 "SystemC" 화면이 나오는데, 여기서 다시 "Core SystemC Language and Examples" 선택.

6. "systemc-2.3.1.tgz" file을 download.

7. Download된 file을, 다음 명령으로 압축을 푼다.
tar xvzf systemc-2.3.1.tgz

8. Build (configure).
  1. 압축이 풀리면 "systemc-2.3.1"라는 directory가 생기는데, "cd systemc-2.3.1"해서 그 안으로 들어간다.
  2. Build를 위해 "mkdir build", "mkdir ~/sysc"를 한다 ("build" directory 에서 build를 하고, "~/sysc" directory에 설치를 할 것이다). 
  3. "cd build" 하여 "build" directory에 들어간 후, 다음 명령어로 configure (build를 위한 사전 작업)를 한다.
    ../configure --prefix=$HOME/sysc

9. Build (make; make install)
  1. "make"로 build 한 다음..
  2. "make install"로 install 한다. 

10. 다음과 같이, "~/sysc"에 SystemC가 설치된 것을 알 수 있다.

11. 설치된 SystemC의 기본적인 사용법에 관해서는 이 글을 참고. 

2016년 6월 12일 일요일

Bash on Windows 설치 방법

1. Windows 10의 Insider Preview build를 이용하기 위해서 다음을 한다.

1-1. Windows 시작 button → "설정" 선택:

1-2. "업데이트 및 복구"를 선택:

1-3. "Windows 업데이트" → "고급 옵션" 선택:

1-4. "Insider Preview 빌드 가져오기"의 "시작"을 선택:

1-5. "Insider Preview 빌드" 창에서 "등록"을 선택:

1-6. https://insider.windows.com/에 자동으로 연결 되는데, "시작하기"를 선택:

1-7. "이 계약 조건에 동의합니다(필수)."에 check한 후 "제출" 선택:

1-8. Web page를 닫는다:

1-9. 앞의 "설정" 창에서 "다음 단계"를 선택한다:

1-10. 확인을 위한 창들이 뜨는데, "다음", "확인"을 선택:

1-11. Reboot을 위한 창에서 "지금 다시 시작"을 선택:

1-12. "1-2" 단계와 같이 "설정" → "업데이트 및 복구" 창에서 "개발자용" → "개발자 모드"를 선택:

1-13. 확인을 위한 창이 뜨는데, "예"를 선택해서 개발자 모드를 켠다:

1-14. "1-3"의 "고급 옵션" 창에서, 아래와 같이 "Insider 수준"을 "초기"로 맞춘다 (선택 bar를 가장 오른쪽으로):

1-15. 이제 준비 완료. Windows 10 Insider Preview build는 Windows update로 받는 것임. 위의 설정을 적용하자 마자는 아래와 같이 "업데이트 확인"해도 Windows 10 Insider Preview build가 검지되지 않음 (나는 설정 다음 날에야 가능했음):

1-16. 아래 그림과 같이 "Windows 10 Insider Preview 14361"이 update되는 걸 확인해야 함 (아마도 14361보다 더 큰 version도 괜찮을 것임):

1-17. Update가 끝나면 "지금 다시 시작"을 선택해서 reboot:

1-18. Reboot이 끝나면 바탕화면 오른쪽 아래에 다음 그림과 같이 "평가본입니다."라고 나옴:

2. Bash on Windows를 활성화 하기 위해서 다음을 한다.

2-1. "제어판" → "프로그램" 선택:

2-2. "Windows 기능 켜기/끄기" 선택:

2-3. "Windows 기능" 창에서 "Linux용 Windows 하위 시스템(베타)"를 check한 후에 "확인"을 선택 (참고로 영어로는 "Windows Subsystem for Linux (Beta)" 임):

2-4. 다음 창이 뜨는데 "다시 시작"을 선택해서 reboot:

2-5. 완성.

3. Bash를 실행시켜 보려면 작업표시줄에 "bash"를 입력하고 Enter:



3-1. Bash를 처음 실행하면 다음과 같이 "동의", "사용자 이름", "암호 입력"을 진행한다 (글이 조금 깨지는데 beta니깐 이해하자):

3-2. 다음과 같이 bash가 Windows command-line처럼 실행된다:

참고:
  1. https://insights.ubuntu.com/2016/04/14/howto-ubuntu-on-windows-2/