第4章アルゴリズムの言語による実現:低水準プログラミング言語
Summaryまとめ
4.1 Models of Computation4.1 計算モデル
• A computational model defines what an algorithm or program does. There are hardware models, programming language models, and abstract models.
• 計算モデルは、アルゴリズムやプログラムが何を行うかを定義する。ハードウェアモデル、プログラミング言語モデル、抽象モデルがある。
• Low-level programming means writing machine code that can be understood by a CPU directly, or something very near to that. It is laborious but yields very fast code.
英語のヒント
• 低水準プログラミングとは、CPUが直接理解できる機械語コード、またはそれに非常に近いものを書くことである。手間はかかるが、非常に高速なコードが得られる。
• Middle-level programming is a compromise that is reasonably efficient and more convenient than low-level programming.
英語のヒント
• 中水準プログラミングは、適度に効率的で、低水準プログラミングより便利な、折衷の方法である。
• High-level programming is more abstract and intuitive for humans. It is less labor-intensive, but high-level code can be slower than low-level code.
英語のヒント
• 高水準プログラミングは、より抽象的で、人間にとって直感的である。労力は少なくて済むが、高水準のコードは低水準のコードより遅くなることがある。
• Programming language paradigms are approaches for organizing source code.
• プログラミング言語のパラダイムは、ソースコードを整理するための手法である。
• In the imperative paradigm, code orders the CPU to execute specific actions.
• 命令型のパラダイムでは、コードが特定の動作を実行するようCPUへ命令する。
• In the declarative paradigm, the programmer declares the outcome that they need.
• 宣言型のパラダイムでは、プログラマーが必要とする結果を宣言する。
• In the functional paradigm, the programmer defines mathematical functions to evaluate.
• 関数型のパラダイムでは、プログラマーが評価する数学的な関数を定義する。
• In structured programming, the flow of execution is specified with explicit syntax elements (“if-then-else,” “for” loop, “while” loop) and never GOTO.
• 構造化プログラミングでは、実行の流れを、明示的な構文要素(if-then-else、forループ、whileループ)で指定し、GOTOは使わない。
• In procedural programming, a program is divided into procedures. Each procedure performs one specific task and has a descriptive name.
• 手続き型プログラミングでは、プログラムを手続きに分ける。各手続きは特定の1つの仕事を行い、その内容を示す名前を持つ。
• In object-oriented programming, the basic building block is an object. An object combines data and procedures that together represent a human concept.
英語のヒント
• オブジェクト指向プログラミングでは、基本的な構成単位はオブジェクトである。オブジェクトは、人間の概念を共に表現するデータと手続きを組み合わせる。
4.2 Building C Programs4.2 Cプログラムを作る
• The C programming language is the most prominent example of a low-level language. Programs written in C typically execute as fast as assembly language and allow programmers to directly manipulate machine features such as memory via the use of pointers.
英語のヒント
• Cプログラミング言語は、低水準言語の最も代表的な例である。Cで書いたプログラムは、通常アセンブリ言語と同じくらい速く実行され、ポインターを使うことで、プログラマーがメモリなどのマシンの機能を直接操作できる。
• The C programming language is used by most of the system software we depend on today (e.g., operating systems, compilers, interpreters, and device drivers) because of its efficient execution, portability, and modularity.
• Cプログラミング言語は、効率的な実行、移植性、モジュール性により、今日私たちが頼るシステムソフトウェアの大半(オペレーティングシステム、コンパイラー、インタープリター、デバイスドライバーなど)で使われている。
• The C data model supports the creation of a variety of basic types including integers and floating point numbers, as well as pointers. C also provides type constructors used to create collections using the
array, struct, and union keywords.英語のヒント
• Cのデータモデルは、ポインターに加え、整数や浮動小数点数など、さまざまな基本型の作成に対応する。またCは、array、struct、unionキーワードを使って集まりを作るための、型構築子も備える。
• C supports the imperative and structured/procedural programming paradigms and allows for conditional and iterative statements as well as functions, which can leverage recursion.
英語のヒント
• Cは、命令型と構造化・手続き型のプログラミングパラダイムに対応する。条件文や反復文に加え、再帰を利用できる関数も使える。
• Program development steps in C require designing algorithms, developing programs that implement algorithms, and compiling, linking, and executing programs. All of these steps may be performed within a C development environment, which is a suite of tools that a programmer uses to create software. It must include a text editor, compiler, and linker, and may include other tools such as a version control manager, and others.
英語のヒント
• Cでのプログラム開発には、アルゴリズムの設計、そのアルゴリズムを実装するプログラムの開発、プログラムのコンパイル・リンク・実行が必要である。これらの手順はすべて、Cの開発環境内で行える。開発環境とは、プログラマーがソフトウェアを作るために使うツール一式である。テキストエディター、コンパイラー、リンカーを必ず含み、さらにバージョン管理ツールなど、ほかのツールを含むこともある。
• A development environment may be an assemblage of separate command-line programs, or an IDE, which is a development environment bundled into a single app. There are a multitude of C development environments, and many of them are free to use.
英語のヒント
• 開発環境は、独立したコマンドラインプログラムの集まりの場合も、1つのアプリにまとめられた開発環境であるIDEの場合もある。Cの開発環境は数多く存在し、その多くは無料で使える。
• Compiling C programs involves converting C into assembly language, which can itself be translated into machine code. This process is performed by using a combination tools known respectively as a C compiler, assembler, and linker. The GCC compiler is an open-source C compiler developed by the GNU project, it include gcc, ar, and ld to implement compiling, assembly, and linking.
英語のヒント
• Cプログラムのコンパイルでは、Cをアセンブリ言語へ変換し、それをさらに機械語コードへ変換できる。この過程は、それぞれCコンパイラー、アセンブラー、リンカーと呼ばれるツールの組合せで行う。GCCコンパイラーは、GNUプロジェクトが開発したオープンソースのCコンパイラーで、コンパイル、アセンブル、リンクを実装するためのgcc、ar、ldを含む。
• Linking is the process of combining the .o files that result from separate C modules into one deliverable library or executable program.
英語のヒント
• リンク処理は、別々のCモジュールから作られた.oファイルを、1つの配布可能なライブラリーまたは実行可能プログラムへまとめる過程である。
• A library is a file that contains the object code of compiled functions. There are several variations of libraries (static, dynamic, shared) and ways of linking them (load-time, run-time).
• ライブラリーは、コンパイルした関数のオブジェクトコードを含むファイルである。ライブラリーには静的・動的・共有などの種類があり、リンクする方法にもロード時・実行時などがある。
• Version control tools manage the files created in programming, facilitating collaboration, backups, and undoing errors.
英語のヒント
• バージョン管理ツールは、プログラミングで作るファイルを管理し、共同作業、バックアップ、誤りの取消しを容易にする。
4.3 Parallel Programming Models4.3 並列プログラミングのモデル
• Multicore computers are commonplace. Most consumer mobile devices, computers, and video game consoles have between two and eight cores. As time goes on, the number of cores in computers tends to increase.
英語のヒント
• マルチコアコンピューターは一般的である。消費者向けのモバイル機器、コンピューター、ビデオゲーム機の大半は、2〜8個のコアを持つ。時とともに、コンピューターのコア数は増える傾向にある。
• Parallel computing does not happen automatically. Rather, a programmer must deliberately write a program in a parallel manner in order for it to use multiple cores.
英語のヒント
• 並列計算は自動的には行われない。複数のコアを使うには、プログラマーが意図的に並列に動くようプログラムを書く必要がある。
• A variety of models of parallel programming exist, including shared memory, threads, and message passing.
• 共有メモリ、スレッド、メッセージパッシングなど、さまざまな並列プログラミングのモデルがある。
• OpenMP is a library for writing parallel code using the message-passing model.
• OpenMPは、メッセージパッシングモデルを使って並列コードを書くためのライブラリーである。
• One strategy for parallel computing is to have a parent thread, which creates and controls child threads. The child threads work in parallel.
• 並列計算の方法の1つは、子スレッドを生成・制御する親スレッドを置くことである。子スレッドは並列に動く。