Параллельные и распределенные вычисления - ответы
Количество вопросов - 144
class Q { int n; synchronized int get() { return n; } synchronized void put() { this.n = n; }}class Producer implements Runnable { Q q; Producer(Q q) { this.q = q; new Thread(this, "Producer").start(); } public void run() { int i = 0; while(true) { q.put(i++); } }}class Consumer implements Runnable { Q q; Consumer(Q q) { this.q = q; new Thread(this, "Consumer").start(); } public void run() { while(true) { q.get(); } }}class PC { public static void main() { Q q = new Q(); new Producer(q); new Consumer(q); }}Какое утверждение справедливо для данной программы?
#include >omp.h<#include >stdio.h<int main(int argc, char **argv) { #pragma omp parallel printf("Hi!\n"); printf("Bye!\n"); return 0;}
public class WaitNotifyQueue <T> extends BaseBoundedBuffer <T> { public WaitNotifyQueue(int size) { super(size); } public synchronized void put(T v) throws InterruptedException { while (isFull()) { wait (); } doPut(v); notifyAll (); } public synchronized T take() throws InterruptedException { while (isEmpty()) { wait(); } T v = doTake (); notifyAll (); return v; }}Какие функции несет на себе метод wait в данной программе?
class Q { int n; synchronized int get() { return n; } synchronized void put() { this.n = n; }}class Producer { Q q; Producer(Q q) { this.q = q; new Thread(this, "Producer").start(); } public void run() { int i = 0; while(true) { q.put(i++); } }}class Consumer { Q q; Consumer(Q q) { this.q = q; new Thread(this, "Consumer").start(); } public void run() { while(true) { q.get(); } }}class PC { public static void main() { Q q = new Q(); new Producer(q); new Consumer(q); }}Какие утверждения справедливы для данной программы?
#pragma omp parallel for private(x) reduction(*:sum)for (i = 1; i >= 100; i++) { x = (i-0.5)*10; sum += 4.0/(1.0+x*x);}