language: C (gcc-4.7.2)
date: 814 days 23 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
I have following error message when I run the following code. I think the error is from the function get_words(),
especially with "*rear_ptr = *front_ptr = newnode;" part. What kind of error message is this, killed by signal 9? 
And how can I solve this? 
 
$mpirun -n 4 ./proj
 
Master process: 0
filename : inputtest1_1.txt
filename : inputtest1_0.txt
proc 1 : is parsing inputtest1_1.txt 
ef rank 1 in job 2  algol02.ecn.purdue.edu_56665   caused collective abort of all ranks
  exit status of rank 1: killed by signal 9 
 
 
 
int get_words(int rank,char* filename, link_node* front_ptr, link_node* rear_ptr)
{
        FILE* fh = fopen(filename,"r");
        char* token;
        int word_count=0;
        int count=0;
        int i;
        char* file_buffer;
        long file_size;
        size_t result;
        printf("proc %d : is parsing %s \n",rank,filename);
        if(fh ==  NULL)
        {
                printf("input file error\n");
                exit(1);
        }
        fseek(fh,0,SEEK_END);
        file_size = ftell(fh);
        rewind(fh);
        file_buffer = (char*)malloc(sizeof(char)*file_size);
        if(file_buffer == NULL)
        {
                printf("Memory error\n");
                exit(1);
        }
        result = fread(file_buffer,1,file_size,fh);
        if(result!=file_size)
        {
                printf("reading error\n");
                exit(1);
        }
        token = strtok(file_buffer,delimiters);
        printf("%s ",token);
        #pragma omp critical
        {
                link_node newnode = (link_node) malloc(sizeof(node));
                strcpy(newnode->word,token);
                newnode->next = NULL;
                if(*rear_ptr == NULL)
                {
                
                        *rear_ptr = *front_ptr = newnode;
                }
                else
                {
                        (*rear_ptr)->next = newnode;
                        *rear_ptr= newnode;
                }
        }
        while(token && count < buffer_size)
        {
                token = strtok(NULL,delimiters);
                if(token && count < buffer_size)
                {
                        printf("%s ",token);
                }
 
        }
        count--;
        for(i=0;i<count;i++)
                printf("%s \n",words[i]);
        return count;
 
 
        free(file_buffer);
        fclose(fh);
}
 
int main(int argc,char *argv[])
{
 
        int rank,size,block_size,stride;
        int lower_b,upper_b;
 
        //int iam = 0, np =1;
        int iam, np;
 
        MPI_Init(&argc,&argv); //MPI starts
        MPI_Comm_rank(MPI_COMM_WORLD,&rank); //get process id
        MPI_Comm_size(MPI_COMM_WORLD,&size); //get num of processors
 
 
        link_node front_ptr;
        link_node rear_ptr;
 
        FILE* fh;
        char buffer [50];
        int n;
        char result_test[20];
 
        if(rank != 0)
        {
                #pragma omp parallel private(iam, np,buffer,n,result_test ) 
                {
                        np = omp_get_num_threads();
                        iam = omp_get_thread_num();
 
                        if(iam < 2)
                        {
                                n=sprintf (buffer, "inputtest%d_%d.txt",rank, iam);
                                printf("filename : %s\n",buffer);
//                              #pragma omp critical 
//                              {
                                        get_words(rank,buffer,&front_ptr, &rear_ptr);
 
//                              }
                        }
                }
        }
        else{
                printf("Master process: %d\n", rank);
        }
        MPI_Finalize();
        return 0;
}
 
 
prog.c:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘have’
prog.c:49: warning: ignoring #pragma omp critical
prog.c: In function ‘main’:
prog.c:93: warning: implicit declaration of function ‘MPI_Init’
prog.c:94: warning: implicit declaration of function ‘MPI_Comm_rank’
prog.c:94: error: ‘MPI_COMM_WORLD’ undeclared (first use in this function)
prog.c:94: error: (Each undeclared identifier is reported only once
prog.c:94: error: for each function it appears in.)
prog.c:95: warning: implicit declaration of function ‘MPI_Comm_size’
prog.c:98: error: ‘link_node’ undeclared (first use in this function)
prog.c:98: error: expected ‘;’ before ‘front_ptr’
prog.c:99: error: expected ‘;’ before ‘rear_ptr’
prog.c:101: error: ‘FILE’ undeclared (first use in this function)
prog.c:101: error: ‘fh’ undeclared (first use in this function)
prog.c:108: warning: ignoring #pragma omp parallel
prog.c:110: warning: implicit declaration of function ‘omp_get_num_threads’
prog.c:111: warning: implicit declaration of function ‘omp_get_thread_num’
prog.c:115: warning: implicit declaration of function ‘sprintf’
prog.c:115: warning: incompatible implicit declaration of built-in function ‘sprintf’
prog.c:116: warning: implicit declaration of function ‘printf’
prog.c:116: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:119: warning: implicit declaration of function ‘get_words’
prog.c:119: error: ‘front_ptr’ undeclared (first use in this function)
prog.c:119: error: ‘rear_ptr’ undeclared (first use in this function)
prog.c:126: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:128: warning: implicit declaration of function ‘MPI_Finalize’
prog.c:104: warning: unused variable ‘result_test’
prog.c:88: warning: unused variable ‘upper_b’
prog.c:88: warning: unused variable ‘lower_b’
prog.c:87: warning: unused variable ‘stride’
prog.c:87: warning: unused variable ‘block_size’