我想创建一个 C 程序,它使用线程计算两个 N*N 矩阵的乘法。
我通过使用多个线程引用矩阵乘法开始此代码,但不是为结果矩阵的每个单元格创建 N * N 个线程,我想创建 N 个线程来同时执行乘法,其中结果矩阵的每一行将通过一个不同的线程。
到目前为止,我的代码如下所示:
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#define N 2
struct v {
int i; //Row
int j; //Column
};
int A[N][N] = {{ 1, 2 }, { 3, 4 }};//Matrix 1
int B[N][N] = {{ 2, 3 }, { 4, 5 }};//Matrix 2
int C[N][N]; //Resulting Matrix
static void *fnc(void *arg) {
struct v *data = (struct v *)arg;
int l; …Run Code Online (Sandbox Code Playgroud) 我正在使用DataSet API在Flink上使用Scala。我想在节点之间重新划分数据。Spark具有让用户使用给定numberOfPartitions参数(link)对数据进行重新分区的功能,我相信Flink不支持该功能。因此,我想通过实现自定义分区功能来实现这一目标。
我的数据类型为DataSet(Double,SparseVector)来自数据的示例行:
(1.0 SparseVector((2024,1.0), (2025,1.0), (2030,1.0), (2045,1.0), (2046,1.41), (2063,1.0), (2072,1.0), (3031,1.0), (3032,1.0), (4757,1.0), (4790,1.0), (177196,1.0), (177197,0.301), (177199,1.0), (177202,1.0), (1544177,1.0), (1544178,1.0), (1544179,1.0), (1654031,1.0), (1654190,1.0), (1654191,1.0), (1654192,1.0), (1654193,1.0), (1654194,1.0), (1654212,1.0), (1654237,1.0), (1654238,1.0)))
Run Code Online (Sandbox Code Playgroud)
由于“ Double”是二进制(1或-1),因此我想根据SparceVector的长度对数据进行分区。我的自定义分区器如下:
class myPartitioner extends Partitioner[SparseVector]
{
override def partition(key: SparseVector, numPartitions: Int): Int = {
key.size % numPartitions
}
}
Run Code Online (Sandbox Code Playgroud)
我将此自定义分区称为:
data.partitionCustom(new myPartitioner(),1)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我理解在Scala中调用myPartitioner函数时如何将分区数指定为“ numPartitions”参数。
谢谢。