Модераторы: bsa
  

Поиск:

Ответ в темуСоздание новой темы Создание опроса
> как переделать программу MPI в OpenMP 
:(
    Опции темы
TheFallenViper
Дата 4.4.2012, 14:49 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Новичок



Профиль
Группа: Участник
Сообщений: 4
Регистрация: 20.3.2012

Репутация: нет
Всего: нет



Всё откомпелировалось нормально.запускал через Linux Ubuntu.а теперь у меня задача запустить эту прогу на линуксе только уже с помощью OpenMP а не MPI.как мне это сделать?

Код

#include<mpi.h>

#include<stdlib.h>
#include<stdio.h>

#define Wtime MPI_Wtime
#define MEGABYTE (1024*1024)
#define BUFFER_SIZE (16*MEGABYTE)
#define TAG1 17
#define MASTER_RANK 0
#define MAX_REQUESTS 16
#define MILLION 1000000.0

static int NTIMES = 1000;
static int NTIMES_PREC = 10000;
static int REPEAT_ALL = 1;
static int REPEAT_EACH_TEST = 1;

#define NTIMES_TIMING NTIMES_PREC
#define NTIMES_BARRIER NTIMES_PREC
#define NTIMES_LATENCY NTIMES_PREC

#define TEST_SENDRECV 0

#define MASTER if(i_am_the_master) 

int nproc,myid,rank,pool_size;
int i_am_the_master = 0;

static int msglen_min = 1;
static int msglen_max = 1000;
static int msglen_multiplier = 10;
static int msglen_step = 0;

int *buf,*obuf;
FILE *out;

/* йНЕОБ РТПГЕУУПТПЧ, ЙМЙ ХЪМПЧ, ОБ ЛПФПТЩИ ТБВПФБАФ РТПГЕУУЩ ЪБДБЮЙ */
static char nodename[32];
static char* nodenames;
int namelen = 32;

void Test_MPI_Routines(MPI_Comm comm,int len);
int checktick();

int main(int argc,char *argv[]) {

int i,k;
int bufsize = BUFFER_SIZE;
int msglen;
double t_start,t_end;
char processor_name[128],output_file_name[128];
int namelen = 128;
MPI_Status status;

MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&nproc);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);

i_am_the_master = (myid == MASTER_RANK);
rank = myid;
pool_size = nproc;

out = stdout;

t_start = Wtime();
MASTER printf("MPItest/C 2.1: running %d processes...\n",nproc);

if(nproc < 2) {
MASTER printf("MPItest expects at least 2 processes\n");
MPI_Finalize();
exit(0);
}


MASTER /* read command line parameters */ 
for(i = 1; i < argc; i ++)
switch(argv[i][0]) {
case 'm': msglen_min = atoi(argv[i]+1); break;
case 'M': msglen_max = atoi(argv[i]+1); break;
case 'K': msglen_multiplier = atoi(argv[i]+1); msglen_step = 0; break;
case 'T': NTIMES = atoi(argv[i]+1); break; 
case 't': NTIMES_PREC = atoi(argv[i]+1); break; 
case 'R': REPEAT_ALL = atoi(argv[i]+1); break; 
case 'r': REPEAT_EACH_TEST = atoi(argv[i]+1); break; 
case 'b': bufsize = (atoi(argv[i]+1)*MEGABYTE)/sizeof(int); break;
case 'o': 
strcpy(output_file_name,argv[i]+1); 
out = fopen(output_file_name,"a+");
if(out == NULL)
{
printf("WARNING: Can't open or create %s, writing to stdout\n",output_file_name);
out = stdout;
}
else 
printf("Writing output to %s\n",output_file_name);
break;

default: fprintf(stderr,"WARNING: unrecognized option: %s\n",argv[i]);
break;
}

MPI_Bcast(&NTIMES,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&NTIMES_PREC,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&REPEAT_ALL,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&REPEAT_EACH_TEST,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&msglen_min,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&msglen_max,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&msglen_multiplier,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);
MPI_Bcast(&bufsize,1,MPI_INT,MASTER_RANK,MPI_COMM_WORLD);

MPI_Barrier(MPI_COMM_WORLD);

/* рЩФБЕНУС ОБРЕЮБФБФШ ЙНЕОБ ЧУЕИ ХЪМПЧ, ОБ ЛПФПТЩИ ТБВПФБЕФ ФЕУФ */

MPI_Get_processor_name(nodename,&namelen);

if(i_am_the_master)
{
nodenames = (char*) malloc(35*pool_size);
strcpy(nodenames,nodename);

/* зПМПЧОПК РТПГЕУУ РПМХЮБЕФ ЙНЕОБ ПУФБМШОЩИ Й УПВЙТБЕФ ЙИ Ч ПДОХ УФТПЛХ */

for(i = 1; i < pool_size; i ++)
{
strcat(nodenames," ");
MPI_Recv(nodename,32,MPI_CHAR,i,2003,MPI_COMM_WORLD,&status);
strcat(nodenames,nodename); 
}

fprintf(out,"\tNodes: %s\n",nodenames);

fflush(out);
} 
else
MPI_Send(nodename,32,MPI_CHAR,0,2003,MPI_COMM_WORLD);

fflush(out);

if(bufsize < msglen_max * nproc) {
MASTER printf("Too small buffer size - %d. At least %d words required\n",bufsize,msglen_max * nproc);
MPI_Finalize();
exit(0);
}
buf = (int*) malloc(sizeof(int)*bufsize);
obuf = (int*) malloc(sizeof(int)*bufsize);

if(buf == NULL || obuf == NULL) 
{
MASTER printf("Too small buffer size. At least %d words required\n",msglen_max * nproc);
MPI_Finalize();
exit(0);
}

MASTER fprintf(out,"Testing basic MPI routines.\n");
MASTER fprintf(out,"T = %d, t = %d\n",NTIMES,NTIMES_PREC);

for(k = 0; k < REPEAT_ALL; k ++)
{
MASTER fprintf(out,"\n--- Iteration %d ---\n",k);
Test_MPI_Routines(MPI_COMM_WORLD,0);

for(msglen = msglen_min; msglen <= msglen_max; msglen *= msglen_multiplier)
{
MASTER fprintf(out,"\n--- Size %d, Iteration %d ---\n",msglen,k);
Test_MPI_Routines(MPI_COMM_WORLD,msglen);
}
}

t_end = Wtime();
MASTER printf("MPItest/C complete in %g sec.\n",t_end-t_start);
MASTER fclose(out);

MPI_Finalize();

return 0;
} 

void Test_MPI_Routines(MPI_Comm comm,int msglen) 
{
int i,k;
int nproc,myid,tick;
int i_am_the_master = 0;
double t, t1, t2, tt, dt, lat, tb, best_time;
MPI_Status status, statuses[MAX_REQUESTS];
MPI_Request request, requests[MAX_REQUESTS];

MPI_Comm_size(MPI_COMM_WORLD,&nproc);
MPI_Comm_rank(MPI_COMM_WORLD,&myid);

i_am_the_master = (myid == MASTER_RANK);

MPI_Barrier(comm);

/* Initialization of buffer data */

for(i = 0; i < BUFFER_SIZE; i ++)
buf[i] = myid;

if(msglen == 0)
{
/* ----- Measuring time for a MPI_Wtime() call ------ */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{
dt = 0;
t1 = Wtime();
MASTER for(i = 0; i < NTIMES_TIMING; i ++) 
{
t = Wtime();
}
t2 = Wtime();
dt = t2 - t1;
dt /= (double) NTIMES_TIMING;
t = dt;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER tick = checktick();
MASTER fprintf(out,"%6.1f\tTIMING\tclock tick = %d\n",t,tick);
MASTER fflush(out);

/* ----------- Testing barrier synchronization ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

tb = 0;
t1 = Wtime();
for(i = 0; i < NTIMES_BARRIER; i ++) 
{
MPI_Barrier(comm);
}
t2 = Wtime();
tb = t2 - t1;
tb /= (double) NTIMES_BARRIER;
t = tb;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tBARRIER\n",t);
fflush(out);


/* ----------- Testing signal send/receive ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
if(i_am_the_master)
{
t1 = Wtime();
for(i = 0; i < NTIMES_LATENCY; i ++) 
{
MPI_Send(NULL,0,MPI_INT,1,TAG1,comm);
MPI_Recv(NULL,0,MPI_INT,1,TAG1,comm,&status);
}
t2 = Wtime();
t = t2 - t1;
}
else if(myid == 1) 
for(i = 0; i < NTIMES_LATENCY; i ++) 
{
MPI_Recv(NULL,0,MPI_INT,MASTER_RANK,TAG1,comm,&status);
MPI_Send(NULL,0,MPI_INT,MASTER_RANK,TAG1,comm);
}

t /= (double) NTIMES_LATENCY;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tSIGNAL SEND & RECEIVE (double latency)\n",t);
fflush(out); 

} /* ЛПОЕГ ВМПЛБ ДМС msglen = 0 */
else
{
/* ----------- Testing MPI_Reduce ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Reduce(buf,obuf,msglen,MPI_INT,MPI_SUM,MASTER_RANK,comm);
}
t2 = Wtime();
t = (t2 - t1);
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tREDUCE (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing MPI_Allreduce ---------- */
best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Allreduce(buf,obuf,msglen,MPI_INT,MPI_SUM,comm);
}
t2 = Wtime();
t = (t2 - t1);
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tALLREDUCE (%d)\n",t,msglen);
fflush(out);


/* ----------- Testing broadcast routine ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Bcast(buf,msglen,MPI_INT,MASTER_RANK,comm);
}
t2 = Wtime();
t = (t2 - t1);
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tBROADCAST (%d)\n",t,msglen);
fflush(out);
/* ----------- Testing gather routine ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Gather(buf,msglen,MPI_INT,obuf,msglen,MPI_INT,MASTER_RANK,comm);
}
t2 = Wtime();
t = (t2 - t1);
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tGATHER (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing Allgather routine ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Allgather(buf,msglen,MPI_INT,obuf,msglen,MPI_INT,comm);
}
t2 = Wtime();
t = (t2 - t1);
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tALLGATHER (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing All-to-All routine ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Alltoall(buf,msglen,MPI_INT,obuf,msglen,MPI_INT,comm);
}
t2 = Wtime();
t = (t2 - t1);
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tALL-TO-ALL (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing non-blocking send with wait ---------- */
best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
if(i_am_the_master)
{
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Isend(buf,msglen,MPI_INT,1,TAG1,comm,&request);
MPI_Wait(&request,&status);
}
t2 = Wtime();
t = (t2 - t1);
}
else if(myid == 1)
for(i = 0; i < NTIMES; i ++) 
{
MPI_Irecv(obuf,msglen,MPI_INT,MASTER_RANK,TAG1,comm,&request);
MPI_Wait(&request,&status);
}
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tISEND & WAIT (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing blocking vector send ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
if(i_am_the_master)
{
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Send(buf,msglen,MPI_INT,1,TAG1,comm);
}
t2 = Wtime();
t = (t2 - t1);
}
else if(myid == 1)
for(i = 0; i < NTIMES; i ++) 
MPI_Recv(obuf,msglen,MPI_INT,MASTER_RANK,TAG1,comm,&status);

t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tSEND (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing simultaneous send & receive ---------- */

best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
if(i_am_the_master)
{
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Sendrecv(buf,msglen,MPI_INT,1,TAG1,obuf,msglen,MPI_INT,1,TAG1,comm,statuses);
}
t2 = Wtime();
t = (t2 - t1);
}
else if(myid == 1) 
for(i = 0; i < NTIMES; i ++) 
MPI_Sendrecv(buf,msglen,MPI_INT,MASTER_RANK,TAG1,obuf,msglen,MPI_INT,MASTER_RANK,TAG1,comm,statuses);

t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tSENDRECV (%d)\n",t,msglen);
fflush(out);

/* ----------- Testing sequential send & receive ---------- */
best_time = 0;

for(k = 0; k < REPEAT_EACH_TEST; k ++)
{

t = 0;
MPI_Barrier(comm);
if(i_am_the_master)
{
t1 = Wtime();
for(i = 0; i < NTIMES; i ++) 
{
MPI_Send(buf,msglen,MPI_INT,1,TAG1,comm);
MPI_Recv(obuf,msglen,MPI_INT, 1,TAG1,comm,&status);
}
t2 = Wtime();
t = (t2 - t1);
}
else if(myid == 1) 
for(i = 0; i < NTIMES; i ++) 
{
MPI_Recv(obuf,msglen,MPI_INT,MASTER_RANK,TAG1,comm,&status);
MPI_Send(buf,msglen,MPI_INT,MASTER_RANK,TAG1,comm);
}
t /= (double) NTIMES;

if((t < best_time) || (best_time == 0)) 
best_time = t;
}

t = best_time * MILLION;

MASTER fprintf(out,"%6.1f\tSEND & RECEIVE (%d)\n",t,msglen);
fflush(out);
}
}

# define M 2000
# ifndef MIN
# define MIN(x,y) ((x)<(y)?(x):(y))
# endif
# ifndef MAX
# define MAX(x,y) ((x)>(y)?(x):(y))
# endif

int checktick()
{
int i, minDelta, Delta;
double t1, t2, timesfound[M];

/* Collect a sequence of M unique time values from the system. */

for (i = 0; i < M; i++) {
t1 = Wtime();
while( ((t2=Wtime()) - t1) < 1.0E-6 )
;
timesfound[i] = t1 = t2;
}

/*
* Determine the minimum difference between these M values.
* This result will be our estimate (in microseconds) for the
* clock granularity.
*/

minDelta = 1000000;
for (i = 1; i < M; i++) {
Delta = (int)( 1.0E6 * (timesfound[i]-timesfound[i-1]));
minDelta = MIN(minDelta, MAX(Delta,0));
}

return(minDelta);
}



M
JackYF
Пользуемся кнопкой "код".

PM MAIL   Вверх
boostcoder
Дата 4.4.2012, 15:04 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


pattern`щик
****


Профиль
Группа: Завсегдатай
Сообщений: 5458
Регистрация: 1.4.2010

Репутация: 20
Всего: 110



отформатируй код, для начала.
PM WWW   Вверх
xvr
Дата 5.4.2012, 13:54 (ссылка) | (нет голосов) Загрузка ... Загрузка ... Быстрая цитата Цитата


Эксперт
****


Профиль
Группа: Комодератор
Сообщений: 7046
Регистрация: 28.8.2007
Где: Дублин, Ирландия

Репутация: 35
Всего: 223



Цитата(TheFallenViper @  4.4.2012,  14:49 Найти цитируемый пост)
как мне это сделать?

Переписать с MPI на OpenMP. Это совершенно разные технологии, автоматически друг в друга они не конвертируются  smile 

PM MAIL   Вверх
  
Ответ в темуСоздание новой темы Создание опроса
Правила форума "C/C++: Для новичков"
JackYF
bsa

Запрещается!

1. Публиковать ссылки на вскрытые компоненты

2. Обсуждать взлом компонентов и делиться вскрытыми компонентами

  • Действия модераторов можно обсудить здесь
  • С просьбами о написании курсовой, реферата и т.п. обращаться сюда
  • Вопросы по реализации алгоритмов рассматриваются здесь


Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, JackYF, bsa.

 
0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | C/C++: Для новичков | Следующая тема »


 




[ Время генерации скрипта: 0.0467 ]   [ Использовано запросов: 22 ]   [ GZIP включён ]


Реклама на сайте     Информационное спонсорство

 
По вопросам размещения рекламы пишите на vladimir(sobaka)vingrad.ru
Отказ от ответственности     Powered by Invision Power Board(R) 1.3 © 2003  IPS, Inc.