Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 29 additions & 26 deletions openMp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,40 @@
#include <stdio.h>
#include <stdlib.h>

#define ROW 2;
#define COL 2;
#define ROW 2
#define COL 2
#define SECTOR_HEIGHT 2
#define SECTOR_WIDTH 2

// given row r and column c and thread ID t_id, you can map thread ID into region of array using following formula
// array(r,c) = array[r+m*t_id][c+m*t_id]
void secureAccess(int array[2][2], int threadID){
// 1. Map threadID to location in array
int row = threadID / ROW;
int col = threadID % COL;

// 2. Modify array based on this mapping
printf("array value: %d, row: %d, col: %d, ThreadID: %d\n"
, array[row][col], row, col, threadID);
// 1. Map threadID to location in array
int row = threadID / ROW;
int col = threadID % COL;

// 2. Modify array based on this mapping
printf("array value: %d, row: %d, col: %d, ThreadID: %d\n" , array[row][col], row, col, threadID);

}

int main(int argc, char *argv[]){
int nthreads, tid;
int array[ROW][COL] = {
{0, 0},
{0, 0}
};
int nthreads, tid;
int array[ROW][COL] = {
{0, 0},
{0, 0}
};

#pragma omp parallel private(nthreads, tid)
{
#pragma omp parallel private(nthreads, tid)
{

tid = omp_get_thread_num();
printf("Hello World from thead = %d\n", tid);
if (tid == 0){
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
secureAccess(array, tid);
}
return 0;
}
tid = omp_get_thread_num();
printf("Hello World from thead = %d\n", tid);
if (tid == 0){
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
}
secureAccess(array, tid);
}
return 0;
}