I Made Krisna's Times My Way to Write the Times

15Nov/110

Counting Size of Struct in C

First, i didn't guarantee that this post will give a true answer for any problem because this conclusion just made by myself based on my observation on some codes. It's very welcome to give another opinions or answers to share more knowledge and better solution.

This post will discuss about how much a struct take a memory? because of structs is a user-defined data structures, it's size will be relative to the content that the struct stores. For beginning let's refresh our memory (brain) about two most-used primitive data types size.

  1. int (4 bytes / 32 bits)
  2. char (1 bytes / 8 bits)
17Oct/110

Draw a “stdio” BL Right-Angled Triangle C Source Code

Hello again, i've posted about drawing a square shape before. Now we're move a step ahead, drawing a simple right-angled triangle. I give this post BL code which means "Bottom-Left" because we're gonna draw right-angled triangle with the '90' placed at bottom left of the triangle.

*
**
***
****

16Oct/110

Draw a “stdio” Square Shape C Source Code

Working in a one of biggest electronics manufacturer in the world that didn't make my training comes to advanced level. I've learn again from the bottom. Of course the language used is native-C which the founder passed away recently...

One of the simplest thing is using looping for drawing some shapes and in this post it will be a square shapes. The easiest shape i think. What we nee d just a nested loop for drawing the rows (outer loop) and the cell or column (inner loop) which loop with the same number (square has same size for width/column and height/row).

25Nov/100

Matrix-Matrix Multiplication MPI C Source Code

Expanding from my previous post, "Matrix-Vector Multiplication MPI C Source Code". Now we create a program to calculate two two-dimensional matrices (array) with MPI. Same concept and algorithm with matrix-vector used to solve this problem, row-based operation.

Now the differences from matrix-vector just the array size and dimension.

#define AROW 3
#define ACOL 2

#define BCOL 3

#define MAX_VALUE 10

For proc_map() function please look at matrix-vector post, and here's the computational code for matrix-matrix multiplication.

18Nov/101

Matrix-Vector Multiplication MPI C Source Code

Here's my first task for MPI Programming. Create a matrix-vector multiplication program using Message Passing Interface. Let's go directly to the source code and we can discuss it later if you want.

First, MPI with C language commonly use "mpi.h" and you still can use standard C library.

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
#include "math.h"

#include "mpi.h"

Now, we need to define the size of matrices, A as [AROW x ACOL] and B as [ACOL x 1] so the result let's call it matrix C [AROW x 1]. Because the row of B must be equals with column of A and the result matrix C has row = AROW and single column. MAX_VALUE is the constant for defining maximum value of random number for matrices elements value.

#define AROW 3
#define ACOL 2

#define MAX_VALUE 10

proc_map() function is the function to map the each task to which process to do it.


/* Process mapping function */
int proc_map(int i, int size)
{
	size = size - 1;
	int r = (int) ceil( (double)AROW / (double)size);
	int proc = i / r;
	return proc + 1;
}