build_csr_from_coo Subroutine

private subroutine build_csr_from_coo(self)

Arguments

Type IntentOptional Attributes Name
class(type_node_adjacency), intent(inout) :: self

Calls

proc~~build_csr_from_coo~~CallsGraph proc~build_csr_from_coo build_csr_from_coo interface~allocate_array allocate_array proc~build_csr_from_coo->interface~allocate_array sort sort proc~build_csr_from_coo->sort proc~allocate_rank1_int16 allocate_rank1_int16 interface~allocate_array->proc~allocate_rank1_int16 proc~allocate_rank1_int32 allocate_rank1_int32 interface~allocate_array->proc~allocate_rank1_int32 proc~allocate_rank1_int64 allocate_rank1_int64 interface~allocate_array->proc~allocate_rank1_int64 proc~allocate_rank1_int8 allocate_rank1_int8 interface~allocate_array->proc~allocate_rank1_int8 proc~allocate_rank1_logical1 allocate_rank1_logical1 interface~allocate_array->proc~allocate_rank1_logical1 proc~allocate_rank1_logical4 allocate_rank1_logical4 interface~allocate_array->proc~allocate_rank1_logical4 proc~allocate_rank1_logical8 allocate_rank1_logical8 interface~allocate_array->proc~allocate_rank1_logical8 proc~allocate_rank1_real128 allocate_rank1_real128 interface~allocate_array->proc~allocate_rank1_real128 proc~allocate_rank1_real32 allocate_rank1_real32 interface~allocate_array->proc~allocate_rank1_real32 proc~allocate_rank1_real64 allocate_rank1_real64 interface~allocate_array->proc~allocate_rank1_real64 proc~allocate_rank2_int16 allocate_rank2_int16 interface~allocate_array->proc~allocate_rank2_int16 proc~allocate_rank2_int32 allocate_rank2_int32 interface~allocate_array->proc~allocate_rank2_int32 proc~allocate_rank2_int64 allocate_rank2_int64 interface~allocate_array->proc~allocate_rank2_int64 proc~allocate_rank2_int8 allocate_rank2_int8 interface~allocate_array->proc~allocate_rank2_int8 proc~allocate_rank2_logical1 allocate_rank2_logical1 interface~allocate_array->proc~allocate_rank2_logical1 proc~allocate_rank2_logical4 allocate_rank2_logical4 interface~allocate_array->proc~allocate_rank2_logical4 proc~allocate_rank2_logical8 allocate_rank2_logical8 interface~allocate_array->proc~allocate_rank2_logical8 proc~allocate_rank2_real128 allocate_rank2_real128 interface~allocate_array->proc~allocate_rank2_real128 proc~allocate_rank2_real32 allocate_rank2_real32 interface~allocate_array->proc~allocate_rank2_real32 proc~allocate_rank2_real64 allocate_rank2_real64 interface~allocate_array->proc~allocate_rank2_real64 proc~error_message error_message proc~allocate_rank1_int16->proc~error_message proc~allocate_rank1_int32->proc~error_message proc~allocate_rank1_int64->proc~error_message proc~allocate_rank1_int8->proc~error_message proc~allocate_rank1_logical1->proc~error_message proc~allocate_rank1_logical4->proc~error_message proc~allocate_rank1_logical8->proc~error_message proc~allocate_rank1_real128->proc~error_message proc~allocate_rank1_real32->proc~error_message proc~allocate_rank1_real64->proc~error_message proc~allocate_rank2_int16->proc~error_message proc~allocate_rank2_int32->proc~error_message proc~allocate_rank2_int64->proc~error_message proc~allocate_rank2_int8->proc~error_message proc~allocate_rank2_logical1->proc~error_message proc~allocate_rank2_logical4->proc~error_message proc~allocate_rank2_logical8->proc~error_message proc~allocate_rank2_real128->proc~error_message proc~allocate_rank2_real32->proc~error_message proc~allocate_rank2_real64->proc~error_message log_error log_error proc~error_message->log_error

Called by

proc~~build_csr_from_coo~~CalledByGraph proc~build_csr_from_coo build_csr_from_coo proc~initialize_hybrid_from_mesh type_node_adjacency%initialize_hybrid_from_mesh proc~initialize_hybrid_from_mesh->proc~build_csr_from_coo proc~initialize_type_domain type_domain%initialize_type_domain proc~initialize_type_domain->proc~initialize_hybrid_from_mesh

Source Code

    subroutine build_csr_from_coo(self)
        implicit none
        class(type_node_adjacency), intent(inout) :: self
        integer(int32) :: i

        if (self%nnz == 0) then
            if (self%num_nodes > 0) then
                call allocate_array(self%ptr, self%num_nodes + 1)
                self%ptr = 1
            end if
            call allocate_array(self%ind, 0)
            return
        end if

        ! COOデータはcreate_unique_cooによって行でソート済み
        call allocate_array(self%ptr, self%num_nodes + 1)
        call allocate_array(self%ind, self%nnz)
        self%ind = self%col ! col配列をindにコピー
        self%ptr = 0

        ! 1. 各行の非ゼロ要素数を数える (次数を計算)
        do i = 1, self%nnz
            self%ptr(self%row(i) + 1) = self%ptr(self%row(i) + 1) + 1
        end do

        ! 2. 次数の累積和からptr配列を構築
        do i = 1, self%num_nodes
            self%ptr(i + 1) = self%ptr(i) + self%ptr(i + 1)
        end do

        ! Fortranは1-based indexなので、全体に1を加算
        self%ptr = self%ptr + 1

        ! 3. 各行の列インデックスをソートする
        do i = 1, self%num_nodes
            if (self%ptr(i + 1) > self%ptr(i)) then
                call sort(self%ind(self%ptr(i):self%ptr(i + 1) - 1))
            end if
        end do
    end subroutine build_csr_from_coo