Wednesday, 15 May 2013

Friday, 10 May 2013

Launch czt-ide from the Eclipse and Create a new project

1. After successful import and build of CZT in Ubuntu, we can launch the czt ide from the Eclipse.
  • Select the "net.sourceforge.czt.eclipse.repository" project, and right click the czt-ide.launch file, select the "Run As -> czt-ide"
  • An error about "-XstartOnFirstThread" is not a recognized option for java
  • Just open the Run configuration edit dialog and delete this option in the "Arguments -> VM Arguments"
  • Then launch again. Succeed.
2. Create a new project circus2bcsp
  • Create a new "Java Project" from the Eclipse
    • Input the name "Main" and Package "net.sourceforge.czt.circus2bcsp"
    • Copy the content of Main.java in z2b project and paste to Main.java in this project
  • There's some errors such as "import  net.sourceforge.czt.session.Filesource can be resolved"
  • Open the project properties of circus2bcsp, and go to the Project tab of Java Build Path, add the necessary projects to build together.
  • Then the error will be disappeared

Enable SSH X11Forwarding to access Ubuntu from the local Mac OS X

X11Forwarding config in ssh can enable the remote desktop access from the local client. This is a set up of access between Ubuntu server and local Mac Client.

1. Ubuntu Server
  • make sure the X11Forwarding option in /etc/ssh/sshd_config is set to yes. If not, set it to yes, and restart the sshd service by "sudo service ssh restart"
  • test X11Forwarding in server
    • Open a terminal in Ubuntu, and "ssh -v -X localhost" to establish the ssh connection with X11Forwarding. 
    • Check if there's a line with "Requesting X11 Forward" shown in the debug output
    • Check DISPLAY environment variables by "echo $DISPLAY" and it should be localhost:10.0
2. Mac OS X client
Reference: http://ruepprich.wordpress.com/2013/01/08/x11-forwarding-on-os-x-10-8-2-mountain-lion/
  •  Install  XQuarz for Mac OS
  • Open iTerm and add remote server to access list by "sudo xhost + 192.168.56.101"
    • There's an error about 'xhost: unable to open display ""' 
    • And ssh -X user@192.168.56.101 also failed to take X running
  • Open XQuarz, and open "Terminal" in Application Menu
    • bash-3.2$ xhost + 192.168.56.101
      192.168.56.101 being added to access control list
    • bash-3.2$ ssh -X rye@192.168.56.101
    • rye@rye-desktop:~$ echo $DISPLAY
      localhost:11.0
    • xclock works

Friday, 26 April 2013

Set up Java Development Environment for CZT (Community Z Tool) On Windows

Set up Java Development Environment for CZT (Community Z Tool) On Windows

Windows

Install JDK-1.7.0

  1. Install Directory
    • c:\Program Files\Java\jdk1.7.0_03
    • c:\Program Files\Java\jre7
  2. Set environment variables
    • Path=c:\Program Files\Java\jdk1.7.0_03\bin\;c:\Program Files\Java\jre7\bin\;
    • JAVA_HOME=c:\Program Files\Java\jre7\

Install maven-3.0.5 (>= 3.0.4)

  1. Download maven for Windows from http://maven.apache.org/download.cgi
  2. Unpack the tar package under d:\programs
  3. Add maven bin to environment variable PATH
    • PATH=d:\randall\Programs\apache-maven-3.0.5\bin\

Git clone czt code

    git clone git://git.code.sf.net/p/czt/code czt_code

Build CZT

  • Execute buildall.bat

Build Error

  1. Compilation Error #1
    ------- Error Log ------
    [INFO] -------------------------------------------------------------  
    [ERROR] COMPILATION ERROR :  
    [INFO] -------------------------------------------------------------  
    [ERROR] Unable to locate the Javac Compiler in:  
    c:\Program Files\Java\jre7\..\lib\tools.jar  
    Please ensure you are using JDK 1.4 or above and  
    not a JRE (the com.sun.tools.javac.Main class is required).  
    In most cases you can change the location of your Java  
    installation by setting the JAVA_HOME environment variable.  
    [INFO] 1 error  
    [INFO] -------------------------------------------------------------
    
    Solution: change JAVA_HOME to c:\Program Files\Java\jdk1.7.0_03\
  2. Build failed
    Line breaks (Windows only)
    On Windows, CZT expects Windows-style line breaks (CR+LF). The conversion is usually set by default (e.g. using msysgit) and nothing else is necessary. If, however, you encounter build problems with some CZT modules, try forcing the Windows line breaks using the following Git command in your repository:
    git config core.autocrlf true
    
    Then reset your Git repository to checkout correct line breaks:
    git rm --cached -r .
    git reset --hard
    
  3. Build Error

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 7:23.874s
    [INFO] Finished at: Tue Apr 23 10:45:24 BST 2013
    [INFO] Final Memory: 291M/784M
    [INFO] ------------------------------------------------------------------------
    [INFO] Scanning for projects...
    [WARNING] Error initializing: org.eclipse.tycho.p2.resolver.P2TargetPlatformReso lver@646d5273
    java.lang.RuntimeException: java.lang.IllegalStateException: Service is not regi
    stered class='interface org.eclipse.tycho.core.facade.ProxyServiceFacade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:301)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:275)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.p2.resolver.P2TargetPlatformResolver.initialize(P2T
    argetPlatformResolver.java:433)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.initializ
    e(PlexusLifecycleManager.java:338)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.manageLif
    ecycle(PlexusLifecycleManager.java:296)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.onProvisi
    on(PlexusLifecycleManager.java:148)
            at com.google.inject.internal.ProvisionListenerStackCallback$Provision.p
    rovision(ProvisionListenerStackCallback.java:108)
            at com.google.inject.internal.ProvisionListenerStackCallback.provision(P
    rovisionListenerStackCallback.java:55)
            at com.google.inject.internal.ProviderInternalFactory.circularGet(Provid
    erInternalFactory.java:68)
            at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(
    InternalFactoryToInitializableAdapter.java:45)
            at com.google.inject.internal.InjectorImpl$3$1.call(InjectorImpl.java:96
    5)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.ja
    va:1011)
            at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:961)
            at com.google.inject.Scopes$1$1.get(Scopes.java:59)
            at org.sonatype.guice.bean.locators.LazyBeanEntry.getValue(LazyBeanEntry
    .java:83)
            at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexus
    Bean.java:49)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:253)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:245)
            at org.eclipse.tycho.core.resolver.DefaultTargetPlatformResolverFactory.
    lookupPlatformResolver(DefaultTargetPlatformResolverFactory.java:74)
            at org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.setupP
    roject(DefaultTychoDependencyResolver.java:86)
            at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProj
    ectsRead(TychoMavenLifecycleParticipant.java:77)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:274)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:290)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:230)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:409)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    352)
    Caused by: java.lang.IllegalStateException: Service is not registered class='int
    erface org.eclipse.tycho.core.facade.ProxyServiceFacade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:291)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.osgi.configuration.OSGiProxyConfigurator.afterFrame
    workStarted(OSGiProxyConfigurator.java:30)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.doS
    tart(DefaultEquinoxEmbedder.java:180)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.sta
    rt(DefaultEquinoxEmbedder.java:67)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:299)
            ... 34 more
    [ERROR] Internal error: java.lang.RuntimeException: Could not instantiate requir
    ed component: com.google.inject.ProvisionException: Guice provision errors:
    [ERROR]
    [ERROR] 1) Error notifying ProvisionListener org.sonatype.guice.plexus.lifecycle
    s.PlexusLifecycleManager of org.eclipse.tycho.core.TargetPlatformResolver annota
    ted with @com.google.inject.name.Named(value=p2).
    [ERROR] Reason: java.lang.RuntimeException: java.lang.IllegalStateException: Ser
    vice is not registered class='interface org.eclipse.tycho.core.facade.ProxyServi
    ceFacade'
    [ERROR] while locating org.eclipse.tycho.core.TargetPlatformResolver annotated w
    ith @com.google.inject.name.Named(value=p2)
    [ERROR]
    [ERROR] 1 error
    [ERROR] role: org.eclipse.tycho.core.TargetPlatformResolver
    [ERROR] roleHint: p2
    [ERROR] -> [Help 1]
    org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeExcept
    ion: Could not instantiate required component
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:168)
            at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
            at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
            at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
    cher.java:290)
            at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
    a:230)
            at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
    uncher.java:409)
            at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
    352)
    Caused by: java.lang.RuntimeException: Could not instantiate required component
            at org.eclipse.tycho.core.resolver.DefaultTargetPlatformResolverFactory.
    lookupPlatformResolver(DefaultTargetPlatformResolverFactory.java:76)
            at org.eclipse.tycho.core.resolver.DefaultTychoDependencyResolver.setupP
    roject(DefaultTychoDependencyResolver.java:86)
            at org.eclipse.tycho.core.maven.TychoMavenLifecycleParticipant.afterProj
    ectsRead(TychoMavenLifecycleParticipant.java:77)
            at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:274)
            at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
            ... 11 more
    Caused by: org.codehaus.plexus.component.repository.exception.ComponentLookupExc
    eption: com.google.inject.ProvisionException: Guice provision errors:

    1) Error notifying ProvisionListener org.sonatype.guice.plexus.lifecycles.Plexus
    LifecycleManager of org.eclipse.tycho.core.TargetPlatformResolver annotated with
     @com.google.inject.name.Named(value=p2).
     Reason: java.lang.RuntimeException: java.lang.IllegalStateException: Service is
     not registered class='interface org.eclipse.tycho.core.facade.ProxyServiceFacad
    e'
      while locating org.eclipse.tycho.core.TargetPlatformResolver annotated with @c
    om.google.inject.name.Named(value=p2)

    1 error
          role: org.eclipse.tycho.core.TargetPlatformResolver
      roleHint: p2
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:257)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:245)
            at org.eclipse.tycho.core.resolver.DefaultTargetPlatformResolverFactory.
    lookupPlatformResolver(DefaultTargetPlatformResolverFactory.java:74)
            ... 15 more
    Caused by: com.google.inject.ProvisionException: Guice provision errors:

    1) Error notifying ProvisionListener org.sonatype.guice.plexus.lifecycles.Plexus
    LifecycleManager of org.eclipse.tycho.core.TargetPlatformResolver annotated with
     @com.google.inject.name.Named(value=p2).
     Reason: java.lang.RuntimeException: java.lang.IllegalStateException: Service is
     not registered class='interface org.eclipse.tycho.core.facade.ProxyServiceFacad
    e'
      while locating org.eclipse.tycho.core.TargetPlatformResolver annotated with @c
    om.google.inject.name.Named(value=p2)

    1 error
            at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:974)
            at com.google.inject.Scopes$1$1.get(Scopes.java:59)
            at org.sonatype.guice.bean.locators.LazyBeanEntry.getValue(LazyBeanEntry
    .java:83)
            at org.sonatype.guice.plexus.locators.LazyPlexusBean.getValue(LazyPlexus
    Bean.java:49)
            at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContai
    ner.java:253)
            ... 17 more
    Caused by: java.lang.RuntimeException: java.lang.IllegalStateException: Service
    is not registered class='interface org.eclipse.tycho.core.facade.ProxyServiceFac
    ade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:301)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:275)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.p2.resolver.P2TargetPlatformResolver.initialize(P2T
    argetPlatformResolver.java:433)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.initializ
    e(PlexusLifecycleManager.java:338)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.manageLif
    ecycle(PlexusLifecycleManager.java:296)
            at org.sonatype.guice.plexus.lifecycles.PlexusLifecycleManager.onProvisi
    on(PlexusLifecycleManager.java:148)
            at com.google.inject.internal.ProvisionListenerStackCallback$Provision.p
    rovision(ProvisionListenerStackCallback.java:108)
            at com.google.inject.internal.ProvisionListenerStackCallback.provision(P
    rovisionListenerStackCallback.java:55)
            at com.google.inject.internal.ProviderInternalFactory.circularGet(Provid
    erInternalFactory.java:68)
            at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(
    InternalFactoryToInitializableAdapter.java:45)
            at com.google.inject.internal.InjectorImpl$3$1.call(InjectorImpl.java:96
    5)
            at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.ja
    va:1011)
            at com.google.inject.internal.InjectorImpl$3.get(InjectorImpl.java:961)
            ... 21 more
    Caused by: java.lang.IllegalStateException: Service is not registered class='int
    erface org.eclipse.tycho.core.facade.ProxyServiceFacade'
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:291)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.get
    Service(DefaultEquinoxEmbedder.java:270)
            at org.eclipse.tycho.osgi.configuration.OSGiProxyConfigurator.afterFrame
    workStarted(OSGiProxyConfigurator.java:30)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.doS
    tart(DefaultEquinoxEmbedder.java:180)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.sta
    rt(DefaultEquinoxEmbedder.java:67)
            at org.eclipse.sisu.equinox.embedder.internal.DefaultEquinoxEmbedder.che
    ckStarted(DefaultEquinoxEmbedder.java:299)
            ... 34 more
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
    ch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please rea
    d the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/InternalErrorE
    xception
    Press any key to continue . . .


Solution: ignore this error at that moment since all builds are successful

Import project into Eclipse

Reference: http://czt.sourceforge.net/dev/eclipse/index.html
  1. Download Eclipse Classic 4.2.0
  2. Install m2e connectors
    • install maven-jflex-plugin and xml-maven-plugin from http://czt.sourceforge.net/dev/eclipse/updates/
  3. Install m2e release for Eclipse
    • from http://download.eclipse.org/technology/m2e/releases
  4. Select the m2e repository cache directory. m2e has caches lucene index in two places
    • Per-workspace indexes are stored under .metadata/.plugins/org.eclipse.m2e.core/nexus
    • and there is also global cache in ~/.m2/repository/.cache/m2e/${m2e.version}
  5. The default cache directory on Windows in the department is the home directory h:\.WindowsProfile\.m2\. However, this folder has very strict limitation of disk volumn. Thus the cache directory has to be changed.
    • Open Eclipse preference, click Maven/Installation. Add external Maven d:\randall\Programs\apache-maven-3.0.5, and unselect the Embedded 3.0.4
    • The settings.xml file will be in d:\randall\Programs\apache-maven-3.0.5\conf. Open settings.xml, and change <localRepository> to <localRepository>d:\.m2\repository</localRepository>
    • Save the changes in Eclipse
  6. Open a command prompt window and rebuild the czt-code again
    • buildall.bat
    • Now all cached files are saved in the specified directory, and can build successfully
    • Thus the previous Build Error with long error log is due to the limited size of cache repository
  7. After the build, open Eclipse and import the czt projects into the Eclipse by File > Import > Existing Maven Projects
    • Select the czt-code root directory and import all necessary projects
    • After import, workspace will build automatically
    • Set CZT target platform
      • Open target definition file at /net.sourceforge.czt.eclipse.target/net.sourceforge.czt.eclipse.target.target within Eclipse and clock Set as Target Platform
    • If necessary, right click the project and Maven > Update Projects to update Maven projects
    • If necessary, clean all projects and build again

Wednesday, 24 April 2013

Setup of a notes writing environment (markdown + Voom + markdown2.py) on Windows

This is a note to write down how to set up a working environment for notes writing efficiently on Windows

Environment Requirement

  • VIM editor
  • markdown syntax
  • Voom outline
  • markdown2.py to convert from mkd to html for easily publishing on blog

Install markdown syntax

Install Voom

Install python27 on Windows

  • Install python27 to C:\python27
  • Add this directory to the PATH environment variable

Install distribute package to have the packages installation capability (such as pip, easy_install )

Install markdown2

markdown2.py is used to convert the mkd file to html file - Open a command prompt window, and type
easy_install markdown2 - Then markdown2.py is installed in the c:/python27/scripts

Test it

  • Create a mkd file and write a sample markdown note by VIM
  • You should see the syntax works for this file. If not, add "syntax on" vimrc file
  • Type command ":Voom markdown" within VIM, and another outline window is opened
  • Quit Vim and open a command prompt window, and type
    markdown2.py hello.mkd
  • Error
    close failed in file object destructor: sys.excepthook is missing lost sys.stderr
  • Solution: use "python c:\python27\Scripts\markdown2.py hello.mkd > hello.html" instead of "markdown2.py hello.mkd > hello.html"

Saturday, 20 April 2013

Concurrency, Parallel, Synchronization and Reactive. How to distinguish them?

Parallel and Concurrent

Parallel

Parallel computing is a form of computation in which many calculations are carried out simultaneously,[1] operating on the principle that large problems can often be divided into smaller ones, which are then solved concurrently ("in parallel"). (from Wikipedia)

Key points of Parallel:

  • Usually for time saving and speeding up the calculation
  • Decompose the big problem into smaller ones
  • The smaller ones run in different processors at the same time
  • Reference: https://computing.llnl.gov/tutorials/parallel_comp/#Whatis

Three-level Parallelisms:

  • Bit-level (4-bit, 8-bit, 16-bit, 32-bit and 64-bit microprocessors)
  • Instruction-level (pipelining (CISC, RISC), superscalar)
  • Task-level (multi-processors, tasks running on different processors simultaneously)

Task Parallelism and Data Parallelism:

  • Task Parallelism (processes, or threads of execution)

"entirely different calculations can be performed on either the same or different sets of data"

  • Data Parallelism

"the same calculation is performed on the same or different sets of data"

Concurrent

Concurrency is a property of systems in which several computations are executing simultaneously, and potentially interacting with each other. (from Wikipedia)

a program is typically factored into multiple threads of control with distinct responsibilities and purposes, which may run simultaneously or take turns. This is often about dealing with concurrency and nondeterminism in the world, or about reducing latency.

Key points of concurrent programming:

  • It may run simultaneously on different processors or multithreads on single processor
  • the number of possible execution paths in the system can be extremely large and the resulting outcome can be nondeterministic
  • Concurrent access of shared resources with nondeterminism may lead to issues such as deadlock and starvation
  • What differentiates concurrent system from sequential system most is the fact that their subprocesses communicate with each other

The difference between parallel and concurrency programming

Parallel and concurrent are synonyms in most cases, but in programming, it's not the case. They are totally different concepts.

Example (Parallel and Concurrent programming in Haskell)

A parallel program

  • utilize the more powerful and computational hardware (e.g. multiple processors or cores) to make it quickly and achieve more efficiency
  • A big task is splitted into several smaller tasks, and each of them is executed in different processor or core at the same time (in parallel). Thus the whole delivery time will be shorter than sequentially performed task

Concurrent program

  • concurrency is a progarm-structuring technique in which there are multiple threads of control.
  • From the user level, threads are executed "at the same time" because their effects interleaved. But whether they actually execute at the same time or not is not a design problem, and just an implementation detail.
  • concurrency can be implemented on one single process with multithreads or on multiple processors
  • concurrent programming also concerns program-structuring to interact with multiple independent external agents (for example, one thread responsible for the user, one for database server, and another for external clients)

Distributed, Reactive and Concurrent System

Distributed System

A distributed system consists of multiple computers that communicate through a computer network, and the computers interact with each other in order to achieve a common goal

For example,

  • a lithography has several subsystems, and each subsystem runs on its individual embedded system. They are working with central workstation together to achieve the function of the lithography

Reactive System

A system that responds or reacts to external events

For example,

  • a motor control driver: it gets the input from the caller or user, then move the motor forward or backward to specified position, and stop
  • interactive system is a kind of typical reactive system, which reacts to its user and operators, and provides the feedback

Concurrent System

several computations are running simultaneously and may interact with each other while they are executing.

Architectural Aspect

  • Each computer in distributed system has the individual processor and memory
  • A parallel system will have the tasks on different processors with shared memory, such as SMP or AMP system
  • A concurrent system may have the multiple threads on a single processor or multiple processors with shared memory

Synchronization

Synchronization refers to one of two distinct but related concepts: synchronization of processes, and synchronization of data. Process synchronization refers to the idea that multiple processes are to join up or handshake at a certain point, in order to reach an agreement or commit to a certain sequence of action. Data synchronization refers to the idea of keeping multiple copies of a dataset in coherence with one another, or to maintain data integrity. (from Wikipedia)

CSP (Communicating Sequential Processes)

is a formal language for modelling and reasoning the patterns of interaction in concurrent system

  • interaction by synchronous message passing

Parallel

  • Synchronous Parallel (P || Q)
  • Alphabetised Parallel (P [ Ap || Aq ] Q)
  • Generalised Parallel (P [ | a | ] Q, such as P [| {| in, out |} |] Q)
  • Interleaving |||

Friday, 12 April 2013

Use VIM to make notes [markdown]

Sometimes you will face a situation that you want to write down some notes, but you can not have a suitable tool on handle. For example, you only have VIM to edit and don't have the "Notes" like Evernote, OneNote etc. So how can you make writing down a note easy? Here's one solution: VIM + Voom + markdown syntax highlight

Source file of this post is reference to markdown.mkd, One screen show:

 

Markdown

Markdown is intended to be as easy-to-read and easy-to-write as is feasible. Markdown’s syntax is intended for one purpose: to be used as a format for writing for the web.
Reference: <http://daringfireball.net/projects/markdown/syntax>

Syntax

Header

Two types of header: Setext and atx
  • Setext
    = for 1st level
    • for 2nd level
  • atx
    # for H1
    ## for H2
    ### for H3
    #### for H4
    ##### for H5
    ###### for H6

Block Quotes

  • Use the > for each line or only > for each paragraph
Quote Block or
  • can be nested
Quote
Block

Bullets

  • *, - and + all do the same

Numbering

  1. 1 Use the number
  2. 2
  3. 3

Codeblocks

Indent with 4 spaces or one tab. C Example: for(i = 0; i \< 5; i++) { printf("%d\n", i); }

Horizontal Rules

  • three or more (*, -, or _)



Links

Emphasis

Text wrapped in * and _
  • Markdown is very helpful to make notes
  • Markdown is very helpful to make notes

Code

Wrap the code with backtick quotes (`) * printf() function will print on the stardard output 0

Special characters

The special characters (\, `, *, _, -, {}, ], (), #, +, ., !) can be inputted by a prefix backslash \

Markdown syntax highlight

Installation

  • It's very easy to install it. Just download the latest the markdown-.vba.gz, then
    $ vim makedown-.vba.gz +":so %"
    Reference: http://www.vim.org/scripts/script.php?script_id=2882
  • Make sure the syntax highlight is on and can be set in .vimrc syntax on filetype on

Usage

Just create a new file with extension 'mkd', for example $ vim hello.mkd

Voom - Two-pane outliner

Installation

Usage

  • Load the markdown format file, such as hello.mkd
  • Open Voom markdown markup formats within VIM : Voom markdown

Markups supported

Voom can support a variety of markups - fmr, fmr1, fmr2 -- start fold markers with levels (variations of the default mode);
- wiki -- MediaWiki, headlines are surrounded by '=';
- vimwiki -- vimwiki plugin (vimscript #2226);
- viki -- Viki/Deplate plugin (vimscript #861);
- org -- Emacs Org-mode;
- rest -- reStructuredText section titles;
- markdown -- Markdown headers, both Setext-style and Atx-style;
- hashes -- #, ##, ###, etc. (Atx-style headers, a subset of Markdown format);
- txt2tags -- txt2tags titles and numbered titles;
- asciidoc -- AsciiDoc document and section titles, both styles;
- latex -- LaTeX sectioning and some other commands;
- taskpaper -- TaskPaper (vimscript #2027);
- thevimoutliner -- The Vim Outliner plugin (vimscript #517);
- vimoutliner -- VimOutliner plugin (vimscript #3515);
- cwiki -- vimscript #2176;
- html -- HTML heading tags, single line only;
- python -- Python code browser, blocks between 'class' and 'def' are also nodes.

Convert to html

Installation of python-markdown

  • MAC OS: $ sudo easy_install Markdown

Command line

$ markdown_py -f hello.html hello.mkd
Notes: two spaces in the end of line means EOL