Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Для новичков > OpenMP and MPI


Автор: TheFallenViper 20.3.2012, 18:50
есть прога "Тест эффективности основных операций MPI"
 не могу найти где скачать mpi.h чтоб добавить в Microsoft Visual Studio 2010,соответсвенно не могу её откомпелировать.у кого установлены нормально 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_W ORLD);
 MPI_Bcast(&NTIMES_PREC,1,MPI_INT,MASTER_RANK,MPI_C OMM_WORLD);
 MPI_Bcast(&REPEAT_ALL,1,MPI_INT,MASTER_RANK,MPI_CO MM_WORLD);
 MPI_Bcast(&REPEAT_EACH_TEST,1,MPI_INT,MASTER_RANK, MPI_COMM_WORLD);
 MPI_Bcast(&msglen_min,1,MPI_INT,MASTER_RANK,MPI_CO MM_WORLD);
 MPI_Bcast(&msglen_max,1,MPI_INT,MASTER_RANK,MPI_CO MM_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_WORL D,&status);
 strcat(nodenames,nodename); 
 }

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

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

 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,&sta tus);
 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_I NT,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_IN T,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,com m,&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,o buf,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
Нам не надо простыней -- пользуйся кнопкой "код".

Автор: boostcoder 20.3.2012, 19:20
Цитата(TheFallenViper @  20.3.2012,  18:50 Найти цитируемый пост)
не могу найти где скачать mpi.h чтоб добавить в Microsoft Visual Studio 2010,соответсвенно не могу её откомпелировать.у кого установлены нормально MPI,можете пожалуйста 

это единственный вопрос, который привел тебя на форум?
спроси у гугла, он все знает.

Автор: TheFallenViper 20.3.2012, 21:08
я хочу узнать у опытных пользователей,запускается ли вообще прога или нет

Автор: boostcoder 20.3.2012, 21:41
запусти - узнаешь.

Автор: W4FhLF 21.3.2012, 23:24
Тебе Microsoft HPC Pack

http://iproc.ru/drafts/microsoft-mpi/

Автор: TheFallenViper 22.3.2012, 16:30
вот ошибка какая

1>------ Построение начато: проект: 123, Конфигурация: Debug Win32 ------
1>Построение начато 22.03.2012 15:26:02.
1>PrepareForBuild:
1>  Создание каталога "c:\users\user\documents\visual studio 2010\Projects\123\Debug\".
1>InitializeBuildStatus:
1>  Создание "Debug\123.unsuccessfulbuild", так как было задано "AlwaysCreate".
1>ClCompile:
1>  123.cpp
1>c:\users\user\documents\visual studio 2010\projects\123\123\123.cpp(8): fatal error C1083: Не удается открыть файл включение: stdlib.h: No such file or directory
1>
1>СБОЙ построения.
1>
1>Затраченное время: 00:00:00.16
========== Построение: успешно: 0, с ошибками: 1, без изменений: 0, пропущено: 0 ==========

Автор: boostcoder 22.3.2012, 16:37
Цитата(TheFallenViper @  22.3.2012,  16:30 Найти цитируемый пост)
123.cpp(8)

покажи что в этой строке.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)