Palabos源碼解析(一)globalDefs.h文件

globalDefs.h文件

plint

/// Integer type for Palabos
/* On some architectures, this type is larger than int.
 * Using plint instead of int ensures 64-bit compatibility of the code.*/
typedef ptrdiff_t plint;

std::ptrdiff_t定義於頭文件<cstddef>

std::ptrdiff_t是兩個指針詳解結果的有符號整數類型。

std::ptrdiff_t 被用於指針算術及數組下標,若負值可行。使用其他類型,如 int 的程序,可能諸如 64 位的系統上失敗,在當下標超過 INT_MAX 或依賴 32 位模算術時。

在用 C++ 容器庫工作時,迭代器的差的準確類型是成員 typedef difference_type ,它常與 std::ptrdiff_t 相同。

只有指向同一數組元素的指針(含指向數組結尾後一位置的指針)可以相減。

若數組過大(大於PTRDIFF_MAX個元素,而小於SIZE_MAX字節),則二個指針的差可能無法以 std::ptrdiff_t 表示,二個這種指針相減的結果是未定義的。

對於短於 PTRDIFF_MAX的 char 數組, std::ptrdiff_t 表現爲std::size_t的有符號對應物:它可以存儲數組的大小,而且在多數平臺上等同於 std::intptr_t

引用自std::ptrdiff_t

pluint

/// Unsigned integer type for Palabos
/* On some architectures, this type is larger than int.
 * Using fluplint instead of unsigned plint ensures 64-bit compatibility of the code.*/
typedef size_t pluint;

std::size_t定義於頭文件<cstddef> <cstdio> <cstdlib> <cstring> <ctime>

std::size_tsizeof運算符還有sizeof...運算符和alignof運算符 (C++11 起)所返回的一種無符號整數類型。

size_t 可以存放下理論上可能存在的對象的最大大小,該對象可以是任何類型,包括數組。大小無法以 std::size_t 表示的類型是病式的。 (C++14 起)在許多平臺上(使用分段尋址的系統除外),std::size_t可以存放下任何非成員的指針,此時可以視作其與std::uintptr_t同義。

std::size_t通常被用於數組索引和循環計數。使用其它類型來進行數組索引操作的程序可能會在某些情況下出錯,例如在 64 位系統中使用 unsigned int 進行索引時,如果索引號超過UINT_MAX或者依賴於 32 位取模運算的話,程序就會出錯。

在對諸如std::stringstd::vector等 C++ 容器進行索引操作時,正確的類型是該容器的成員 typedef size_type,而該類型通常被定義爲與std::size_t相同。

引用自std::size_t

IndexOrdering::OrderingT

/// Ordering of indices when a BlockXD is converted into a serial data stream.
/** Signification of constants:
 *	- forward:  Right-most index (y in 2D and z in 3D) is contiguous in memory.
 *              For non-allocated parts of the Block, the value 0 is produced 
 *              for output, and values are ignored during input.
 *  - backward: Left-most index (x) is contiguous in memory.
 *              For non-allocated parts of the Block, the value 0 is produced 
 *              for output, and values are ignored during input.
 *  - memorySaving: Ordering is forward (this respects the natural ordering in
 *                  Palabos). Non-allocated parts of the Block are neither 
 *                  written or read: memory savings in the program are 
 *                  reflected by memory savings on the disk.
 **/
namespace IndexOrdering {
    enum OrderingT {forward, backward, memorySaving};
}

BlockXD數據轉換爲串行數據流時索引的排序。

常數的意義:

-向前:最右邊的索引(y在2D中,z在3D中)在內存中是連續的。對於塊中未分配的部分,將爲輸出生成值0,並在輸入期間忽略值。

-向後:最左邊的索引(x)在內存中是連續的。對於塊中未分配的部分,將爲輸出生成值0,並在輸入期間忽略值。

-存儲:排序是向前的(這尊重Palabos中的自然排序)。塊中未分配的部分既不寫也不讀:程序中的內存節省反映在磁盤上的內存節省上。

OrderingT 爲不限定作用域的枚舉成員,放在IndexOrering名稱空間中,限定作用域範圍。

博文同步更新地址.

發佈了9 篇原創文章 · 獲贊 1 · 訪問量 2667
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章