LINUX.ORG.RU

Сообщения shonny

 

Распараллеливание с помощью openmp

Вообщем пытаюсь использовать Openmp, чтобы распараллелить задачу вычисления экспоненты с помощью ряда Тейлора. Программа работает, но при сравнении времени выполнения последовательного кода и с Openmp, нет прироста скорости, а даже наоборот выполняется дольше с Openmp. В чем может быть причина?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
int fact(int c);
double taylor(double x, int n);
 
int main(int argc, char *argv[]) {
  double x=0;
  int n=0;
  int n_max = 32;
  if (argc != 3) {
  printf("Input three parametrs!\n");
  return 1;
}
  sscanf(argv[1], "%lf", &x);
  sscanf(argv[2], "%d", &n);

 if((n>n_max)||(n<0)) {
 printf("Invalid parameter n, enter n from 0..10\n");
 return 1;
 }
    
 int i; 
 double sum=0 ;
 double t = omp_get_wtime();
 
  #pragma omp parallel for private(i) reduction(+: sum)
   for (i=1; i<=n; i++) {
	  double taylor = pow(x,i)/fact(i);
	  sum+=taylor;
  }
  
  double diff = omp_get_wtime() - t; 
  printf("e^x = %lf\n Time: \t %lf\n", ++sum, diff);
  return 0;
}

int fact(int c) {
   int fact=1;
   int i;
   for (i = 1; i <= c; i++ ) {
      fact *=i;
   }
   return fact;
}

 , , , ,

shonny
()

Вопрос по Scala вывести предложение текста, в котором больше всего слов

Всем привет! Задача такая, нужно вывести предложение текста, в котором больше всего слов. Есть только самое начало, по scala не нашел особо литературы, может кто может помочь

import io.Source 
object tryagain {
  def main(args: Array[String]) { 
text("US President-elect Donald Trump has defended his handling of the transition to the White House, amid reports of disarray in his team. A new sentence for text.") 
}
 def text(news: String) 
{ 
news.split(" ").groupBy(x=>x) 
val counts = news.split("\\W+").groupBy(x=>x).mapValues(x=>x.length) 
printsomething(counts) 
}

 ,

shonny
()

RSS подписка на новые темы