mpirun程序没有输出

时间:2013-01-24 19:19:18

标签: c mpi openmpi

我正在进行mpi任务。

我的程序是让用户输入数据列表,我们计算程序搜索数据库中数据所需的时间(.csv)。

我写的顺序程序写得很好。它可以允许用户输入然后搜索csv文件中的用户输入并返回所需的时间。

但是当我将mpi应用到程序中时,它可以使用mpicc进行编译。当我使用mpirun运行程序时,它什么也没显示。任何人都可以帮助我看看发生了什么? 这是.csv文件中的示例数据

=============================================== ====

经理ID,yearID,teamID,lgID,inseason,G,W,L,秩,plyrMgr

wrighha01m,1871年,BS1,NA,1,31,20,10,3,Y

woodji01m,1871年,CH1,NA,1,28,19,9,2,Y

paborch01m,1871年,CL1,NA,1,29,10,19,8,Y

=======================================

我的代码

=============================================

#include "mpi.h" 
#include <stdio.h> 
#include <stdlib.h>
#include <string.h>     //for string operations : strcpy & strtok
#include <time.h> 

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

int n, myid, numprocs; 
MPI_Init(&argc,&argv); 
MPI_Comm_size(MPI_COMM_WORLD,&numprocs); 
MPI_Comm_rank(MPI_COMM_WORLD,&myid); 

struct
{
    char managerID[50];
    char yearID[50];
    char teamID[10];
    char lgID[3];
    char inseason[7];
    char G[50];
    char W[50];
    char L[10];
    char rank[3];
    char plyrMgr[7];
}Managers[5000];

time_t start, end;      //variable used for compute time.

//double diff;
int choice;

int dataSize=0;
FILE *fp;
char buf[99999];        //max total array size
int i = 0, j;
fp=fopen("Managers.csv","r");

//ignore the commna delimiters, copy the value into each field's arrays.
 while( fgets(buf,sizeof(buf),fp) != NULL)
{
    strcpy(Managers[i].managerID, strtok(buf,","));
    strcpy(Managers[i].yearID, strtok(NULL,","));
    strcpy(Managers[i].teamID, strtok(NULL,","));
    strcpy(Managers[i].lgID, strtok(NULL,","));
    strcpy(Managers[i].inseason, strtok(NULL,","));
    strcpy(Managers[i].G, strtok(NULL,","));
    strcpy(Managers[i].W, strtok(NULL,","));
    strcpy(Managers[i].L, strtok(NULL,","));
    strcpy(Managers[i].rank, strtok(NULL,","));
    strcpy(Managers[i].plyrMgr, strtok(NULL,","));
    ++i;        //increment array
    dataSize++;     //counter for data size
}

char *s;
char str[5];
if(myid ==0){
    printf("\n\n Please input the data to be retrieved\n");
    printf(" Note : No space is allowed...\n");
    printf(" Sample Query : abc,123,def,321\n");
    printf(" Input =>");
    scanf ("%s", str);
}
MPI_Bcast(str, 1, MPI_CHAR, 0, MPI_COMM_WORLD); // broadcast the information out

 start = clock(); // start the time


s = strtok (str, ",");
printf("\n");

//print header field
printf(" ManagerID");
printf("       YearID");
printf("      TeamID");
printf("      LgID");
printf("      InSeason");
printf("    Game");
printf("        Win");
printf("       Lose");
printf("        Rank");
printf("     PlyrMgr\n\n");

//print all the data
 while (s != NULL)
{
    int k;

    for (k =1; k<=dataSize; k++)
    {
        if(strcmp(s,Managers[k].managerID) == 0)
        {
            printf(" %10s",Managers[k].managerID);
            printf(" %10s",Managers[k].yearID);
            printf(" %10s",Managers[k].teamID);
            printf(" %10s",Managers[k].lgID);
            printf(" %10s",Managers[k].inseason);
            printf(" %10s",Managers[k].G);
            printf(" %10s",Managers[k].W);
            printf(" %10s",Managers[k].L);
            printf(" %10s",Managers[k].rank);
            printf(" %10s",Managers[k].plyrMgr);
        }
    }
    printf("\n");
    s = strtok (NULL, ",");
}

end = clock(); // end time
double diff = (((double)end - (double)start)/1000000.0F) * 1000;

if(myid==0){

    printf(" Time Taken : %.5f seconds \n", diff);
}


MPI_Finalize(); 

}

0 个答案:

没有答案