小编Mas*_*ano的帖子

使用接近“INT_MAX”的“count”值传送数据

消息传递接口 API 始终用作变量int的类型count。例如,原型是MPI_Send

int MPI_Send(const void* buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
Run Code Online (Sandbox Code Playgroud)

如果要发送或接收的元素数量接近甚至超过 INT_MAX,这可能会成为问题。

当然,可以通过以下任一方法降低 的值来解决该问题count

  1. 将单个呼叫拆分为多个呼叫
  2. 定义(不必要的)聚合MPI_Datatype

无论如何,这两种方法都更像是一种黑客行为,而不是真正的解决方案,特别是如果使用简单的启发式方法来实现。因此我想问的是:

是否有更好的习惯用标准 MPI 调用来处理此类情况?如果没有,有人知道一些围绕 MPI 构建的(实体)包装库来克服这个限制吗?

c c++ int buffer mpi

4
推荐指数
1
解决办法
1179
查看次数

OpenMP 4中的任务依赖性

以下代码基于OpenMP 4.0规范工作:

out和inout依赖类型.生成的任务将是所有先前生成的兄弟任务的从属任务,其引用入口,出口或入口依赖类型列表中的至少一个列表项.

这意味着task3变得依赖于task2.对?但它没有意义!为什么输入 - 输出依赖性任务应该是输入依赖性任务的依赖?

为了使它们独立,我需要做什么?ps:在Linux上使用g ++ 4.9进行代码测试.

#include <stdio.h>
#include <omp.h>
#include <unistd.h>
int main() {
int x,y;
#pragma omp parallel num_threads(10)
{
#pragma omp single nowait
 {
#pragma omp task depend (out:x)  //task1
  {
        x=1;
  }
#pragma omp task depend(in:x) depend(out:y)  //task2
  {
        sleep(2); //Does task3 wait for us? Yes!
        y=x+1;
  }
#pragma omp task depend (inout:x)  //task3
  {
        x++;
        printf("task3(x): %d\n" , x);
  }
#pragma omp task depend (in:x,y)  //task4
 {
        printf("task4 (x+y): %d\n" …
Run Code Online (Sandbox Code Playgroud)

c++ parallel-processing dependencies task openmp

4
推荐指数
1
解决办法
4324
查看次数

模块调用具有隐式接口的外部过程

以下代码,结合模块程序外部程序

module module_dummy

  implicit none

contains

  subroutine foo(a)

    real, intent(inout) :: a(:)

    call bar(a)

  end subroutine foo

end module module_dummy

program main

  use module_dummy

  implicit none 

  integer, parameter :: nelems = 100000000
  real,  allocatable :: a(:)

  allocate( a(nelems) )
  a = 0.0
  call foo(a)
  print *, a(1:10)
  deallocate(a)

end program main

subroutine bar(a)

  implicit none

  real, intent(inout) :: a(:)

  a = 1.0      

end subroutine bar
Run Code Online (Sandbox Code Playgroud)

似乎失败了:

  1. segmentation fault
  2. 打印块0.000而不是块1.000

在我迄今为止尝试过的任何平台上。该问题与 的隐式接口声明 …

module interface subroutine fortran90

2
推荐指数
1
解决办法
2069
查看次数

CRTP:表达式模板的编译器相关问题

我在编译器相关问题中遇到以下代码(存储在crtp.cc中):

#include <vector>
#include <cassert>
#include <iostream>

template < class Derived >
class AlgebraicVectorExpression {
public:
  typedef std::vector<double>::size_type  SizeType;
  typedef std::vector<double>::value_type ValueType;
  typedef std::vector<double>::reference  ReferenceType;

  SizeType size() const {
    return static_cast<const Derived&>(*this).size();
  }

  ValueType operator[](SizeType ii) const {
    return static_cast<const Derived&>(*this)[ii];
  }

  operator Derived&() {
    return static_cast<Derived&>(*this);
  }

  operator const Derived&() const {
    return static_cast< const Derived& >(*this);
  }
};

template< class T1, class T2>
class AlgebraicVectorSum : public AlgebraicVectorExpression< AlgebraicVectorSum<T1,T2> > {
  const T1 & a_;
  const T2 & …
Run Code Online (Sandbox Code Playgroud)

c++ crtp expression-templates

1
推荐指数
1
解决办法
441
查看次数

openmp - 用于文本文件读取和使用管道的while循环

我发现openmp不支持while循环(或者至少不太喜欢它们).而且也不喜欢'!='运算符.

我有这段代码.

int count = 1;
#pragma omp parallel for
    while ( fgets(buff, BUFF_SIZE, f) != NULL )
    {
        len = strlen(buff);
        int sequence_counter = segment_read(buff,len,count);
        if (sequence_counter == 1)
        {
            count_of_reads++;
            printf("\n Total No. of reads: %d \n",count_of_reads);
        }
    count++;
    }
Run Code Online (Sandbox Code Playgroud)

关于如何管理这个的任何线索?我在某处读到(包括stackoverflow的另一篇文章)我可以使用管道.那是什么 ?以及如何实施它?

c parallel-processing hpc openmp

0
推荐指数
1
解决办法
8703
查看次数

int f(int&x)之间的区别int f(int x)

#include<stdio.h>
#include<conio.h>

int f(int & ,int );//function prototype

main()
{
  int x,p=5; //p is initialized to 5
  x=f(p,p);
  printf("\n Value is : %d",x);//print the value of x
  getch();
}

int f (int & x, int c)
{
c=c-1;
if (c==0) return 1;
x=x+1;
return f(x,c) * x; //recursion
}
Run Code Online (Sandbox Code Playgroud)

输出:6561

谁能向我解释程序的流程。这个问题来自我无法理解的门。似乎该函数以p = 5的值调用。它被int&x捕获在函数f中,问题出在这里。是值,即5是存储在x还是x的地址中。

c++ recursion

-2
推荐指数
1
解决办法
9729
查看次数