c++ - Ushing shmat and shmget with forks to multiply a matrix -


this assignment i'm working on class. must use forks, shmget, , shmat create multiplied matrix 2 given matrices. each fork 1 instance of multiplication each (this required).

size_t size = matrix1.height * matrix2.width * sizeof(int);         int shmid = shmget(2000,size,0);         int ** shm;         shm = (int ** )shmat (shmid, 0 , 0);         (int = 0; < matrix1.height; i++){             (int j = 0; j < matrix2.width; j++){                 cout << "i: " << << "j: " << j << endl;                 shm[i][j] = 0;                 cout <<"a" << endl;             }         }         (int = 0; < matrix1.height; i++){              (int j = 0; j < matrix2.width; j++){                 vector<int> row = matrix1.matrix_rows_by_columns[i];                 vector<int> column;                 (int s = 0; s < matrix2.height; s++){                     column.push_back(matrix2.matrix_rows_by_columns[s][j]);                 }                 (int p = 0; p < row.size(); p++){                     shm = (int ** )shmat (shmid, 0 , 0);                     pid_t pid = fork();                     if (pid == 0){                         shm[i][j] += row[p] * column[p];                     } }             } 

my current issue segmentation fault on line shm[i][j] occurs on first loop through (i = 0, j = 0). know have change way make pids in array of pids. don't know how join forks @ end. i'm trying here documentation i've been able find dense , professor taught none of coding aspect of assignment.

you must test return values , errno. in case shmget fails enoent. see man shmget details.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -