0
사이트에 대한 질문이 있으니이 부분은 here인데 c로 구현되어 있습니다. C++ 버전이 필요합니다.C++ MPI 필드 char [16]과 정수가 포함 된 구조체의 배열을 만들고 보내십시오.
문제는 다음과 같다 : I 다음 형태 I이 구조체의 어레이를 보내야
struct word
{
char value[WORD_MAX_LENGTH];
int freq;
};
을 갖는 구조체를 만들었다. 이 구조체를 직렬화하고 MPI_Send를 사용하여 다른 프로세스에 500 개를 전송할 수 있습니까? 내가 지금까지 어디서 얻었 여기
이다 : 나는이 작업을 수행 할 때 나는 그것을 실행하려고하면
MPI_Datatype word_type, oldtypes[2];
int blockcounts[2];
MPI_Aint offsets[2], extent;
//Determine the offset and block length of the first element of the struct which is a char array.
offsets[0] = 0;
oldtypes[0] = MPI_CHAR;
blockcounts[0] = WORD_MAX_LENGTH;
//Determine the offset of int ferq of the struct.
MPI_Type_extent(MPI_CHAR, &extent);
offsets[1] = 16 * extent;
blockcounts[1] = 1;
// Finally create the type.
MPI_Type_create_struct(2, blockcounts, offsets, oldtypes, &word_type);
MPI_Type_commit(&word_type);
, 그것은 그러나 오류없이 컴파일합니다. 불평합니다
Fatal error in PMPI_Type_create_struct: Invalid datatype, error stack:
PMPI_Type_create_struct(173): MPI_Type_create_struct(count=2,
array_of_blocklengths=0x7fffbd059f70,
array_of_displacements=0x7fffbd059f80, array_of_types=0x7fffbd059f60,
newtype=0x7fffbd059f14) failed
PMPI_Type_create_struct(142): Invalid datatype
도움이 되겠습니다. 참고 : 부스트 라이브러리를 사용할 수 없습니다. 컴파일러가 추가하는 경우
정말 고마워요! 나는 질문을 한 후에 오프셋을 편집하는 것을 잊어 버렸다. 나는 어쨌든 머리를 가져 주셔서 감사합니다. 그들은이 오프셋 [1] = (size_t) & (word.freq) - (size_t) &word;처럼 보입니다. 또한 oldtypes에 MPI_INT를 추가했습니다. 이제 고마워요. D –
이것이 효과가 있습니다. 어떻게 이러한 구조체를 여러개의 슬레이브에 보낼 수 있습니까? –
'MPI_Send (words, n, word_type, ...)' –