Welcome to MSDN Blogs Sign in | Join | Help

Physics e-Learning Portal - Envisioning

I am working to help some of physicists who run KucingFisika, to design their future multimedia e-learning site with Silverlight. From animation perspective, I am considering to use Farseer Physics Games engine. You can see some demos from icons below. Please go to Codeplex to download Farseer Physics.

001  002  003

The next step for me is to develop end-to-end solution architecture in managing RIA based application like this. After looking around for design practices, I found that Microsoft .NET RIA Services is good as our base line. This is now available and you can download and later explore it like I do. In this post, I would like to encourage you to see that we can add additional scenarios, making RIA Services really applicable in limited bandwidth condition – adding offline feature. From marketing point of view:

Microsoft .NET RIA Services simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms. RIA Services provides a pattern to write application logic that runs on the mid-tier and controls access to data for queries, changes and custom operations. It also provides end-to-end support for common tasks such as data validation, authentication and roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier.

From technical point of view (you can read more from its PDF documentation). It is a framework that provides patterns for writing LOB application logic and validation (by design). LOB applications use data that needs to flow across tiers. It may be created and used through basic CRUD operations or it may be accessed through domain-specific custom operations in encapsulated form such as an approval operation. In an internet application, there is a trust boundary between the client and the mid-tier server. Hence, it is important to have a stylized way to express what resources are available to the client tier and what operations are permitted. In addition to defining the resources and operations, a developer needs to validate the data as it is created or updated. The validation needs to run on the presentation tier for giving immediate feedback to the user and on the mid-tier for ensuring that the rules defined for the application are enforced. Thus, there may be common validation across the tiers as well as tier-specific validations that need to be integrated with the resources and operations.

v01

Lets look at the anatomy of a common Web application compared to RIA. With a RIA, most of the presentation logic moves to the client to improve the UX and to make effective use of local state. The result is additional work for the developer: defining a full-fledged services layer, new types and contracts to share etc. and continually evolving them as the app evolves on either end. A RIA isn't just a client app, but an "Internet" app that includes a server component. This is where RIA Service guidance will give you values – end-to-end pattern for this additional work. But remember, there is no perfect design/pattern, we can always improve it based on our requirements.

 

v02     v03

The first part of RIA Services pattern is to write a DomainService class. This represents your application domain, your application logic, or business logic, a set of operations – CRUD based or custom domain-specific, DAL specific, authorization and validation. A DomainService is optimized to be stateless - to respond to query requests and to change set processing requests.

v05v06

The second part of the pattern is what we generate - the client-side data model - in a DomainContext class. This class represents the view of what the client can see. It contains lists of objects, one for each type exposed to the client, and it contains a set of load methods that roughly correspond to the queries exposed on the service. These load methods can be used to load objects into the corresponding lists. The individual objects and lists track changes and raise change notifications. The DomainContext can extract all the changes, create a change set and submit it to the service for processing and committing. A DomainContext is optimized for taking advantage of the stateful environment and to be a well-behaved citizen in a binding-centric presentation technology such as Silverlight or WPF.

Nikhil Kothari describe .NET RIA Services vision as RAD for RIA, which is I totally agreed and have the same sense.But there is one requirement here in Asia that we must consider – low bandwidth condition. This will rise new scenario - offline-enabled RIA application, means that we need to add local storage scenario for the DomainContext. The design challenges of all the offline-enabled applications are:

 

How to isolate client data layer

What is actually the data layer in RIA? It that the API that server exposes to AJAX? Gears provides a good vision on Server Data Layer and Local Data Layer, controlled by a Data Switch. Gears propose JavaScript DB API with SQLite to enable local data storage. It is a good project to start with SQL Compact Edition, however, but an ActiveXObject should be created for SQL Compact Edition/SQL Express/ESENT. Anyone interested here?

v07

Offline strategy – what features need offline scenario

This is the harder part for me, as closely related to our application scenarios. Some numerical calculation should be done at client side and its results should be store locally in order to feed parameters for responsive and dynamic GUI animation. You might think that you would always want to use the local store since it is faster. However, there are many practical reasons why you may want or need to access the data on server instead. For instance:

- Data may be so transient in nature that it makes no sense to cache it. I will use Project Velocity for cache anyway.
- Some Simulation's data makes sense only while online.
- The App may choose to store only the most frequently accessed data.
- Numerical computational and/or disk space requirements make it unfeasible to recreate the feature offline.

Typically, the optimal solution is to use the local store as much as possible, since it's usually faster than a remote connection. However, the more work an application does locally, the more code you need to write to implement the feature locally and to synchronize the corresponding data. There is a cost/benefit tradeoff to consider, and some features may not be worthwhile to support locally.


In fact, .NET RIA Service provide ready to extend set of capability that I like. But, a lot of work should be done to make it work like I want. That is my problem though :).

 

Application Modality

What is modality – feature to switch from online to offline states or vice versa. Modal applications usually indicated through some change in the UI. The user is made aware of the state and participates in switching states in some manner. Modeless applications attempt to transition seamlessly between online and offline states, without significant UI changes. The user does not need to participate in switching states, which the application does automatically.

In a modal application, when the application is online it communicates with the server. When it's offline, it uses the local store. Data must be synchronized when the app switches between modes. The advantage of making a modal application is that it's “relatively simple” to implement and therefore a reasonable way to bootstrap the application to function offline. But some disadvantages are: The user must decide and remember to switch modes. Since the local store is not always up-to-date, it can't be used to improve the application's responsiveness when connected to the server.

 

Data Synchronization

What is the sync strategy for this kind of application? No matter which connection and modality strategy we use, the data in the local database will get out of sync with the server data. For example, local data and server data get out of sync when:

- The user makes changes while offline
- Data is shared and can be changed by external parties
- Data comes from an external source

There are many approaches to synchronization and none are perfect for all situations. We have Microsoft Sync Framework and Astroria Offline as candidates for reusable framework here (where I am still arguing). The most important thing for engineer to decide is manual or background synchronization. In manual sync user decides when to synchronize. It can be implemented simply by uploading all the old local data to the server, and then downloading a fresh copy from the server before going offline. In background sync, the application continuously synchronizes the data between the local data store and the server. This can be implemented by pinging the server every once in a while or better yet, letting the server push or stream data to the client. With Silverlight supports on WCF, this should be easy to implement.

v08

Well, the next step for me is to gather our detail requirements and see how current frameworks can help. I am still hacking the MSF, Astoria Offline, RIA Services, and Velocity. For sure, I will share with you if I found interesting things.

 

Hope this helps!

 

Cheers – RAM

Posted by Mattotorang | 1 Comments

MS-MPI with Visual Studio 2008

This is a step-by-step guide for you to write MPI program using MS-MPI and Visual Studio 2008. I want to introduce MS-MPI as many of my blog posts will be related to parallelism both shared memory and distributed in C/C++ and C#. You can use any OS to write, compile and test MPI program and in additional to that, and of course you also need:

- HPC Pack SDK 2008
- VC++ Compiler and IDE (VC++ 2008 Express is okay)

What you have to know in this SDK is the location of MPI header and lib files. MPI header file (mpi.h) contains all the definitions of MPI types and operations, while the lib file is the main MPI libraries. By default HPC Pack SDK installation, it will be located at :

C:\Program Files\Microsoft HPC Pack 2008 SDK\ in the Include and Lib folders.

Once you able to locate MS-MPI header and lib files, you are ready to write and compile MPI program using Visual Studio 2008. Open VC++ 2008 and create an empty C++ project then follow these steps.

1 – Create an Empty C++ Project

 MPI03

2 – Change the Linker’s System configuration to CONSOLE(/SUBSYSTEM:CONSOLE)

MPI04

3 – Add Linker Additional Library Directories as following:

MPI05

4 – Add Linker’s Input Additional Dependencies. Type msmpi.lib to the list.

MPI06

5 – Add a C++ file to write your first MPI program and write the following codes as a test:

#include<iostream>
#include<mpi.h>
using namespace std;

int main(int argc, char** argv){

    int mynode, totalnodes;

    MPI_Init(&argc, &argv); 
    MPI_Comm_size(MPI_COMM_WORLD, &totalnodes);
    MPI_Comm_rank(MPI_COMM_WORLD, &mynode);
    
    cout << "Hello world from process " << mynode;
    cout << " of " << totalnodes << endl;

    MPI_Finalize();
    return 0;
}

6 – Add the location of header file to C++ Compiler property:

MPI07


7 – Build your first program and if no error found, you can test it by running MPIEXEC (MPI launcher) :

mpiexec –n 10 MyMPIProject.exe

It will create 10 independent processes (you can say 10 nodes), without communication between nodes applied for now. I will discuss later about the inter-process communication inside MPI. The normal result of your program will be:

MPI08

Congratulation is you reach this stage. You are ready to learn deeper about MS-MPI!.

Cheers – RAM

Posted by Mattotorang | 5 Comments

Books on MPI (and Windows)

If you're serious about MPI, you'll need parallel computing background (mostly from scientific) and the official standard for understanding the fussy details of MPI APIs. There are many books about those two things in the market, if you go to Amazon and search for MPI keyword, you will get it all. Here is my recommendation:

Theoretical and Scientific Background

BooksMPI04 BooksMPI05 BooksMPI06


For practical programmers

MPIBooks01 BooksMPI02 BooksMPI01

I always believe that bottom-up learning approach is the best way to learn programming. MPI is not really complex APIs, but you will not program in vacuum. Understanding about computer architecture and Windows APIs itself will be a great asset. For you who want to advance your native Win32 (Windows API), I would recommend my current readings:

WIN01 Win02 WIN03


I hope you enjoy MPI exploration like I do.

Happy learning – RAM

Posted by Mattotorang | 1 Comments

MPI.NET – MPI for Managed Codes

In this post, I would like to introduce you MPI.NET from Indiana University. You can download MPI.NET here including its runtime, SDK and source codes then follow this post. You do not need to have a Windows cluster or even a multi-core/multi-processor workstation to develop MPI programs: you can use any desktop machine with Windows XP, Vista or Windows Server 200x to develop MPI programs with MPI.NET.

In development, you will also need Visual Studio 2005/2008 and MS-MPI. Why MS-MPI? Because MPI.NET can only work with MS-MPI that you can get freely from Microsoft HPC Pack 2008 SDK (or Microsoft Compute Cluster Pack SDK). I prefer to use the HPC Pack 2008 SDK because it has newer version of MS-MPI (version 2). In order to use your future MPI.NET in a cluster, MPI.NET runtime must be installed on the cluster nodes.
 
Now let see a C# program to calculate PI with the following algorithm:

Inscribe a unit circle within a unit square, and then randomly throw darts within the unit square. The ratio of the number of darts that land within the circle to the number of darts that land within the square is the same as the ration of the area of the circle to the area of the square, and therefore can be used to compute PI.

Using this principle, the following sequential program computes an approximation of PI: 

using System;

class SequentialPi
{
    static void Main(string[] args)
    {
        int dartsPerProcessor = 10000;
        Random random = new Random();
        int dartsInCircle = 0;
        for (inti = 0; i<dartsPerProcessor; ++i)
        {
            double x = (random.NextDouble() - 0.5) * 2;
            double y = (random.NextDouble() - 0.5) * 2;
            if (x * x + y * y <= 1.0)
                ++dartsInCircle;
        }

        Console.WriteLine("Pi is approximately {0:F15}.",
                          4*(double)totalDartsInCircle/(double)dartsPerProcessor);
    }
}

What MPI Can Do To Parallelize The Codes?

In a message-passing system like MPI, different concurrently-executing “processes” communicate by sending/receiving messages from one to another over a network. Each of the MPI processes has its own, local program state that cannot be observed or modified by any other process except in response to a message.  Most MPI programs are written with the Single Program, Multiple Data (SPMD) parallel model, where each of the processes is running the same program but working on a different part of the data. MPI allows us to launch the same program across many nodes with single command. Initially, each of the processes is identical, with one distinguishing characteristic: each process is assigned a rank, which uniquely identifies that process. The ranks of MPI processes are integer values from 0 to P-1, where P is the number of processes launched as part of the MPI program. MPI processes can query their rank, allowing different processes in the MPI program to have different behavior, and exchange messages with other processes in the same job via their ranks.

Now look on PI sequential program, the more darts we throw, the better the approximation to PI. To parallelize this program, we'll utilize MPI to run several processes, each of which will throw darts independently. Once all of the processes have finished, we'll sum up the results (the total number of darts that landed inside the circle on all processes) to compute PI. The complete code for the parallel calculation of PI is as following:

using System;
using MPI; 
// add reference to message passing interface namespace before add this line

class ParallelPI
{
    static void Main(string[] args)
    {
        int dartsPerProcessor = 10000;
        using (new MPI.Environment(ref args))
        {
            if (args.Length > 0)
                dartsPerProcessor = Convert.ToInt32(args[0]);
            Intracommunicator world = Communicator.world;
            Random random = new Random(5 * world.Rank);
            int dartsInCircle = 0;
            for (int i = 0; i < dartsPerProcessor; ++i)
            {
                double x = (random.NextDouble() - 0.5) * 2;
                double y = (random.NextDouble() - 0.5) * 2;
                if (x * x + y * y <= 1.0)
                    ++dartsInCircle;
            }

            if (world.Rank == 0)
            {
                int totalDartsInCircle = world.Reduce<int>(dartsInCircle, Operation<int>.Add, 0);
                System.Console.WriteLine("Pi is approximately {0:F15}.",
                    4*(double)totalDartsInCircle/(world.Size*(double)dartsPerProcessor));
            }
            else
            {
                world.Reduce<int>(dartsInCircle, Operation<int>.Add, 0);
            }
        }
    }
}

1st step in MPI program is to initialize MPI environment by creating a new instance of MPI.Environment within Main method, passing the new object a reference to our command-line arguments. The entire MPI program should be contained within the using statement, which guarantees that the MPI environment properly created and disposed. All valid MPI programs must both initialize and finalize the MPI environment. Reference to command-line arguments, args, is ok because some MPI implementations are permitted to use special arguments to pass state information in to the MPI initialization routines.

After MPI environment initialized, then we can create Communicator object.  MPI communicators are the fundamental abstraction that permits communication among different MPI processes, and every non-trivial MPI program will make use of some communicators. Each communicator representations a self-contained communication space for some set of MPI processes. Any of the processes in that communicator can exchange messages with any other process in that communicator, without fear of those messages colliding with any messages being transmitted on a different communicator.

The PI program above is very simple because we used basic skeleton of MPI program to separate the process from rank 0 and other ranks. The skeleton of giving one of the processes (which is often called the "root", and is typically rank 0) a slightly different code path than all of the other processes is relatively common in MPI programs, which often need to perform some coordination or interaction with the user. Then there are two properties of communicators we used in our PI program: the rank of the process within the communicator, which identifies that process (world.Rank), and the size of the communicator, which provides the number of processes in the communicator (world.Size).

Intraommunicator world = Communicator.world;
if (world.Rank == 0)
{
    // program for rank 0 (root process)
}
else // not rank 0
{
    // program for all other ranks
}

As mentioned before, to parallelize PI program, we used MPI to run several processes, each of which will throw darts independently. Once all of the processes have finished, we'll need to sum up the results. In MPI, there are several parallel reduction operations that combine the values provided by each of the processes into a single value that somehow sums up the results. The most basic reduction operation is the Reduce collective, which combines the values provided by each of the processes and returns the result at the designated root process.  We used world.Reduce() in our PI program, which is reduce collective algorithm, to combine values stored in each process into a single value available at root process (rank 0) :

world.Reduce<int>(dartsInCircle, Operation<int>.Add, 0);


Now we can compile PI program then try to run it using MPIEXEC launcher (inside HPC Pack 2008 or MPICH2). For example we want to run the codes in 10 processes, just type:

MPIEXEC –n 10 ParallelPI.exe


Cheers – RAM

Posted by Mattotorang | 1 Comments

MS-MPI and HPC Pack 2008 SDK

The best known implementation of the MPI specification is the MPICH2 maintained by Argonne National Laboratory. MPICH2 is an open-source implementation of the MPI2 specification that is widely used on HPC clusters. MS-MPI is based on and designed for maximum compatibility with the MPICH2 reference implementation. It was shipped within HPC Pack 2008 SDK.

The exceptions to compatibility with MPICH2 are on the job launch and job management side of MPICH2; the APIs are identical to MPICH2. MS-MPI exceptions to the MPICH2 implementation were necessary to meet the strict security requirements of Windows HPC Server 2008 (including integration to Active Directory and System Center Manager). MS-MPI includes a complete set of MPI2 functionality as implemented in MPICH2 with the exception of dynamic process spawn and publishing. In addition, MS-MPI supports lower latency, shared-memory communications. The shared-memory communications implementation, which has been completely rewritten for Windows HPC Server 2008, improves the overall efficiency of communications between cores—especially when an application is using both shared memory and networked communication—and reduces the CPU cost associated with message passing between cores. When combined with the new NetworkDirect MS-MPI interface and the new networking stack in Windows Server 2008, the result is a significantly more efficient HPC cluster.

MS-MPI uses the Microsoft NetworkDirect protocol for maximum compatibility with high-performance networking hardware and maximum networking performance. MS-MPI can use any Ethernet connection that is supported by Windows Server 2008, as well as low-latency and high-bandwidth connections such as InfiniBand, 10-Gigabit Ethernet, or Myrinet. Windows HPC Server 2008 also supports the use of any network connection that has either a NetworkDirect or Winsock Direct provider. Gigabit Ethernet provides a high-speed and cost-effective interconnect fabric, while InfiniBand, 10-Gigabit Ethernet, and Myrinet are ideal for latency-sensitive and high-bandwidth applications. The NetworkDirect protocol bypasses Windows Sockets (Winsock) and the TCP/IP stack, using Remote Direct Memory Access (RDMA) on supported hardware to improve performance and reduce CPU overhead.

 MPI01 mshpcsdk_horz
HPCKit 

HPC Kit 2008 is a great collection of technical documents, presentations and training for developer and IT Professionals. Everything you need to get started with Windows HPC Server 2008 in one convenient place. Download here.

Windows HPC Server 2008 includes the Microsoft HPC Pack 2008 SDK that currently contains:
- MPIEXEC                                      : MPI Application Launcher
- SMPD                                           : MPI Process Manager
- MPISYNC                                      : MPI Trace Clock Synchronizer
- Microsoft.Hpc.VSDeployTool         : MPI Deployment Tools for Visual Studio
- ELT2CLOG and ETL2OTF              : MPI ETL Trace Converter
- MPI Scheduler API DLLs
- MPI Header and Library Files for i386 and AMD64
- Network Direct Service Provider Interface
 
We can use to Scheduler API to write client applications that interact with the job scheduler but note that we can use the SDK to schedule jobs on Microsoft HPC Server 2008 and later servers only; we cannot use this SDK to schedule jobs on Microsoft Compute Cluster Server 2003 (CCS).   

Please start to download the HPC Kit 2008 and explore about parallel computing using MS-MPI. I will post more tutorial about parallelism on Microsoft platform in this MSDN community. Stay tuned!


Cheers – RAM

Posted by Mattotorang | 1 Comments

Introduction to MPI

Message Passing Interface (MPI) is a portable programming model used widely on parallel computers, especially Scalable Parallel Computers (SPCs) with distributed memory, and on Networks of Workstations (NOWs). Many vendors have their own implementation of MPI, including Microsoft with its MSMPI, Intel, and HP. I am happy that Microsoft finally released Windows HPC Server 2008 with its MSMPI Sept 2008.

In this post, I would like to introduce you to MPI using MPICH2 from Argonne National LAB before jumping into detail of MSMPI inside Windows HPC Server 2008. Learning directly from MPICH2 is good foundation for you because MPICH2 is distributed as source (open-source and free license) and has been tested on several platforms, including Windows (32 and 64 bit). MPICH2 documentations are freely available here too. My goals in this post is to explain you how to start with MPICH2 and create your first MPICH2 C++ program. 

What you need to do is download and install MPICH2 first, then you will have all the header files (*.h), libraries (*.lib) and MPIEXEC.EXE to run jobs. Before you do that, please install the MPICH2 Process Manager by running SMPD.EXE –install. There are many other options for SMPD that you can learn from –help option. SMPD will be installed as Windows Services and you can manage it using SMPD.EXE tool itself or using services.msc.

The MPI-2 Standard describes MPIEXEC as a suggested way to run MPI programs. Sample form of a command to start an MPI job is MPIEXEC -n 32 [yourprogram], which means you want to start your program with 32 processes (providing an MPI COMM WORLD of size 32 inside the MPI application). The -configfile argument allows one to specify a file containing the specifications for process sets on separate lines in the file. This makes it unnecessary to have long command lines for MPIEXEC. Please refer to MPICH2 User Guide about all options of MPIEXEC. In Windows HPC 2008 Server, you will have nicer MPI launcher to help you run MPI programs.


Compiling MPICH2 Source Codes in Windows Server 2008

Now lets learn how to compile the MPICH2 from its source codes. You will need Perl to do that because mpi.h and other header files will be generated automatically using Perl script. I am using Windows Server 2008 x64 with Visual Studio 2008 installed and ActivePerl. To enable you compile MPICH2 source codes, download and extract its source codes from Argonne LAB, then run a file called winconfigure.wsf. That script will generate required header files depend to your configuration. Once finished, open the visual studio solution project (*.sln) and try to compile. I believe you will find around 50 errors of:

_vsnprintf': attributes inconsistent with previous declaration   

in your first compilation, to solve it, please find the following config header (I’m using x64):

..\MPICH2-1.0.8\src\include\win64\mpichconf.h

Then change the codes like below:

#if not defined(_MSC_VER) || defined(__MINGW32__)
   #define snprintf _snprintf
   #define vsnprintf _vsnprintf
#endif


If you are using 64 bit machine like me, make sure you change the include directory that contains mpich2conf.h in all projects properties (initially in win32 folder) then you can try to compile ch3sock, ch3shm, ch3sshm, ch3ssm, and ch3ib projects (release or debug). The last part of the compilation is doing a solution build with the Release or Debug configuration to build MPICEXEC and SMPD. The mpich2 dlls can be built to use shared memory communication, tcp socket communication, or both.

- Select the ch3sockDebug or ch3sockRelease configurations to build the sockets only dlls.
- Select the ch3shmDebug or ch3shmRelease configurations to build the shmem only dlls.
- Select the ch3sshmDebug or ch3sshmRelease configurations to build the scalable shmem only dlls.
- Select the ch3ssmDebug or ch3ssmRelease configurations to build the sockets+shmem dlls.
- Select the ch3ibDebug or ch3ibRelease configurations to build the infiniband dlls.


I hope you are done with the compilation, now lets start to see the simplest MPI program to calculate pi value:

// This is an interactive version of cpi
#include "mpi.h"
#include <stdio.h>
#include <math.h>

double f(double);

double f(double a)
{
    return (4.0 / (1.0 + a*a));
}

int main(int argc,char *argv[])
{
    int done = 0, n, myid, numprocs, i;
    double PI25DT = 3.141592653589793238462643;
    double mypi, pi, h, sum, x;
    double startwtime = 0.0, endwtime;
    int  namelen;
    char processor_name[MPI_MAX_PROCESSOR_NAME];

    MPI_Init(&argc,&argv);
    MPI_Comm_size(MPI_COMM_WORLD,&numprocs);
    MPI_Comm_rank(MPI_COMM_WORLD,&myid);
    MPI_Get_processor_name(processor_name,&namelen);

    /*
    fprintf(stdout,"Process %d of %d is on %s\n", myid, numprocs, processor_name);
    fflush(stdout);
    */

    while (!done) {
        if (myid == 0) {
            fprintf(stdout, "Enter the number of intervals: (0 quits) ");
        fflush(stdout);
            if (scanf("%d",&n) != 1) {
        fprintf( stdout, "No number entered; quitting\n" );
        n = 0;
        }
        startwtime = MPI_Wtime();
        }
        MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
        if (n == 0)
            done = 1;
        else {
            h   = 1.0 / (double) n;
            sum = 0.0;
            for (i = myid + 1; i <= n; i += numprocs) {
                x = h * ((double)i - 0.5);
                sum += f(x);
            }
            mypi = h * sum;
            MPI_Reduce(&mypi, &pi, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD);

            if (myid == 0) {
                printf("pi is approximately %.16f, Error is %.16f\n",
                       pi, fabs(pi - PI25DT));
        endwtime = MPI_Wtime();
        printf("wall clock time = %f\n", endwtime-startwtime);          
        fflush( stdout );
        }
        }
    }
    MPI_Finalize();
    return 0;
}


I will explain more about all the MPI codes in my in coming posting. For now, just try to install, compile and try your first MPI program (like cpi). Let me know if you have problem in compilation.

Cheers – RAM

Posted by Mattotorang | 1 Comments

Parallel Programming with OpenMP

OpenMP is the first parallel programming model (compiler directives and library routines) for shared memory multiprocessors. It was pioneered by SGI then becoming de-facto standard for parallelizing FORTRAN and C/C++ applications. Take a look on the official standard website of OpenMP to get more information about this standard. In this post I will guide you more practically to use OpenMP in Microsoft Visual C++.

OpenMP uses Fork-Join Model of parallel execution. Every OpenMP program begins as a single process: called it master thread. The master thread will be executed sequentially until the first parallel region construct is encountered. Most of constructs in OpenMP are compiler directives, with the following structure:

#pragma omp construct [clause [clause] …]

In C/C++ general code structure of the simplest OpenMP program is using omp.h directive and #pragma omp. You have to look on OpenMP documentation in MSDN library for complete construct options in MS VC++ then use /openmp option to compile your program.

#include <omp.h>
#include <iostream>
using namespace std;

int main ()  {

int nthreads, tid;

/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(tid)
  {
  /* Obtain and print thread id */
  tid = omp_get_thread_num();
  cout << "Hello World from thread = " << tid << endl;
  /* Only master thread does this */
  if (tid == 0)
    {
    nthreads = omp_get_num_threads();
    cout << "Number of threads = " << nthreads << endl;
    }

  }  /* All threads join master thread and terminate */

}

Please remember to include omp.h because all function prototypes and types are there. Using OpenMP to parallelize an application is “not hard” as modifications to the original source program are often needed in just a few places. Moreover, one usually does not need to rewrite significant portions of the code. So In general, the effort of parallelizing a program with OpenMP goes mainly into identifying the parallelism, and not in reprogramming the code to implement that parallelism. Let me show you how to use OpenMP to parallelize a simple operation that realizes a very basic problem: multiplying an m x n matrix B with a vector c
of length n, storing the result into a vector a of length m. Here is the formula:

OpenMP03

The sequential codes will look like:

void multiplyer(int m, int n, double *a, double *b, double *c)
{
    int i, j;
    for (i=0; i<m; i++)
     {
        a[i] = 0.0;
        for (j=0; j<n; j++) a[i] += b[i*n+j]*c[j];
    }
}

Lets review the codes before parallelizing it. As you can see no two dotproducts compute the same element of the result vector and also the order in which the values for the elements a[i] for i = 1, . . . , m are calculated does not affect correctness of the answer. In other words, this problem can be parallelized over the index value i.

Data in an OpenMP program either is shared by the threads in a team, in which case all member threads will be able to access the same shared variable, or is
private. For private case, each thread has its own copy of the data object, and hence the variable may have different values for different threads. In our case, we want each thread will access the same variable m,n,a,b,c, but each will have its own distinct variable i and j. A single #pragma (directive) is sufficient to parallelize the multiplyer.

void multiplyer(int m, int n, double *a, double *b, double *c)
{
    int i, j;

    #pragma omp parallel for default(none) shared(m,n,a,b,c) private(i,j)
    for (i=0; i<m; i++)
     {
        a[i] = 0.0;
        for (j=0; j<n; j++) a[i] += b[i*n+j]*c[j];
    }
}

You can continue your OpenMP exploration by reading this tutorial. If you prefer to read books, I would like to recommend you the following books from MIT Press. I will post more about parallel computing later.

OpenMP04

Cheers – RAM 

Posted by Mattotorang | 0 Comments

Working with Sharepoint in Vista

I followed the guidance from Bambo solutions to run WSS 3.0 SP1 with IIS 7.0 and SQL Server 2005 backend in my Vista machine. It works well, you can follow it too within 15 minutes. For UI level customization, I use Sharepoint Designer which is available also for remote site customization. Look how it run in my vista machine below.

To manage the operations and applications inside your Sharepoint farm, WSS shipped with web based Central Administration tools (you can also use SPAdmin tool) that you can use intuitively once you understood basic concepts of IIS, SP Farm, Web Application and Site Collections. Please consult to Sharepoint Documentation for further information. In my case, I use Central Administration to create one Web Application and one site collection.

SP02

To help me doing site customization, I use Sharepoint Designer (SD) to connect to all site resources and manipulate them visually. I just connected to my site using SD and did a simple manipulation to the title text of my site. Very easy and intuitive. I can manipulate contents of _catalog, _cts, _private, images, lists, etc using SD, without dealing directly with its physical location. SP01 
Editing content with SD is like using other HTML IDE with property driven customization. For example:
SP05

If you are curious to know where the physical location of those files, just open the IIS 7.0 and look there. It is not recommended to directly change something inside the physical directory as every things are managed logically in SD. I can use SD not only to change the existing content resources (CSS, ASPX, master pages, etc), but also to add custom content. Excellent!.
SP03                SP04

If you want to know more, on top of your Sharepoint Designer documentation, the following links are important:

- Sharepoint Designer Developer Reference
- Microsoft Sharepoint Designer Team Blog 

Hope this helps!.


Cheers, RAM

Posted by Mattotorang | 1 Comments

MSDN Nepal Beta Today

This is an early announcement for the release of MSDN NEPAL, online developer community for NEPAL. You can access its BETA version and take a look its nice face. Click to visit MSDN NEPAL.

Announcement01

I do hope this community can bring new experiences for thousands developers in NEPAL. To learn Microsoft latest technologies and share it with others.


Happy coding!

Cheers, RAM

Posted by Mattotorang | 2 Comments

WPF and Silverlight Deep Dive Sessions

I will deliver this training at four cities in Asia:

- Bangkok on Sept 24-26, 2008
- Manila on Oct 13-15, 2008
- Jakarta, TBD around Nov, 2008
- Hanoi, TBD around Dec, 2008 
phifinal

Unfortunately, I have limited time to prepare scientific related contents using WPF and Silverlight. I plan to do that, indeed.

Stay tuned.

Cheers - RAM

Posted by Mattotorang | 1 Comments

My PDC Pre-conference Session

I will attend "Concurrent, Multi-core Programming on Windows and .NET" session at PDC, next month. This will be a great workshop for me, not only because of its great topics, but I will meet some folks behind these technologies.

Guru (s): David Callahan, Joe Duffy, Stephen Toub

The leap from single-core to multi-core technology is altering computing as we know it, enabling increased productivity, powerful energy-efficient performance, and leading-edge advanced computing experiences. The good news is that Windows and .NET offer rich support for threading and synchronization to take advantage of these new platforms. This session, presented by David Callahan, Microsoft distinguished engineer, Joe Duffy, author of "Concurrent Programming on Windows” (Addison-Wesley), and Stephen Toub, program manager lead for the Concurrency Development Platform team at Microsoft, will cover a broad range of topics, including mechanisms to create, coordinate, and synchronize among threads; best practices for concurrent libraries and apps; and techniques for improving scalability, including lock-free algorithms. Focus will be on .NET programming, including the next generation of parallel programming support within the Framework, but Windows internals and C++ nuggets will be discussed too.


Can't wait to see and learn from them soon.

Cheers - Risman Adnan

Posted by Mattotorang | 1 Comments

Welcome to F#

In this post, I will introduce you to F#, a multi-paradigm .NET programming language that already attracted my attention. Lets try by downloading and installing it. I am using Version 1.9.6.2 at the time of this posting. For you who wants to follow me in F# exploration, I strongly recommend you to download and print the F# Language Specification and regularly visit F# Official MSDN Website.

FS01 
For you who already installed Visual Studio 2008, the F# installer will give you project templates for F# Application, Library and Tutorial. I am using VS 2008 Team Suite, and here is my VS 2008 looks like when I created new F# App project. Don't worry too much if you don't have VS 2008, you can use any text editor to write your codes then paste your code in MSR F# interactive console, fsi.exe. FS04

VS 2008 provides compilation environment using MSBuild extension. You can find the definition F# extension at Microsoft.FSharp.Targets and FSharp.Build.dll at Program Files/MSBuild folder. What you need to do in VS 2008 is just create new F# App project, write codes, then build. Let start by simple equation:

// Turn on the lightweight syntax
#light
// Open .NET standard namespaces
open System
// A very simple constant integer
let i1 = 1
// A second very simple constant integer
let i2 = 2
// Add two integers
let i3 = i1 + i2
// Functions on integers  f(x) = 10*x*x - 15*x + 13
let f x = 10*x*x - 15*x + 13

// The result of a simple computation
let result = f (i3 + 400)

// Print an integer
printfn "Result = %d" result


I believe you can easily understand above codes intuitively. The first line of the codes is an option to turn on F# lightweight syntax option. This option allows us to write code that looks and feels simpler by omitting recurring F# tokens such as, done, ; (semicolon), ;; (double semicolon), begin, and end. The option instructs F# compiler to use the indentation of F# code to determine where constructs start and finish.

Writing function in functional language is very straight forward. In our case, I wrote f x (f space x) as a function of x. Then I can reuse f for any input values. I will not explain language aspect in this first post, but I will do it in some tutorial series later on. My current F# reading is:
FS06  FS07

Good News.
The F# and .NET libraries include support for parallel and asynchronous programming. One way to write these kinds of programs is to use F#-facing libraries such as F# Asynchronous Workflows. Also, we can combine F# Async Workflow with the Parallel Extension for .NET, to implement task parallelism, I/O parallelism and message passing agents.

Stay tuned!. Lets make IT happen in NEPAL.

Cheers, RAM
My other blogs : http://blogs.msdn.com/risman

Posted by Mattotorang | 1 Comments
 
Page view tracker