Programming2012. 5. 21. 09:52
년/월/일 변경시 윤년인지 확인하는 귀차니즘이 필요한데
윤년 확인하는 방법을 간단하게 구현해 놓은 곳이 있어 링크!

if(((year % 400) == 0) || ((year % 4) == 0) && ((year % 100) != 0)) 
{
    // 윤년
}
else
{
     // 평년
[링크 :  http://blog.daum.net/sualchi/13719905]

그레고리력의 윤년 규칙은 정확히 4년마다 윤년이 오는 율리우스력을 수정한 것이다. 정확한 규칙은 다음과 같다.
  1. 서력 기원 연수가 4로 나누어 떨어지는 해는 우선 윤년으로 한다. (2004년, 2008년, 2012년…)
  2. 100으로 나누어 떨어지는 해는 평년으로 한다. (2100년, 2200년, 2300년…)
  3. 400으로 나누어 떨어지는 해는 다시 윤년으로 한다. (1600년, 2000년, 2400년 …)

[링크 :  http://ko.wikipedia.org/wiki/윤년

만약 달력 입력하는 곳이 있으면
년이 변경될 경우 2월일 경우에 날짜 확인 (time_t 구조체 상으로 tm_mon 0부터 시작하므로, 2월은 1임)
월이 변경될 경우 2월에 대해서 날짜 확인
일이 변경될 경우 매월에 대한 최대 날짜를 확인해야 한다. 

---
2015.02.04

if( month==2 && ( year%4==0 && year%100!=0 || year%400==0 ) ) {
    maxDay = 29;
}


'Programming' 카테고리의 다른 글

apple 차세대 언어 swift  (0) 2014.06.03
ARToolKit / openVRML  (0) 2012.12.25
TBB/IPP  (2) 2012.02.12
프로그래밍 언어에 대한 생각  (2) 2012.01.25
S language  (0) 2011.07.01
Posted by 구차니
개소리 왈왈2012. 5. 20. 22:18
어릴적 태권도를 배울때 세뇌에 가깝도록 듣게 되는 소리가 바로
운동하는 사람들은 다른 사람에게 폭력을 행사해서는 안된다는 이야기인데

대상이 모든 생명체가 아닌 사람으로 한정되는건 왜일까
혹은 조금 더 확대해서, 동포라던가 친한 사람으로 잡히는건 왜일까..
화가나서 누군가를 패고 싶어서 선듯 주먹이 나가지 않음은 어릴적 세뇌의 영향인진 몰라도,
그러한 현상에 당혹스러우면서 머리는 그 이유를 찾으려고 고민을 하게 된다.

그 대상이 "인간의 형상"을 하고 있기 때문에 폭력을 투사하지 못하게 하는것인지
아니면 인간의 형상을 하고 있더라도 악마라면 패도 되는것일지
인간의 형상을 하지 않고 개조를 당한(?) 인간이라도 패면 안되는것일지


참.. 웃기는 소리지만...
인간의 형상이라.. 도대체 그것 자체에 어떤 의미가 주어진걸까. 

'개소리 왈왈' 카테고리의 다른 글

생각을 정지합니다. 으아 안되잖아  (4) 2012.06.11
엇 네이트온 메모짱이!  (6) 2012.06.01
잘가 메모짱  (0) 2012.05.15
질문 : 왜 사는가? 어떻게 사는가?  (0) 2012.04.20
4.19  (0) 2012.04.18
Posted by 구차니
갤노트 갤플 5 인치 vs 아잉1 중고 vs 아잉2 중고 vs 아이덴티티탭




그냥 로또 되거나
show me the money 면 다 사겠지만.. ㅠ.ㅠ
아이덴티티 탭은 카메라 모듈이 없는거 같고..
이래저래 고민만 느는구나아 ㅠ.ㅠ 
Posted by 구차니
개소리 왈왈/자전거2012. 5. 19. 14:03
성남공단 내리막길에 2단/5단 놓고 달성 -_-b
그나저나.. 아직 다리힘이 한계인지 50킬로도 안되네 ㅠㅠ
이제 헬멧사야겠다 ㅠㅠ

+ 최고속도
- 때릉이

'개소리 왈왈 > 자전거' 카테고리의 다른 글

BB가 고장난게 아니라~  (0) 2012.06.09
야간에 자전거!  (2) 2012.05.25
간만에 자전거  (4) 2012.05.12
오랫만에 자전거 나들이  (4) 2012.03.17
자전거 핸들 스템  (1) 2011.12.21
Posted by 구차니
Programming/openCL & CUDA2012. 5. 18. 21:22
CUDA device에서 제공하는 메모리의 종류는 다음과 같다.

5.3.2  Device Memory Accesses .................................................................... 70 
    5.3.2.1  Global Memory ............................................................................ 70 
    5.3.2.2  Local Memory .............................................................................. 72 
    5.3.2.3  Shared Memory ........................................................................... 72 
    5.3.2.4  Constant Memory ........................................................................ 73 
     5.3.2.5  Texture and Surface Memory ........................................................ 73  

[출처 :  CUDA C Programming guide.pdf] 

Local memory 와 Global memory는 그래픽 카드의 비디오 메모리(통상 512MB / 1기가 이런식으로 말하는)에 존재하고
Shared memory는 GPU 내의 Multi-Processor에 통합되어있다.

Devicequery를 비교하면서 보자면
8800GT 512MB 짜리에서
Global memory와 Local memory는 512MB 까지 가능하며
Shared memory는 블럭당 16KB 까지 가능하다.

 Device 0: "GeForce 8800 GT"
  CUDA Driver Version:                           3.20
  CUDA Runtime Version:                          3.10
  CUDA Capability Major revision number:         1
  CUDA Capability Minor revision number:         1
  Total amount of global memory:                 536543232 bytes
  Number of multiprocessors:                     14
  Number of cores:                               112
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       16384 bytes
  Total number of registers available per block: 8192
  Warp size:                                     32
  Maximum number of threads per block:           512
  Maximum sizes of each dimension of a block:    512 x 512 x 64
  Maximum sizes of each dimension of a grid:     65535 x 65535 x 1   

2011/01/02 - [Programming/openCL / CUDA] - deviceQuery on 8600GT 512MB + CUDA 하드웨어 구조
      
 

예제로 들어있는 행렬곱 예제에서
shared memory를 사용하고 사용하지 않는 차이점은 아래의 그림처럼
Global memory에 직접 한 바이트씩 읽어서 계산하는지

아니면 global memory의 블럭을
shared memory로 일정 영역만(블럭 사이즈 만큼) 복사해서 계산을 하는지의 차이점이 있다.

다른 책에 의하면 global memory는 700~900 cuda clock에 읽어오고
shared memory는 거의 1 cuda clock에 읽어 온다고 하니
되도록이면 shared memory에 복사해서 더욱 빠르게 연산하는게 유리하다고 한다.

 

 

// Matrices are stored in row-major order: 
// M(row, col) = *(M.elements + row * M.width + col) 
typedef struct { 
    int width; 
    int height; 
    float* elements; 
} Matrix; 
 
// Thread block size 
#define BLOCK_SIZE 16 
 
// Forward declaration of the matrix multiplication kernel 
__global__ void MatMulKernel(const Matrix, const Matrix, Matrix); 
 


























 
// Matrix multiplication - Host code 
// Matrix dimensions are assumed to be multiples of BLOCK_SIZE 
void MatMul(const Matrix A, const Matrix B, Matrix C) 
    // Load A and B to device memory 
    Matrix d_A; 
    d_A.width = A.width; d_A.height = A.height; 
    size_t size = A.width * A.height * sizeof(float); 
    cudaMalloc(&d_A.elements, size); 
    cudaMemcpy(d_A.elements, A.elements, size, 
               cudaMemcpyHostToDevice); 
    Matrix d_B; 
    d_B.width = B.width; d_B.height = B.height; 
    size = B.width * B.height * sizeof(float); 
    cudaMalloc(&d_B.elements, size); 
    cudaMemcpy(d_B.elements, B.elements, size, 
               cudaMemcpyHostToDevice); 
 
    // Allocate C in device memory 
    Matrix d_C; 
    d_C.width = C.width; d_C.height = C.height; 
    size = C.width * C.height * sizeof(float); 
    cudaMalloc(&d_C.elements, size); 
 
    // Invoke kernel 
    dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE); 
    dim3 dimGrid(B.width / dimBlock.x, A.height / dimBlock.y); 
    MatMulKernel<<<dimGrid, dimBlock>>>(d_A, d_B, d_C); 
 
    // Read C from device memory 
    cudaMemcpy(C.elements, Cd.elements, size, 
               cudaMemcpyDeviceToHost); 
 
    // Free device memory 
    cudaFree(d_A.elements); 
    cudaFree(d_B.elements); 
    cudaFree(d_C.elements); 

// Matrix multiplication kernel called by MatMul() 
__global__ void MatMulKernel(Matrix A, Matrix B, Matrix C) 
    // Each thread computes one element of C 
    // by accumulating results into Cvalue 
    float Cvalue = 0; 
    int row = blockIdx.y * blockDim.y + threadIdx.y; 
    int col = blockIdx.x * blockDim.x + threadIdx.x; 
    for (int e = 0; e < A.width; ++e) 
        Cvalue += A.elements[row * A.width + e] 
                * B.elements[e * B.width + col]; 
    C.elements[row * C.width + col] = Cvalue; 













































 

// Matrices are stored in row-major order: 
// M(row, col) = *(M.elements + row * M.stride + col) 
typedef struct { 
    int width; 
    int height; 
    int stride;  
    float* elements; 
} Matrix; 
 
// Get a matrix element 
__device__ float GetElement(const Matrix A, int row, int col) 
    return A.elements[row * A.stride + col]; 
 
// Set a matrix element 
__device__ void SetElement(Matrix A, int row, int col, 
                           float value) 
    A.elements[row * A.stride + col] = value; 
 
// Get the BLOCK_SIZExBLOCK_SIZE sub-matrix Asub of A that is 
// located col sub-matrices to the right and row sub-matrices down 
// from the upper-left corner of A 
__device__ Matrix GetSubMatrix(Matrix A, int row, int col)  
    Matrix Asub; 
    Asub.width    = BLOCK_SIZE; 
    Asub.height   = BLOCK_SIZE; 
    Asub.stride   = A.stride; 
    Asub.elements = &A.elements[A.stride * BLOCK_SIZE * row 
                                         + BLOCK_SIZE * col]; 
    return Asub; 
 
// Thread block size 
#define BLOCK_SIZE 16 
 
// Forward declaration of the matrix multiplication kernel 
__global__ void MatMulKernel(const Matrix, const Matrix, Matrix); 
 
// Matrix multiplication - Host code 
// Matrix dimensions are assumed to be multiples of BLOCK_SIZE 
void MatMul(const Matrix A, const Matrix B, Matrix C) 
    // Load A and B to device memory 
    Matrix d_A; 
    d_A.width = d_A.stride = A.width; d_A.height = A.height; 
    size_t size = A.width * A.height * sizeof(float); 
    cudaMalloc(&d_A.elements, size); 
    cudaMemcpy(d_A.elements, A.elements, size, 
               cudaMemcpyHostToDevice); 
    Matrix d_B; 
    d_B.width = d_B.stride = B.width; d_B.height = B.height; 
    size = B.width * B.height * sizeof(float); 
    cudaMalloc(&d_B.elements, size); 
    cudaMemcpy(d_B.elements, B.elements, size, 
               cudaMemcpyHostToDevice); 
 
    // Allocate C in device memory 
    Matrix d_C; 
    d_C.width = d_C.stride = C.width; d_C.height = C.height; 
    size = C.width * C.height * sizeof(float); 
    cudaMalloc(&d_C.elements, size); 
 
    // Invoke kernel 
    dim3 dimBlock(BLOCK_SIZE, BLOCK_SIZE); 
    dim3 dimGrid(B.width / dimBlock.x, A.height / dimBlock.y); 
    MatMulKernel<<<dimGrid, dimBlock>>>(d_A, d_B, d_C); 
 
    // Read C from device memory 
    cudaMemcpy(C.elements, d_C.elements, size, 
               cudaMemcpyDeviceToHost); 
 
    // Free device memory 
    cudaFree(d_A.elements); 
    cudaFree(d_B.elements); 
    cudaFree(d_C.elements); 
 
// Matrix multiplication kernel called by MatMul() 
__global__ void MatMulKernel(Matrix A, Matrix B, Matrix C) 
    // Block row and column 
    int blockRow = blockIdx.y; 
    int blockCol = blockIdx.x; 
 
    // Each thread block computes one sub-matrix Csub of C 
    Matrix Csub = GetSubMatrix(C, blockRow, blockCol); 
     // Each thread computes one element of Csub 
    // by accumulating results into Cvalue 
    float Cvalue = 0; 
 
    // Thread row and column within Csub 
    int row = threadIdx.y; 
    int col = threadIdx.x; 
 
    // Loop over all the sub-matrices of A and B that are 
    // required to compute Csub 
    // Multiply each pair of sub-matrices together 
    // and accumulate the results 
    for (int m = 0; m < (A.width / BLOCK_SIZE); ++m) { 
 
        // Get sub-matrix Asub of A 
        Matrix Asub = GetSubMatrix(A, blockRow, m); 
 
        // Get sub-matrix Bsub of B 
        Matrix Bsub = GetSubMatrix(B, m, blockCol); 
 
        // Shared memory used to store Asub and Bsub respectively 
        __shared__ float As[BLOCK_SIZE][BLOCK_SIZE]; 
        __shared__ float Bs[BLOCK_SIZE][BLOCK_SIZE]; 
 
        // Load Asub and Bsub from device memory to shared memory 
        // Each thread loads one element of each sub-matrix 
        As[row][col] = GetElement(Asub, row, col); 
        Bs[row][col] = GetElement(Bsub, row, col); 
 
        // Synchronize to make sure the sub-matrices are loaded 
        // before starting the computation 
        __syncthreads(); 
 
        // Multiply Asub and Bsub together 
        for (int e = 0; e < BLOCK_SIZE; ++e) 
            Cvalue += As[row][e] * Bs[e][col]; 
 
        // Synchronize to make sure that the preceding 
        // computation is done before loading two new 
        // sub-matrices of A and B in the next iteration 
        __syncthreads(); 
    } 
 
    // Write Csub to device memory 
    // Each thread writes one element 
    SetElement(Csub, row, col, Cvalue); 
}


'Programming > openCL & CUDA' 카테고리의 다른 글

cuda 5 preview  (0) 2012.06.02
nvidia ion cuda core와 h.264 library  (0) 2012.05.22
Interoperability (상호운용성)  (0) 2012.05.04
cuda 내장변수  (0) 2012.04.30
kernel block 과 thread  (0) 2012.04.26
Posted by 구차니
5달만에 복귀한 코스피 지수.
펀드 들어놓은걸 손실 감수하고 지금이라도 빼야하나 일단 그냥 계속 묵혀둘까 고민고민..



솔찍히.. 증권가의 가장 큰 문제는
증권 얼마간다! 얼마선은 무너지지 않는다! 수익률은 얼마이다! 이러지만
실제로 보면 투자자는 이래저래 절대 큰 이익을 얻을수 없고
수수료라던가 자잘하게 뜯어가면서 증권사가 대행인만 돈버는 구조라고 해야하나.

그러면서도 그 사람들은 세계증시가 어쩌구 하면서 자신의 책임은 하나도 지지않는 다는점.
펀드매니저도 힘들고 밤새고 수명도 짧다지만, 그것과 책임은 별개아 아닐까?
머.. 다르게 말해서 책임도 주어진다면 이런 위험을 무릎쓰고 무리하게 공격적으로(?) 투자하는
투자자들도 사라지고 허언을 남발하는 예언가들도 사라질꺼고 너무 조용한 세상이 되려나... 
Posted by 구차니
4년 연속 불참에 개회사 생략이라니
부디 대선에 원하는 결과가 나오길 빌어본다.. 시발 -_-t

[링크 : http://media.daum.net/politics/newsview?newsid=20120518081010857
[링크 : http://ko.wikipedia.org/wiki/5.18]
Posted by 구차니
경기버스 타고 가야하나 -ㅁ-?
그래도 솔찍히 9.5% 인상은 좀 너무 하는 느낌인데 -_-
차라리 인력을 더 뽑아달라구 하지 ㅠ.ㅠ

[링크 :  http://media.daum.net/society/others/newsview?newsid=20120517035604880&cateid=1067&RIGHT_COMM=R3]

'개소리 왈왈 > 직딩의 비애' 카테고리의 다른 글

프로그램에서 제일 중요한 것  (0) 2012.05.24
D-103  (0) 2012.05.23
아이고 내 펀드 ㅠ.ㅠ  (2) 2012.05.11
길빵을 왜케 많이해?  (2) 2012.05.09
와이파이 안터져요 ㅠ.ㅠ  (0) 2012.05.04
Posted by 구차니
교과서에서 진화론을 빼달라고 기독교에서 요청을 했다는데
머.. 이단이라고 하면 빠져나갈수 있는 참으로 간편한 논리를 또 쓰려나?

[링크 :  http://media.daum.net/society/newsview?newsid=20120517032635618]
Posted by 구차니
귀찮아서 SDK starter package만 설치하고
가상머신 버전 대충 하나 골라서 추가해주고 나니
java sdk 없이 win7 내장 java vm으로도 작동이 문제없이 되는데...


역시.. 2.3.3 만으로는.. setting도 없고 아무것도 없어서 되는게 아니구나 ㅠ.ㅠ

[링크 : http://developer.android.com/sdk/index.html]
Posted by 구차니