__sync_fetch_and_add

/usr/include/c++/4.4/ext/atomicity.h(46): error: identifier "__sync_fetch_and_add" is undefined
/usr/include/c++/4.4/ext/atomicity.h(50): error: identifier "__sync_fetch_and_add" is undefined

symptoms: #include <iostream> and using gcc 4.4
solution: AFAIK, do upgrade your gcc, or do not use iostream header.. 😀

import existing C++ code and its Makefile in Eclipse (Linux)

Cuma catatan doank biar gampang nyari kalo bsok lupa.. 😀 kbetulan lagi pengen nyobain ngutak-ngatik source code punya orang.. kbetulan jg lagi pengen ngrasain make Eclipse di Linux..

1. Create a new project, File > New > C++ Project.

2. C++ Project window will appear.

a. Give the project name same as the existing C++ code’s folder.

b. in Project Type column, select Makefile project > Empty project.

c. select the compiler type in the Toolchain column.

d. click Next and then Continue reading

another kotretan..

  1. Double data type is only supported on CUDA device which has compute capability 1.3. Use device query application to check your device capability.
  2. The following error message often appears when compiling a CUDA file (*.cu) in Visual C++ Express on a XP 64-bit machine and using CUDA toolkit 64-bit.
  3. "fatal error LNK1112: module machine type 'X64' conflicts with target machine type 'x86'"

    By default, Visual Express can only compile your program as 32-bit application. Since our CUDA toolkit type is 64-bit, then nvcc will compile your CUDA file as a 64-bit application. So, the error message warns this mismatch.

    To solve this, we have to add an extra option on NVCC when compiling a CUDA file. Go to Properties of our project, then in CUDA Build Rule v3.x.x >> General, add “–machine 32” (without quotation mark) in Extra Options column.

A simple CUDA-MFC program

Well, it’s just a simple CUDA program written in MFC framework. You know, all CUDA examples in NVIDIA SDK were written by using GLUT library, so they only use glut-window. Here, I’m trying to combine CUDA+OpenGL+GLSL in an MFC program, and this is the result.cumfc Continue reading

cunami on windows

Kemarin nyobain ng-convert CUDA application dari Linux ke Windows.. Setelah ngubek2 pesan error yang muncul, akhirnya berhasil jg.. Biar ga lupa dicatet aja ah.. 😀 Aplikasi yang mau gw convert namanya “cunami”, singkatan dari CUDA for Simulation of Tsunami.. hasil dari thesis gw kmaren.. hehe.. aslinya sih dikerjain di linux.. cuma pengen nyobain di windows aja..

yang perlu gw lakukan biar bisa dicompile di visual studio :

  1. ubah header include sys/time.h ke time.h, di windows ga perlu pake “sys”
  2. rendercheck_gl.cpp and rendercheck_gl.h are needed, jadi copas-kan ke cunami folder..
  3. project property di visual studio pada bagian C/C++ > Additional include directory: $(CUDA_INC_PATH);
    $(NVSDKCOMPUTE_ROOT)Ccommoninc
  4. project property di visual studio pada bagian C/C++ > Debug Information format: Program Database for Edit & Continue (/ZI) atau pada bagian Linker > Enable Incremental Linking: Yes (/INCREMENTAL)
  5. project property di visual studio pada bagian Linker > Additional dependecies : cudart.lib cutil32D.lib glew32.lib
  6. copas-kan cutil32.dll, glew32.dll and glut32.dll ke C:WindowsSystem32 agar file *.exe hasil compiling bisa running.

That’s all, and.. taraa…

multithreading in linux

Below is a sample multithreading program based on C language.


# include
...
/* parameter that will be passed to each matrix */
struct v{
	...
};

/* function that will be executed in each thread */
void *runonThread(void *param){
	struct v* data = (struct v*) param;
	/* put your application here */
	pthread_exit(0);
}

int  main()
{
	pthread_t pid[NUMTHREADS];
	pthread_attr_t attr;
	...
	/* get the default attributes */
	pthread_attr_init(&attr);

	for(i=0; i... = ... ;
		/*passing 'data' as parameter to each thread*/
		pthread_create(&pid[i], &attr,
				runonThread, data);
	} 

	/*waiting for the threads to complete */
	for(i=0; i<NUMTHREADS; i++)
		pthread_join(pid[i], NULL);

	return 0;
}

You may download a sample application to count matrix multiplication that uses multithreads, Matrix_Mul.zip