Posts tagged ‘C++’

Intel Performance Libraries allow you to leverage both parallelism and SIMD instructions in C#

Modern microprocessors can execute Single Instruction, Multiple Data (SIMD) instructions. Because the execution units for SIMD instructions usually belong to a physical core, it is possible to run as many SIMD instructions in parallel as available physical cores. The usage of these vector-processing capabilities in parallel can provide important speedups in certain algorithms. You can use Intel Performance Libraries to leverage both parallelism and SIMD instructions in C# and .NET Framework 4. Read more

January 12, 2011 at 1:31 pm Leave a comment

A project with an output type of class library cannot be started directly

Did you get bellow error message while compiling your ASP.NET project  or your C# project in Visual Studio 2005 or Visual Studio 2008 ?

Error message:

A project with an Output type of Class Library cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

To fix this issue, do these steps:

  • Right click the Project name in Solution Explorer of Visual Studio
  • Select Set as StartUp Project from the popup menu
  • Re-run your project, it should work !

If it did not work, be sure that you have set your start page. If your project is C# Windows Application or C# Console Application, try this:

  • Right click the Project name in Solution Explorer of Visual Studio
  • Select Properties
  • Select Application tab
  • In Output type drop box, select the correct application type of your project
  • Re-run your project and let me know if it won’t work.

December 12, 2010 at 10:00 pm 5 comments

Dynamic Memory Allocation for Two Dimensional Arrays in C++

In C++, a two-dimensional array can be declared simply like this

int a[10][20];

However, this declaration requires contanst array size and it is inconvenient when the array size vary. To avoid this issue, you can use dynamic two dimensional array. There are several ways to allocate a dynamic two-dimensional array in C++. In this post, I will show you three most frequent methods.

First one is flattening the two dimensional array into one dimensional array and using it as one dimensional array  

//Allocate
int *a = new int[m*n];

//Use a[m][n]
for( int i = 0 ; i < m ; i++)
        for ( int j = 0 ; j < n ; j++)
                 a[i*n + j] = 1;

//Deallocate
delete[] a;
 

Second method is using an array of dynamic one-dimensional arrays. It makes use of dynamic 2D array be easier. However, elements of array may not be continuous in memory

//Allocate
int **a = new int*[m];
for ( int i = 0 ; i < m ; i++)
a[i] = new int[n];
 
 
//Use a[m][n]
for ( int i = 0 ; i < m ; i++)
         for ( int j = 0 ; j < n ; j++)
a[i][j] = 1;
 
//Deallocate
for ( int i = 0 ; i < m ; i++) delete[] a[i];
delete[] a;
 
 
The third one allows all elements of a 2D int array to be contiguous in memory and I like this way most.

 //Allocate
int **a = new int*[m];

int a[0] = new int[m*n];
for ( int i = 1 ; i < m ; i++)  a[i] = a[i-1] + n;
 

 //Use a[m][n]
for ( int i = 0 ; i < m ; i++)
        for ( int j = 0 ; j < n ; j++)
a[i][j] = 1;

  
//Deallocate
delete[] a[0];
delete[] a;
 
If you prefer to performance, I recommend you to use the first method. This may be weird but I have tested on several codes.

August 3, 2010 at 3:39 pm 7 comments

Example Code of Multithreading in C# GUI Application

One of my friends recently asked me about the multithreading in C# so that many jobs can work on a same shared data. Like many programming languages, C# has its own libraries to support this need. Let me firstly describe a little bit about multithreading.   

In the trend of increasing number of cores integrated in the same processor chip, you may wonder “How do I utilize all available cores to make my program run faster?”. I guess that most of programs you’ve ever written till now are in sequential model. In this model, only one job is executed at a time and all jobs are finished in a sequential order. However, if you do a review of your programs and find some jobs can be run parallelly, multithreading can be a good choice to answer your question.  Using a right multi-thread programming model can speed up your program if it runs on a machine with multi-processor/multi-core.  However, this is not the only purpose of using many threads in a program. Another purpose of multithreading is interaction.  For example, your program provides a service that may be requested by many clients at the same time. Instead of letting the clients queue and wait for their turns, the program can accept all requests and process them concurrently. At the result, all clients can receive the responses at the time of request.      

A multi-thread program is enabled by using multithreading libraries such as OpenMP, Pthreads, Java Threads, Windows API threads… I don’t know exactly how many libraries of this type but I’m sure there are a lot. Some of them are created by companies like Microsoft, Intel while the others are born by research groups in universities or organizations.  My professor developed her own one for writting programs running on Cray or similar machines. In practice, each programming language has one or many tools that support multithreading. So which one should I choose? It is very hard to answer this question since it depends on the usage purpose, computing model and the programming language of your program.

In C#, the System.Threading namespace gives you a number of types that enable multithreading programming.  In this post, I did a small example program demonstrating how to do multithreading in C# GUI application. In the program, two threads are created and work on a same shared text data. One thread is scrolling in the text data from right the left and the other does the scrolling of same text in the reverse direction. Below is the program screenshot.

Download source code here

June 27, 2010 at 5:54 pm Leave a comment


Recent Posts

/openmp AMD app fixing dead pixel iphone C++ cmd program CPU C sharp dead pixels directory download ibm synthetic data generator Dynamic Dynamic Memory Allocation Edit Environment Variables in Windows Environment Variables error lnk2019: unresolved external symbol _getprocessmemoryinfo@12 referenced in function error lnk2019: unresolved external symbol _ getprocessmemoryinfo@12 referenced in function "void __cdecl printmemoryinfo(unsigned long example code Fixing Dead Pixels and Gray Lines on the iPhone Screen Fixing Dead Pixels on the iPhone Screen Fixing Gray Lines on the iPhone Screen Fix iPhone getprocessmemoryinfo GPU Gray Line iPhone Screen gray lines gray pixels green pixels GUI how to "new" a two-dimension array in C++ how to use ibm quest synthetic data generator ibm data generator ibm quest data generator ibm quest data generator exe ibm quest data mining project ibm quest market-basket synthetic data generator ibm quest market basket market-basket synthetic data generator ibm quest synthetic data generator ibm quest synthetic data generator linux ibm synthetic data generator ibm synthetic generator Intel iPhone Iphone 3G iPhone 3GS iPhone 4 iphone gray lines on startup iphone pixel damage iPhone Screen iPhone screen damage Linux market-basket synthetic data generator Memory Allocation Multicore multithread multi thread multi threaded multithreading mysql extract data into file new OpenCL Path processor quest data generator quest synthetic data generator R SAS Set Environment Variables Set Environment Variables in Windows souce code source code stuck pixels system file two dimension array Windows 7 Windows Vista