0
eigen3에서이 프로그램과 동등한 것은 무엇입니까? 나는 별도의 프로세스에서 공유 메모리 행렬을 읽고 쓸 수 있어야하고 그 다음 행렬의 고유 값을 취해야한다. Eigen3이 OpenMP를 사용할 수있는 것처럼 보이지만 명확한 예제를 찾지 못했습니다.Eigen3 또는 다른 매트릭스 라이브러리 2D 매트릭스가 공유 메모리를 통해 다른 프로세스에서 업데이트 될 수 있습니까?
서버 :
#include <string>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
int main()
{
int rows = 10; // The number of rows of the 2D array
int columns = 30; // The number of columns of the 2D array
int row, column;
int *matrix;
key_t ipc_key = 5678; /* key to be passed to shmget() */
int shmflg = 0666; /* shmflg to be passed to shmget() */
int id_shmem; /* return value from shmget() */
int theSize; /* size to be passed to shmget() */
theSize = sizeof(int) * rows * columns;
// Create the shared memory segment
id_shmem = shmget(ipc_key, theSize, IPC_CREAT | shmflg);
// Attach the shared memory to our matrix
matrix = (int *)shmat(id_shmem, 0, 0);
int retVal = mlock(matrix, theSize);
if(retVal)
std::cout << "Error Locking" << std::endl;
// Loop through all elements in the array
for (row = 0; row < rows; row++)
{
for (column = 0; column < columns; column++)
{
matrix[row * columns + column] = column; // Equivalent to matrix[column][row]
}
}
while (matrix[0] != -1)
usleep(1);
// Loop through all elements in the array
for (row = 0; row < rows; row++)
{
std::cout << std::endl << row << "\t";
for (column = 0; column < columns; column++)
{
std::cout << " " << matrix[row * columns + column]; // Equivalent to matrix[column][row]
}
}
std::cout << std::endl;
}
클라이언트
#include <string>
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/mman.h>
// This is SXI see http://www.boost.org/doc/libs/1_50_0/doc/html/interprocess/sharedmemorybetweenprocesses.html
int main()
{
int rows = 10; // The number of rows of the 2D array
int columns = 30; // The number of columns of the 2D array
int row, column;
int *matrix;
key_t ipc_key = 5678; /* key to be passed to shmget() */
int shmflg = 0666; /* shmflg to be passed to shmget() */
int id_shmem; /* return value from shmget() */
int theSize; /* size to be passed to shmget() */
theSize = sizeof(int) * rows * columns;
// Create the shared memory segment
id_shmem = shmget(ipc_key, theSize, shmflg);
// Attach the shared memory to our matrix
matrix = (int *)shmat(id_shmem, 0, 0);
// Loop through all elements in the array
for (row = 0; row < rows; row++)
{
std::cout << std::endl << row << "\t";
for (column = 0; column < columns; column++)
{
std::cout << " " << matrix[row * columns + column]; // Equivalent to matrix[column][row]
}
}
matrix[0] = -1;
std::cout << std::endl;
}
실제 분산 메모리 선형 대수학을 살펴볼 수 있습니다. libelemental.org를 사용하는 대신 Eigen을 POSIX 공유 메모리와 같이 하위 수준의 가능성이있는 기능과 함께 사용할 수 있습니다. – Jeff
주셔서 감사합니다. – Ivan